Commit | Line | Data |
e312add1 |
1 | #./perl |
2 | |
0f4b6630 |
3 | BEGIN { |
ea2b5ef6 |
4 | eval { my $q = pack "q", 0 }; |
0f4b6630 |
5 | if ($@) { |
868d6b85 |
6 | print "1..0\n# Skip: no 64-bit types\n"; |
0f4b6630 |
7 | exit(0); |
8 | } |
ea2b5ef6 |
9 | chdir 't' if -d 't'; |
20822f61 |
10 | @INC = '../lib'; |
0f4b6630 |
11 | } |
12 | |
686fa4bb |
13 | # This could use many more tests. |
0f4b6630 |
14 | |
d0ba1bd2 |
15 | # so that using > 0xfffffff constants and |
972b05a9 |
16 | # 32+ bit integers don't cause noise |
4438c4b7 |
17 | no warnings qw(overflow portable); |
ea2b5ef6 |
18 | |
868d6b85 |
19 | print "1..55\n"; |
0f4b6630 |
20 | |
21 | my $q = 12345678901; |
22 | my $r = 23456789012; |
20fe1ea2 |
23 | my $f = 0xffffffff; |
0f4b6630 |
24 | my $x; |
2d4389e4 |
25 | my $y; |
0f4b6630 |
26 | |
27 | $x = unpack "q", pack "q", $q; |
20fe1ea2 |
28 | print "not " unless $x == $q && $x > $f; |
0f4b6630 |
29 | print "ok 1\n"; |
30 | |
31 | |
22f3ae8c |
32 | $x = sprintf("%lld", 12345678901); |
20fe1ea2 |
33 | print "not " unless $x eq $q && $x > $f; |
0f4b6630 |
34 | print "ok 2\n"; |
35 | |
36 | |
0f4b6630 |
37 | $x = sprintf("%lld", $q); |
20fe1ea2 |
38 | print "not " unless $x == $q && $x eq $q && $x > $f; |
22f3ae8c |
39 | print "ok 3\n"; |
0f4b6630 |
40 | |
41 | $x = sprintf("%Ld", $q); |
20fe1ea2 |
42 | print "not " unless $x == $q && $x eq $q && $x > $f; |
22f3ae8c |
43 | print "ok 4\n"; |
0f4b6630 |
44 | |
45 | $x = sprintf("%qd", $q); |
20fe1ea2 |
46 | print "not " unless $x == $q && $x eq $q && $x > $f; |
22f3ae8c |
47 | print "ok 5\n"; |
0f4b6630 |
48 | |
0f4b6630 |
49 | |
50 | $x = sprintf("%llx", $q); |
20fe1ea2 |
51 | print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f; |
22f3ae8c |
52 | print "ok 6\n"; |
0f4b6630 |
53 | |
54 | $x = sprintf("%Lx", $q); |
20fe1ea2 |
55 | print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f; |
22f3ae8c |
56 | print "ok 7\n"; |
0f4b6630 |
57 | |
58 | $x = sprintf("%qx", $q); |
20fe1ea2 |
59 | print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f; |
22f3ae8c |
60 | print "ok 8\n"; |
0f4b6630 |
61 | |
0f4b6630 |
62 | |
63 | $x = sprintf("%llo", $q); |
20fe1ea2 |
64 | print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f; |
22f3ae8c |
65 | print "ok 9\n"; |
0f4b6630 |
66 | |
67 | $x = sprintf("%Lo", $q); |
20fe1ea2 |
68 | print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f; |
22f3ae8c |
69 | print "ok 10\n"; |
0f4b6630 |
70 | |
71 | $x = sprintf("%qo", $q); |
20fe1ea2 |
72 | print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f; |
22f3ae8c |
73 | print "ok 11\n"; |
0f4b6630 |
74 | |
0f4b6630 |
75 | |
76 | $x = sprintf("%llb", $q); |
20fe1ea2 |
77 | print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 && |
78 | oct("0b$x") > $f; |
22f3ae8c |
79 | print "ok 12\n"; |
0f4b6630 |
80 | |
81 | $x = sprintf("%Lb", $q); |
20fe1ea2 |
82 | print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 && |
83 | oct("0b$x") > $f; |
22f3ae8c |
84 | print "ok 13\n"; |
0f4b6630 |
85 | |
86 | $x = sprintf("%qb", $q); |
20fe1ea2 |
87 | print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 && |
88 | oct("0b$x") > $f; |
22f3ae8c |
89 | print "ok 14\n"; |
0f4b6630 |
90 | |
91 | |
22f3ae8c |
92 | $x = sprintf("%llu", $q); |
20fe1ea2 |
93 | print "not " unless $x eq $q && $x > $f; |
22f3ae8c |
94 | print "ok 15\n"; |
0f4b6630 |
95 | |
22f3ae8c |
96 | $x = sprintf("%Lu", $q); |
20fe1ea2 |
97 | print "not " unless $x == $q && $x eq $q && $x > $f; |
22f3ae8c |
98 | print "ok 16\n"; |
0f4b6630 |
99 | |
22f3ae8c |
100 | $x = sprintf("%qu", $q); |
20fe1ea2 |
101 | print "not " unless $x == $q && $x eq $q && $x > $f; |
22f3ae8c |
102 | print "ok 17\n"; |
0f4b6630 |
103 | |
104 | |
29fe7a80 |
105 | $x = sprintf("%D", $q); |
20fe1ea2 |
106 | print "not " unless $x == $q && $x eq $q && $x > $f; |
22f3ae8c |
107 | print "ok 18\n"; |
29fe7a80 |
108 | |
109 | $x = sprintf("%U", $q); |
20fe1ea2 |
110 | print "not " unless $x == $q && $x eq $q && $x > $f; |
22f3ae8c |
111 | print "ok 19\n"; |
29fe7a80 |
112 | |
113 | $x = sprintf("%O", $q); |
20fe1ea2 |
114 | print "not " unless oct($x) == $q && oct($x) > $f; |
22f3ae8c |
115 | print "ok 20\n"; |
29fe7a80 |
116 | |
117 | |
0f4b6630 |
118 | $x = $q + $r; |
20fe1ea2 |
119 | print "not " unless $x == 35802467913 && $x > $f; |
22f3ae8c |
120 | print "ok 21\n"; |
0f4b6630 |
121 | |
122 | $x = $q - $r; |
20fe1ea2 |
123 | print "not " unless $x == -11111110111 && -$x > $f; |
22f3ae8c |
124 | print "ok 22\n"; |
0f4b6630 |
125 | |
f3ff050f |
126 | if ($^O ne 'unicos') { |
127 | $x = $q * 1234567; |
128 | print "not " unless $x == 15241567763770867 && $x > $f; |
129 | print "ok 23\n"; |
0f4b6630 |
130 | |
8d489514 |
131 | $x /= 1234567; |
132 | print "not " unless $x == $q && $x > $f; |
133 | print "ok 24\n"; |
2d4389e4 |
134 | |
8d489514 |
135 | $x = 98765432109 % 12345678901; |
136 | print "not " unless $x == 901; |
137 | print "ok 25\n"; |
138 | |
139 | # The following 12 tests adapted from op/inc. |
2d4389e4 |
140 | |
f3ff050f |
141 | $a = 9223372036854775807; |
142 | $c = $a++; |
143 | print "not " unless $a == 9223372036854775808; |
144 | print "ok 26\n"; |
145 | |
146 | $a = 9223372036854775807; |
147 | $c = ++$a; |
148 | print "not " |
149 | unless $a == 9223372036854775808 && $c == $a; |
150 | print "ok 27\n"; |
151 | |
152 | $a = 9223372036854775807; |
153 | $c = $a + 1; |
154 | print "not " |
155 | unless $a == 9223372036854775807 && $c == 9223372036854775808; |
156 | print "ok 28\n"; |
157 | |
158 | $a = -9223372036854775808; |
159 | $c = $a--; |
160 | print "not " |
161 | unless $a == -9223372036854775809 && $c == -9223372036854775808; |
162 | print "ok 29\n"; |
163 | |
164 | $a = -9223372036854775808; |
165 | $c = --$a; |
166 | print "not " |
167 | unless $a == -9223372036854775809 && $c == $a; |
168 | print "ok 30\n"; |
169 | |
170 | $a = -9223372036854775808; |
171 | $c = $a - 1; |
172 | print "not " |
173 | unless $a == -9223372036854775808 && $c == -9223372036854775809; |
174 | print "ok 31\n"; |
175 | |
176 | $a = 9223372036854775808; |
177 | $a = -$a; |
178 | $c = $a--; |
179 | print "not " |
180 | unless $a == -9223372036854775809 && $c == -9223372036854775808; |
181 | print "ok 32\n"; |
182 | |
183 | $a = 9223372036854775808; |
184 | $a = -$a; |
185 | $c = --$a; |
186 | print "not " |
187 | unless $a == -9223372036854775809 && $c == $a; |
188 | print "ok 33\n"; |
189 | |
190 | $a = 9223372036854775808; |
191 | $a = -$a; |
192 | $c = $a - 1; |
193 | print "not " |
194 | unless $a == -9223372036854775808 && $c == -9223372036854775809; |
195 | print "ok 34\n"; |
196 | |
197 | $a = 9223372036854775808; |
198 | $b = -$a; |
199 | $c = $b--; |
200 | print "not " |
201 | unless $b == -$a-1 && $c == -$a; |
202 | print "ok 35\n"; |
203 | |
204 | $a = 9223372036854775808; |
205 | $b = -$a; |
206 | $c = --$b; |
207 | print "not " |
208 | unless $b == -$a-1 && $c == $b; |
209 | print "ok 36\n"; |
210 | |
211 | $a = 9223372036854775808; |
212 | $b = -$a; |
213 | $b = $b - 1; |
214 | print "not " |
215 | unless $b == -(++$a); |
216 | print "ok 37\n"; |
217 | |
218 | } else { |
219 | # Unicos has imprecise doubles (14 decimal digits or so), |
8d489514 |
220 | # especially if operating near the UV/IV limits the low-order bits |
221 | # become mangled even by simple arithmetic operations. |
222 | for (23..37) { |
2f7c487e |
223 | print "ok $_ # skipped: too imprecise numbers\n"; |
f3ff050f |
224 | } |
225 | } |
e312add1 |
226 | |
2d4389e4 |
227 | |
c5a0f51a |
228 | $x = ''; |
229 | print "not " unless (vec($x, 1, 64) = $q) == $q; |
e312add1 |
230 | print "ok 38\n"; |
c5a0f51a |
231 | |
232 | print "not " unless vec($x, 1, 64) == $q && vec($x, 1, 64) > $f; |
e312add1 |
233 | print "ok 39\n"; |
c5a0f51a |
234 | |
235 | print "not " unless vec($x, 0, 64) == 0 && vec($x, 2, 64) == 0; |
e312add1 |
236 | print "ok 40\n"; |
c5a0f51a |
237 | |
972b05a9 |
238 | |
239 | print "not " unless ~0 == 0xffffffffffffffff; |
e312add1 |
240 | print "ok 41\n"; |
972b05a9 |
241 | |
242 | print "not " unless (0xffffffff<<32) == 0xffffffff00000000; |
e312add1 |
243 | print "ok 42\n"; |
972b05a9 |
244 | |
245 | print "not " unless ((0xffffffff)<<32)>>32 == 0xffffffff; |
e312add1 |
246 | print "ok 43\n"; |
972b05a9 |
247 | |
248 | print "not " unless 1<<63 == 0x8000000000000000; |
e312add1 |
249 | print "ok 44\n"; |
972b05a9 |
250 | |
251 | print "not " unless (sprintf "%#Vx", 1<<63) eq '0x8000000000000000'; |
e312add1 |
252 | print "ok 45\n"; |
972b05a9 |
253 | |
254 | print "not " unless (0x8000000000000000 | 1) == 0x8000000000000001; |
e312add1 |
255 | print "ok 46\n"; |
972b05a9 |
256 | |
f3ff050f |
257 | print "not " |
258 | unless (0xf000000000000000 & 0x8000000000000000) == 0x8000000000000000; |
e312add1 |
259 | print "ok 47\n"; |
972b05a9 |
260 | |
f3ff050f |
261 | print "not " |
262 | unless (0xf000000000000000 ^ 0xfffffffffffffff0) == 0x0ffffffffffffff0; |
e312add1 |
263 | print "ok 48\n"; |
972b05a9 |
264 | |
686fa4bb |
265 | |
f3ff050f |
266 | print "not " |
267 | unless (sprintf "%b", ~0) eq |
268 | '1111111111111111111111111111111111111111111111111111111111111111'; |
686fa4bb |
269 | print "ok 49\n"; |
270 | |
f3ff050f |
271 | print "not " |
272 | unless (sprintf "%64b", ~0) eq |
273 | '1111111111111111111111111111111111111111111111111111111111111111'; |
686fa4bb |
274 | print "ok 50\n"; |
275 | |
276 | print "not " unless (sprintf "%d", ~0>>1) eq '9223372036854775807'; |
277 | print "ok 51\n"; |
278 | |
279 | print "not " unless (sprintf "%u", ~0) eq '18446744073709551615'; |
280 | print "ok 52\n"; |
281 | |
868d6b85 |
282 | # If the 53..55 fail you have problems in the parser's string->int conversion, |
283 | # see toke.c:scan_num(). |
284 | |
285 | $q = -9223372036854775808; |
00450673 |
286 | print "# $q ne\n# -9223372036854775808\nnot " unless "$q" eq "-9223372036854775808"; |
868d6b85 |
287 | print "ok 53\n"; |
288 | |
289 | $q = 9223372036854775807; |
00450673 |
290 | print "# $q ne\n# 9223372036854775807\nnot " unless "$q" eq "9223372036854775807"; |
868d6b85 |
291 | print "ok 54\n"; |
292 | |
293 | $q = 18446744073709551615; |
00450673 |
294 | print "# $q ne\n# 18446744073709551615\nnot " unless "$q" eq "18446744073709551615"; |
868d6b85 |
295 | print "ok 55\n"; |
296 | |
c5a0f51a |
297 | # eof |