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;
177 unless $a == -9223372036854775809 && $c == -9223372036854775808;
180 $a = -9223372036854775808;
183 unless $a == -9223372036854775809 && $c == $a;
186 $a = -9223372036854775808;
189 unless $a == -9223372036854775808 && $c == -9223372036854775809;
192 $a = 9223372036854775808;
196 unless $a == -9223372036854775809 && $c == -9223372036854775808;
199 $a = 9223372036854775808;
203 unless $a == -9223372036854775809 && $c == $a;
206 $a = 9223372036854775808;
210 unless $a == -9223372036854775808 && $c == -9223372036854775809;
213 $a = 9223372036854775808;
217 unless $b == -$a-1 && $c == -$a;
220 $a = 9223372036854775808;
224 unless $b == -$a-1 && $c == $b;
227 $a = 9223372036854775808;
231 unless $b == -(++$a);
235 # Unicos has imprecise doubles (14 decimal digits or so),
236 # especially if operating near the UV/IV limits the low-order bits
237 # become mangled even by simple arithmetic operations.
239 print "ok $_ # skipped: too imprecise numbers\n";
245 print "not " unless (vec($x, 1, 64) = $q) == $q;
248 print "not " unless vec($x, 1, 64) == $q && vec($x, 1, 64) > $f;
251 print "not " unless vec($x, 0, 64) == 0 && vec($x, 2, 64) == 0;
255 print "not " unless ~0 == 0xffffffffffffffff;
258 print "not " unless (0xffffffff<<32) == 0xffffffff00000000;
261 print "not " unless ((0xffffffff)<<32)>>32 == 0xffffffff;
264 print "not " unless 1<<63 == 0x8000000000000000;
267 print "not " unless (sprintf "%#Vx", 1<<63) eq '0x8000000000000000';
270 print "not " unless (0x8000000000000000 | 1) == 0x8000000000000001;
274 unless (0xf000000000000000 & 0x8000000000000000) == 0x8000000000000000;
278 unless (0xf000000000000000 ^ 0xfffffffffffffff0) == 0x0ffffffffffffff0;
283 unless (sprintf "%b", ~0) eq
284 '1111111111111111111111111111111111111111111111111111111111111111';
288 unless (sprintf "%64b", ~0) eq
289 '1111111111111111111111111111111111111111111111111111111111111111';
292 print "not " unless (sprintf "%d", ~0>>1) eq '9223372036854775807';
295 print "not " unless (sprintf "%u", ~0) eq '18446744073709551615';
298 # If the 53..55 fail you have problems in the parser's string->int conversion,
299 # see toke.c:scan_num().
301 $q = -9223372036854775808;
302 print "# $q ne\n# -9223372036854775808\nnot " unless "$q" eq "-9223372036854775808";
305 $q = 9223372036854775807;
306 print "# $q ne\n# 9223372036854775807\nnot " unless "$q" eq "9223372036854775807";
309 $q = 18446744073709551615;
310 print "# $q ne\n# 18446744073709551615\nnot " unless "$q" eq "18446744073709551615";
313 # Test that sv_2nv then sv_2iv is the same as sv_2iv direct
314 # fails if whatever Atol is defined as can't actually cope with >32 bits.
315 my $num = 4294967297;
316 my $string = "4294967297";
322 if ($num eq $string) {
325 print "not ok 56 # \"$num\" ne \"$string\"\n";
328 # Test that sv_2nv then sv_2uv is the same as sv_2uv direct
330 $string = "4294967297";
333 if ($num eq $string) {
336 print "not ok 57 # \"$num\" ne \"$string\"\n";
339 $q = "18446744073709551616e0";
341 print "# \"18446744073709551616e0\" += 0 gives $q\nnot " if "$q" eq "18446744073709551615";
344 # 0xFFFFFFFFFFFFFFFF == 1 * 3 * 5 * 17 * 257 * 641 * 65537 * 6700417'
345 $q = 0xFFFFFFFFFFFFFFFF / 3;
346 if ($q == 0x5555555555555555 and ($q != 0x5555555555555556
347 or !$maths_preserves_UVs)) {
350 print "not ok 59 # 0xFFFFFFFFFFFFFFFF / 3 = $q\n";
351 print "# Should not be floating point\n" if $q =~ tr/e.//;
354 $q = 0xFFFFFFFFFFFFFFFF % 0x5555555555555555;
358 print "not ok 60 # 0xFFFFFFFFFFFFFFFF % 0x5555555555555555 => $q\n";
361 $q = 0xFFFFFFFFFFFFFFFF % 0xFFFFFFFFFFFFFFF0;
365 print "not ok 61 # 0xFFFFFFFFFFFFFFFF % 0xFFFFFFFFFFFFFFF0 => $q\n";
368 $q = 0x8000000000000000 % 9223372036854775807;
372 print "not ok 62 # 0x8000000000000000 % 9223372036854775807 => $q\n";
375 $q = 0x8000000000000000 % -9223372036854775807;
376 if ($q == -9223372036854775806) {
379 print "not ok 63 # 0x8000000000000000 % -9223372036854775807 => $q\n";
384 $q = hex "0x123456789abcdef0";
385 if ($q == 0x123456789abcdef0 and $q != 0x123456789abcdef1) {
388 printf "not ok 64 # hex \"0x123456789abcdef0\" = $q (%X)\n", $q;
389 print "# Should not be floating point\n" if $q =~ tr/e.//;
392 $q = oct "0x123456789abcdef0";
393 if ($q == 0x123456789abcdef0 and $q != 0x123456789abcdef1) {
396 printf "not ok 65 # oct \"0x123456789abcdef0\" = $q (%X)\n", $q;
397 print "# Should not be floating point\n" if $q =~ tr/e.//;
400 $q = oct "765432176543217654321";
401 if ($q == 0765432176543217654321 and $q != 0765432176543217654322) {
404 printf "not ok 66 # oct \"765432176543217654321\" = $q (%o)\n", $q;
405 print "# Should not be floating point\n" if $q =~ tr/e.//;
408 $q = oct "0b0101010101010101010101010101010101010101010101010101010101010101";
409 if ($q == 0x5555555555555555 and $q != 0x5555555555555556) {
412 printf "not ok 67 # oct \"0b0101010101010101010101010101010101010101010101010101010101010101\" = $q (%b)\n", $q;
413 print "# Should not be floating point\n" if $q =~ tr/e.//;