4 eval { my $q = pack "q", 0 };
6 print "1..0 # Skip: no 64-bit types\n";
13 # This could use many more tests.
15 # so that using > 0xfffffff constants and
16 # 32+ bit integers don't cause noise
18 no warnings qw(overflow portable);
22 # as 6 * 6 = 36, the last digit of 6**n will always be six. Hence the last
23 # digit of 16**n will always be six. Hence 16**n - 1 will always end in 5.
24 # Assumption is that UVs will always be a multiple of 4 bits long.
27 die "UV_max eq '$UV_max', doesn't end in 5; your UV isn't 4n bits long :-(."
28 unless $UV_max =~ /5$/;
29 my $UV_max_less3 = $UV_max - 3;
30 my $maths_preserves_UVs = $UV_max_less3 =~ /^\d+2$/; # 5 - 3 is 2.
31 if ($maths_preserves_UVs) {
32 print "# This perl's maths preserves all bits of a UV.\n";
34 print "# This perl's maths does not preserve all bits of a UV.\n";
43 $x = unpack "q", pack "q", $q;
44 print "not " unless $x == $q && $x > $f;
48 $x = sprintf("%lld", 12345678901);
49 print "not " unless $x eq $q && $x > $f;
53 $x = sprintf("%lld", $q);
54 print "not " unless $x == $q && $x eq $q && $x > $f;
57 $x = sprintf("%Ld", $q);
58 print "not " unless $x == $q && $x eq $q && $x > $f;
61 $x = sprintf("%qd", $q);
62 print "not " unless $x == $q && $x eq $q && $x > $f;
66 $x = sprintf("%llx", $q);
67 print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
70 $x = sprintf("%Lx", $q);
71 print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
74 $x = sprintf("%qx", $q);
75 print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
79 $x = sprintf("%llo", $q);
80 print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
83 $x = sprintf("%Lo", $q);
84 print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
87 $x = sprintf("%qo", $q);
88 print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
92 $x = sprintf("%llb", $q);
93 print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
97 $x = sprintf("%Lb", $q);
98 print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
102 $x = sprintf("%qb", $q);
103 print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
108 $x = sprintf("%llu", $q);
109 print "not " unless $x eq $q && $x > $f;
112 $x = sprintf("%Lu", $q);
113 print "not " unless $x == $q && $x eq $q && $x > $f;
116 $x = sprintf("%qu", $q);
117 print "not " unless $x == $q && $x eq $q && $x > $f;
121 $x = sprintf("%D", $q);
122 print "not " unless $x == $q && $x eq $q && $x > $f;
125 $x = sprintf("%U", $q);
126 print "not " unless $x == $q && $x eq $q && $x > $f;
129 $x = sprintf("%O", $q);
130 print "not " unless oct($x) == $q && oct($x) > $f;
135 print "not " unless $x == 35802467913 && $x > $f;
139 print "not " unless $x == -11111110111 && -$x > $f;
142 if ($^O ne 'unicos') {
144 print "not " unless $x == 15241567763770867 && $x > $f;
148 print "not " unless $x == $q && $x > $f;
151 $x = 98765432109 % 12345678901;
152 print "not " unless $x == 901;
155 # The following 12 tests adapted from op/inc.
157 $a = 9223372036854775807;
159 print "not " unless $a == 9223372036854775808;
162 $a = 9223372036854775807;
165 unless $a == 9223372036854775808 && $c == $a;
168 $a = 9223372036854775807;
171 unless $a == 9223372036854775807 && $c == 9223372036854775808;
174 $a = -9223372036854775808;
176 no warnings 'imprecision';
180 unless $a == -9223372036854775809 && $c == -9223372036854775808;
183 $a = -9223372036854775808;
185 no warnings 'imprecision';
189 unless $a == -9223372036854775809 && $c == $a;
192 $a = -9223372036854775808;
195 unless $a == -9223372036854775808 && $c == -9223372036854775809;
198 $a = 9223372036854775808;
201 no warnings 'imprecision';
205 unless $a == -9223372036854775809 && $c == -9223372036854775808;
208 $a = 9223372036854775808;
211 no warnings 'imprecision';
215 unless $a == -9223372036854775809 && $c == $a;
218 $a = 9223372036854775808;
222 unless $a == -9223372036854775808 && $c == -9223372036854775809;
225 $a = 9223372036854775808;
228 no warnings 'imprecision';
232 unless $b == -$a-1 && $c == -$a;
235 $a = 9223372036854775808;
238 no warnings 'imprecision';
242 unless $b == -$a-1 && $c == $b;
245 $a = 9223372036854775808;
249 unless $b == -(++$a);
253 # Unicos has imprecise doubles (14 decimal digits or so),
254 # especially if operating near the UV/IV limits the low-order bits
255 # become mangled even by simple arithmetic operations.
257 print "ok $_ # skipped: too imprecise numbers\n";
263 print "not " unless (vec($x, 1, 64) = $q) == $q;
266 print "not " unless vec($x, 1, 64) == $q && vec($x, 1, 64) > $f;
269 print "not " unless vec($x, 0, 64) == 0 && vec($x, 2, 64) == 0;
273 print "not " unless ~0 == 0xffffffffffffffff;
276 print "not " unless (0xffffffff<<32) == 0xffffffff00000000;
279 print "not " unless ((0xffffffff)<<32)>>32 == 0xffffffff;
282 print "not " unless 1<<63 == 0x8000000000000000;
285 print "not " unless (sprintf "%#Vx", 1<<63) eq '0x8000000000000000';
288 print "not " unless (0x8000000000000000 | 1) == 0x8000000000000001;
292 unless (0xf000000000000000 & 0x8000000000000000) == 0x8000000000000000;
296 unless (0xf000000000000000 ^ 0xfffffffffffffff0) == 0x0ffffffffffffff0;
301 unless (sprintf "%b", ~0) eq
302 '1111111111111111111111111111111111111111111111111111111111111111';
306 unless (sprintf "%64b", ~0) eq
307 '1111111111111111111111111111111111111111111111111111111111111111';
310 print "not " unless (sprintf "%d", ~0>>1) eq '9223372036854775807';
313 print "not " unless (sprintf "%u", ~0) eq '18446744073709551615';
316 # If the 53..55 fail you have problems in the parser's string->int conversion,
317 # see toke.c:scan_num().
319 $q = -9223372036854775808;
320 print "# $q ne\n# -9223372036854775808\nnot " unless "$q" eq "-9223372036854775808";
323 $q = 9223372036854775807;
324 print "# $q ne\n# 9223372036854775807\nnot " unless "$q" eq "9223372036854775807";
327 $q = 18446744073709551615;
328 print "# $q ne\n# 18446744073709551615\nnot " unless "$q" eq "18446744073709551615";
331 # Test that sv_2nv then sv_2iv is the same as sv_2iv direct
332 # fails if whatever Atol is defined as can't actually cope with >32 bits.
333 my $num = 4294967297;
334 my $string = "4294967297";
340 if ($num eq $string) {
343 print "not ok 56 # \"$num\" ne \"$string\"\n";
346 # Test that sv_2nv then sv_2uv is the same as sv_2uv direct
348 $string = "4294967297";
351 if ($num eq $string) {
354 print "not ok 57 # \"$num\" ne \"$string\"\n";
357 $q = "18446744073709551616e0";
359 print "# \"18446744073709551616e0\" += 0 gives $q\nnot " if "$q" eq "18446744073709551615";
362 # 0xFFFFFFFFFFFFFFFF == 1 * 3 * 5 * 17 * 257 * 641 * 65537 * 6700417'
363 $q = 0xFFFFFFFFFFFFFFFF / 3;
364 if ($q == 0x5555555555555555 and ($q != 0x5555555555555556
365 or !$maths_preserves_UVs)) {
368 print "not ok 59 # 0xFFFFFFFFFFFFFFFF / 3 = $q\n";
369 print "# Should not be floating point\n" if $q =~ tr/e.//;
372 $q = 0xFFFFFFFFFFFFFFFF % 0x5555555555555555;
376 print "not ok 60 # 0xFFFFFFFFFFFFFFFF % 0x5555555555555555 => $q\n";
379 $q = 0xFFFFFFFFFFFFFFFF % 0xFFFFFFFFFFFFFFF0;
383 print "not ok 61 # 0xFFFFFFFFFFFFFFFF % 0xFFFFFFFFFFFFFFF0 => $q\n";
386 $q = 0x8000000000000000 % 9223372036854775807;
390 print "not ok 62 # 0x8000000000000000 % 9223372036854775807 => $q\n";
393 $q = 0x8000000000000000 % -9223372036854775807;
394 if ($q == -9223372036854775806) {
397 print "not ok 63 # 0x8000000000000000 % -9223372036854775807 => $q\n";
402 $q = hex "0x123456789abcdef0";
403 if ($q == 0x123456789abcdef0 and $q != 0x123456789abcdef1) {
406 printf "not ok 64 # hex \"0x123456789abcdef0\" = $q (%X)\n", $q;
407 print "# Should not be floating point\n" if $q =~ tr/e.//;
410 $q = oct "0x123456789abcdef0";
411 if ($q == 0x123456789abcdef0 and $q != 0x123456789abcdef1) {
414 printf "not ok 65 # oct \"0x123456789abcdef0\" = $q (%X)\n", $q;
415 print "# Should not be floating point\n" if $q =~ tr/e.//;
418 $q = oct "765432176543217654321";
419 if ($q == 0765432176543217654321 and $q != 0765432176543217654322) {
422 printf "not ok 66 # oct \"765432176543217654321\" = $q (%o)\n", $q;
423 print "# Should not be floating point\n" if $q =~ tr/e.//;
426 $q = oct "0b0101010101010101010101010101010101010101010101010101010101010101";
427 if ($q == 0x5555555555555555 and $q != 0x5555555555555556) {
430 printf "not ok 67 # oct \"0b0101010101010101010101010101010101010101010101010101010101010101\" = $q (%b)\n", $q;
431 print "# Should not be floating point\n" if $q =~ tr/e.//;