1N/A#./perl
1N/A
1N/ABEGIN {
1N/A eval { my $q = pack "q", 0 };
1N/A if ($@) {
1N/A print "1..0 # Skip: no 64-bit types\n";
1N/A exit(0);
1N/A }
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A}
1N/A
1N/A# This could use many more tests.
1N/A
1N/A# so that using > 0xfffffff constants and
1N/A# 32+ bit integers don't cause noise
1N/Ause warnings;
1N/Ano warnings qw(overflow portable);
1N/A
1N/Aprint "1..67\n";
1N/A
1N/A# as 6 * 6 = 36, the last digit of 6**n will always be six. Hence the last
1N/A# digit of 16**n will always be six. Hence 16**n - 1 will always end in 5.
1N/A# Assumption is that UVs will always be a multiple of 4 bits long.
1N/A
1N/Amy $UV_max = ~0;
1N/Adie "UV_max eq '$UV_max', doesn't end in 5; your UV isn't 4n bits long :-(."
1N/A unless $UV_max =~ /5$/;
1N/Amy $UV_max_less3 = $UV_max - 3;
1N/Amy $maths_preserves_UVs = $UV_max_less3 =~ /^\d+2$/; # 5 - 3 is 2.
1N/Aif ($maths_preserves_UVs) {
1N/A print "# This perl's maths preserves all bits of a UV.\n";
1N/A} else {
1N/A print "# This perl's maths does not preserve all bits of a UV.\n";
1N/A}
1N/A
1N/Amy $q = 12345678901;
1N/Amy $r = 23456789012;
1N/Amy $f = 0xffffffff;
1N/Amy $x;
1N/Amy $y;
1N/A
1N/A$x = unpack "q", pack "q", $q;
1N/Aprint "not " unless $x == $q && $x > $f;
1N/Aprint "ok 1\n";
1N/A
1N/A
1N/A$x = sprintf("%lld", 12345678901);
1N/Aprint "not " unless $x eq $q && $x > $f;
1N/Aprint "ok 2\n";
1N/A
1N/A
1N/A$x = sprintf("%lld", $q);
1N/Aprint "not " unless $x == $q && $x eq $q && $x > $f;
1N/Aprint "ok 3\n";
1N/A
1N/A$x = sprintf("%Ld", $q);
1N/Aprint "not " unless $x == $q && $x eq $q && $x > $f;
1N/Aprint "ok 4\n";
1N/A
1N/A$x = sprintf("%qd", $q);
1N/Aprint "not " unless $x == $q && $x eq $q && $x > $f;
1N/Aprint "ok 5\n";
1N/A
1N/A
1N/A$x = sprintf("%llx", $q);
1N/Aprint "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
1N/Aprint "ok 6\n";
1N/A
1N/A$x = sprintf("%Lx", $q);
1N/Aprint "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
1N/Aprint "ok 7\n";
1N/A
1N/A$x = sprintf("%qx", $q);
1N/Aprint "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
1N/Aprint "ok 8\n";
1N/A
1N/A
1N/A$x = sprintf("%llo", $q);
1N/Aprint "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
1N/Aprint "ok 9\n";
1N/A
1N/A$x = sprintf("%Lo", $q);
1N/Aprint "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
1N/Aprint "ok 10\n";
1N/A
1N/A$x = sprintf("%qo", $q);
1N/Aprint "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
1N/Aprint "ok 11\n";
1N/A
1N/A
1N/A$x = sprintf("%llb", $q);
1N/Aprint "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
1N/A oct("0b$x") > $f;
1N/Aprint "ok 12\n";
1N/A
1N/A$x = sprintf("%Lb", $q);
1N/Aprint "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
1N/A oct("0b$x") > $f;
1N/Aprint "ok 13\n";
1N/A
1N/A$x = sprintf("%qb", $q);
1N/Aprint "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
1N/A oct("0b$x") > $f;
1N/Aprint "ok 14\n";
1N/A
1N/A
1N/A$x = sprintf("%llu", $q);
1N/Aprint "not " unless $x eq $q && $x > $f;
1N/Aprint "ok 15\n";
1N/A
1N/A$x = sprintf("%Lu", $q);
1N/Aprint "not " unless $x == $q && $x eq $q && $x > $f;
1N/Aprint "ok 16\n";
1N/A
1N/A$x = sprintf("%qu", $q);
1N/Aprint "not " unless $x == $q && $x eq $q && $x > $f;
1N/Aprint "ok 17\n";
1N/A
1N/A
1N/A$x = sprintf("%D", $q);
1N/Aprint "not " unless $x == $q && $x eq $q && $x > $f;
1N/Aprint "ok 18\n";
1N/A
1N/A$x = sprintf("%U", $q);
1N/Aprint "not " unless $x == $q && $x eq $q && $x > $f;
1N/Aprint "ok 19\n";
1N/A
1N/A$x = sprintf("%O", $q);
1N/Aprint "not " unless oct($x) == $q && oct($x) > $f;
1N/Aprint "ok 20\n";
1N/A
1N/A
1N/A$x = $q + $r;
1N/Aprint "not " unless $x == 35802467913 && $x > $f;
1N/Aprint "ok 21\n";
1N/A
1N/A$x = $q - $r;
1N/Aprint "not " unless $x == -11111110111 && -$x > $f;
1N/Aprint "ok 22\n";
1N/A
1N/Aif ($^O ne 'unicos') {
1N/A $x = $q * 1234567;
1N/A print "not " unless $x == 15241567763770867 && $x > $f;
1N/A print "ok 23\n";
1N/A
1N/A $x /= 1234567;
1N/A print "not " unless $x == $q && $x > $f;
1N/A print "ok 24\n";
1N/A
1N/A $x = 98765432109 % 12345678901;
1N/A print "not " unless $x == 901;
1N/A print "ok 25\n";
1N/A
1N/A # The following 12 tests adapted from op/inc.
1N/A
1N/A $a = 9223372036854775807;
1N/A $c = $a++;
1N/A print "not " unless $a == 9223372036854775808;
1N/A print "ok 26\n";
1N/A
1N/A $a = 9223372036854775807;
1N/A $c = ++$a;
1N/A print "not "
1N/A unless $a == 9223372036854775808 && $c == $a;
1N/A print "ok 27\n";
1N/A
1N/A $a = 9223372036854775807;
1N/A $c = $a + 1;
1N/A print "not "
1N/A unless $a == 9223372036854775807 && $c == 9223372036854775808;
1N/A print "ok 28\n";
1N/A
1N/A $a = -9223372036854775808;
1N/A $c = $a--;
1N/A print "not "
1N/A unless $a == -9223372036854775809 && $c == -9223372036854775808;
1N/A print "ok 29\n";
1N/A
1N/A $a = -9223372036854775808;
1N/A $c = --$a;
1N/A print "not "
1N/A unless $a == -9223372036854775809 && $c == $a;
1N/A print "ok 30\n";
1N/A
1N/A $a = -9223372036854775808;
1N/A $c = $a - 1;
1N/A print "not "
1N/A unless $a == -9223372036854775808 && $c == -9223372036854775809;
1N/A print "ok 31\n";
1N/A
1N/A $a = 9223372036854775808;
1N/A $a = -$a;
1N/A $c = $a--;
1N/A print "not "
1N/A unless $a == -9223372036854775809 && $c == -9223372036854775808;
1N/A print "ok 32\n";
1N/A
1N/A $a = 9223372036854775808;
1N/A $a = -$a;
1N/A $c = --$a;
1N/A print "not "
1N/A unless $a == -9223372036854775809 && $c == $a;
1N/A print "ok 33\n";
1N/A
1N/A $a = 9223372036854775808;
1N/A $a = -$a;
1N/A $c = $a - 1;
1N/A print "not "
1N/A unless $a == -9223372036854775808 && $c == -9223372036854775809;
1N/A print "ok 34\n";
1N/A
1N/A $a = 9223372036854775808;
1N/A $b = -$a;
1N/A $c = $b--;
1N/A print "not "
1N/A unless $b == -$a-1 && $c == -$a;
1N/A print "ok 35\n";
1N/A
1N/A $a = 9223372036854775808;
1N/A $b = -$a;
1N/A $c = --$b;
1N/A print "not "
1N/A unless $b == -$a-1 && $c == $b;
1N/A print "ok 36\n";
1N/A
1N/A $a = 9223372036854775808;
1N/A $b = -$a;
1N/A $b = $b - 1;
1N/A print "not "
1N/A unless $b == -(++$a);
1N/A print "ok 37\n";
1N/A
1N/A} else {
1N/A # Unicos has imprecise doubles (14 decimal digits or so),
1N/A # especially if operating near the UV/IV limits the low-order bits
1N/A # become mangled even by simple arithmetic operations.
1N/A for (23..37) {
1N/A print "ok $_ # skipped: too imprecise numbers\n";
1N/A }
1N/A}
1N/A
1N/A
1N/A$x = '';
1N/Aprint "not " unless (vec($x, 1, 64) = $q) == $q;
1N/Aprint "ok 38\n";
1N/A
1N/Aprint "not " unless vec($x, 1, 64) == $q && vec($x, 1, 64) > $f;
1N/Aprint "ok 39\n";
1N/A
1N/Aprint "not " unless vec($x, 0, 64) == 0 && vec($x, 2, 64) == 0;
1N/Aprint "ok 40\n";
1N/A
1N/A
1N/Aprint "not " unless ~0 == 0xffffffffffffffff;
1N/Aprint "ok 41\n";
1N/A
1N/Aprint "not " unless (0xffffffff<<32) == 0xffffffff00000000;
1N/Aprint "ok 42\n";
1N/A
1N/Aprint "not " unless ((0xffffffff)<<32)>>32 == 0xffffffff;
1N/Aprint "ok 43\n";
1N/A
1N/Aprint "not " unless 1<<63 == 0x8000000000000000;
1N/Aprint "ok 44\n";
1N/A
1N/Aprint "not " unless (sprintf "%#Vx", 1<<63) eq '0x8000000000000000';
1N/Aprint "ok 45\n";
1N/A
1N/Aprint "not " unless (0x8000000000000000 | 1) == 0x8000000000000001;
1N/Aprint "ok 46\n";
1N/A
1N/Aprint "not "
1N/A unless (0xf000000000000000 & 0x8000000000000000) == 0x8000000000000000;
1N/Aprint "ok 47\n";
1N/A
1N/Aprint "not "
1N/A unless (0xf000000000000000 ^ 0xfffffffffffffff0) == 0x0ffffffffffffff0;
1N/Aprint "ok 48\n";
1N/A
1N/A
1N/Aprint "not "
1N/A unless (sprintf "%b", ~0) eq
1N/A '1111111111111111111111111111111111111111111111111111111111111111';
1N/Aprint "ok 49\n";
1N/A
1N/Aprint "not "
1N/A unless (sprintf "%64b", ~0) eq
1N/A '1111111111111111111111111111111111111111111111111111111111111111';
1N/Aprint "ok 50\n";
1N/A
1N/Aprint "not " unless (sprintf "%d", ~0>>1) eq '9223372036854775807';
1N/Aprint "ok 51\n";
1N/A
1N/Aprint "not " unless (sprintf "%u", ~0) eq '18446744073709551615';
1N/Aprint "ok 52\n";
1N/A
1N/A# If the 53..55 fail you have problems in the parser's string->int conversion,
1N/A# see toke.c:scan_num().
1N/A
1N/A$q = -9223372036854775808;
1N/Aprint "# $q ne\n# -9223372036854775808\nnot " unless "$q" eq "-9223372036854775808";
1N/Aprint "ok 53\n";
1N/A
1N/A$q = 9223372036854775807;
1N/Aprint "# $q ne\n# 9223372036854775807\nnot " unless "$q" eq "9223372036854775807";
1N/Aprint "ok 54\n";
1N/A
1N/A$q = 18446744073709551615;
1N/Aprint "# $q ne\n# 18446744073709551615\nnot " unless "$q" eq "18446744073709551615";
1N/Aprint "ok 55\n";
1N/A
1N/A# Test that sv_2nv then sv_2iv is the same as sv_2iv direct
1N/A# fails if whatever Atol is defined as can't actually cope with >32 bits.
1N/Amy $num = 4294967297;
1N/Amy $string = "4294967297";
1N/A{
1N/A use integer;
1N/A $num += 0;
1N/A $string += 0;
1N/A}
1N/Aif ($num eq $string) {
1N/A print "ok 56\n";
1N/A} else {
1N/A print "not ok 56 # \"$num\" ne \"$string\"\n";
1N/A}
1N/A
1N/A# Test that sv_2nv then sv_2uv is the same as sv_2uv direct
1N/A$num = 4294967297;
1N/A$string = "4294967297";
1N/A$num &= 0;
1N/A$string &= 0;
1N/Aif ($num eq $string) {
1N/A print "ok 57\n";
1N/A} else {
1N/A print "not ok 57 # \"$num\" ne \"$string\"\n";
1N/A}
1N/A
1N/A$q = "18446744073709551616e0";
1N/A$q += 0;
1N/Aprint "# \"18446744073709551616e0\" += 0 gives $q\nnot " if "$q" eq "18446744073709551615";
1N/Aprint "ok 58\n";
1N/A
1N/A# 0xFFFFFFFFFFFFFFFF == 1 * 3 * 5 * 17 * 257 * 641 * 65537 * 6700417'
1N/A$q = 0xFFFFFFFFFFFFFFFF / 3;
1N/Aif ($q == 0x5555555555555555 and ($q != 0x5555555555555556
1N/A or !$maths_preserves_UVs)) {
1N/A print "ok 59\n";
1N/A} else {
1N/A print "not ok 59 # 0xFFFFFFFFFFFFFFFF / 3 = $q\n";
1N/A print "# Should not be floating point\n" if $q =~ tr/e.//;
1N/A}
1N/A
1N/A$q = 0xFFFFFFFFFFFFFFFF % 0x5555555555555555;
1N/Aif ($q == 0) {
1N/A print "ok 60\n";
1N/A} else {
1N/A print "not ok 60 # 0xFFFFFFFFFFFFFFFF % 0x5555555555555555 => $q\n";
1N/A}
1N/A
1N/A$q = 0xFFFFFFFFFFFFFFFF % 0xFFFFFFFFFFFFFFF0;
1N/Aif ($q == 0xF) {
1N/A print "ok 61\n";
1N/A} else {
1N/A print "not ok 61 # 0xFFFFFFFFFFFFFFFF % 0xFFFFFFFFFFFFFFF0 => $q\n";
1N/A}
1N/A
1N/A$q = 0x8000000000000000 % 9223372036854775807;
1N/Aif ($q == 1) {
1N/A print "ok 62\n";
1N/A} else {
1N/A print "not ok 62 # 0x8000000000000000 % 9223372036854775807 => $q\n";
1N/A}
1N/A
1N/A$q = 0x8000000000000000 % -9223372036854775807;
1N/Aif ($q == -9223372036854775806) {
1N/A print "ok 63\n";
1N/A} else {
1N/A print "not ok 63 # 0x8000000000000000 % -9223372036854775807 => $q\n";
1N/A}
1N/A
1N/A{
1N/A use integer;
1N/A $q = hex "0x123456789abcdef0";
1N/A if ($q == 0x123456789abcdef0 and $q != 0x123456789abcdef1) {
1N/A print "ok 64\n";
1N/A } else {
1N/A printf "not ok 64 # hex \"0x123456789abcdef0\" = $q (%X)\n", $q;
1N/A print "# Should not be floating point\n" if $q =~ tr/e.//;
1N/A }
1N/A
1N/A $q = oct "0x123456789abcdef0";
1N/A if ($q == 0x123456789abcdef0 and $q != 0x123456789abcdef1) {
1N/A print "ok 65\n";
1N/A } else {
1N/A printf "not ok 65 # oct \"0x123456789abcdef0\" = $q (%X)\n", $q;
1N/A print "# Should not be floating point\n" if $q =~ tr/e.//;
1N/A }
1N/A
1N/A $q = oct "765432176543217654321";
1N/A if ($q == 0765432176543217654321 and $q != 0765432176543217654322) {
1N/A print "ok 66\n";
1N/A } else {
1N/A printf "not ok 66 # oct \"765432176543217654321\" = $q (%o)\n", $q;
1N/A print "# Should not be floating point\n" if $q =~ tr/e.//;
1N/A }
1N/A
1N/A $q = oct "0b0101010101010101010101010101010101010101010101010101010101010101";
1N/A if ($q == 0x5555555555555555 and $q != 0x5555555555555556) {
1N/A print "ok 67\n";
1N/A } else {
1N/A printf "not ok 67 # oct \"0b0101010101010101010101010101010101010101010101010101010101010101\" = $q (%b)\n", $q;
1N/A print "# Should not be floating point\n" if $q =~ tr/e.//;
1N/A }
1N/A}
1N/A
1N/A# eof