This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix a printf thinko: now quads must have the ll L q prefix.
[perl5.git] / t / op / 64bit.t
CommitLineData
0f4b6630 1BEGIN {
ea2b5ef6 2 eval { my $q = pack "q", 0 };
0f4b6630
JH
3 if ($@) {
4 print "1..0\n# no 64-bit types\n";
5 exit(0);
6 }
ea2b5ef6
JH
7 chdir 't' if -d 't';
8 unshift @INC, '../lib';
0f4b6630
JH
9}
10
11# This could use a lot of more tests.
12#
c5a0f51a 13# Nota bene: bit operations (&, |, ^, ~, <<, >>) are not 64-bit clean.
817e2dcb 14# See the beginning of pp.c and the explanation next to IBW/UBW.
0f4b6630 15
d0ba1bd2
JH
16# so that using > 0xfffffff constants and
17# 32+ bit vector sizes doesn't cause noise
4438c4b7 18no warnings qw(overflow portable);
ea2b5ef6 19
22f3ae8c 20print "1..34\n";
0f4b6630
JH
21
22my $q = 12345678901;
23my $r = 23456789012;
20fe1ea2 24my $f = 0xffffffff;
0f4b6630 25my $x;
2d4389e4 26my $y;
0f4b6630
JH
27
28$x = unpack "q", pack "q", $q;
20fe1ea2 29print "not " unless $x == $q && $x > $f;
0f4b6630
JH
30print "ok 1\n";
31
32
22f3ae8c 33$x = sprintf("%lld", 12345678901);
20fe1ea2 34print "not " unless $x eq $q && $x > $f;
0f4b6630
JH
35print "ok 2\n";
36
37
0f4b6630 38$x = sprintf("%lld", $q);
20fe1ea2 39print "not " unless $x == $q && $x eq $q && $x > $f;
22f3ae8c 40print "ok 3\n";
0f4b6630
JH
41
42$x = sprintf("%Ld", $q);
20fe1ea2 43print "not " unless $x == $q && $x eq $q && $x > $f;
22f3ae8c 44print "ok 4\n";
0f4b6630
JH
45
46$x = sprintf("%qd", $q);
20fe1ea2 47print "not " unless $x == $q && $x eq $q && $x > $f;
22f3ae8c 48print "ok 5\n";
0f4b6630 49
0f4b6630
JH
50
51$x = sprintf("%llx", $q);
20fe1ea2 52print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
22f3ae8c 53print "ok 6\n";
0f4b6630
JH
54
55$x = sprintf("%Lx", $q);
20fe1ea2 56print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
22f3ae8c 57print "ok 7\n";
0f4b6630
JH
58
59$x = sprintf("%qx", $q);
20fe1ea2 60print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
22f3ae8c 61print "ok 8\n";
0f4b6630 62
0f4b6630
JH
63
64$x = sprintf("%llo", $q);
20fe1ea2 65print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
22f3ae8c 66print "ok 9\n";
0f4b6630
JH
67
68$x = sprintf("%Lo", $q);
20fe1ea2 69print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
22f3ae8c 70print "ok 10\n";
0f4b6630
JH
71
72$x = sprintf("%qo", $q);
20fe1ea2 73print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
22f3ae8c 74print "ok 11\n";
0f4b6630 75
0f4b6630
JH
76
77$x = sprintf("%llb", $q);
20fe1ea2
JH
78print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
79 oct("0b$x") > $f;
22f3ae8c 80print "ok 12\n";
0f4b6630
JH
81
82$x = sprintf("%Lb", $q);
20fe1ea2
JH
83print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
84 oct("0b$x") > $f;
22f3ae8c 85print "ok 13\n";
0f4b6630
JH
86
87$x = sprintf("%qb", $q);
20fe1ea2
JH
88print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
89 oct("0b$x") > $f;
22f3ae8c 90print "ok 14\n";
0f4b6630
JH
91
92
22f3ae8c 93$x = sprintf("%llu", $q);
20fe1ea2 94print "not " unless $x eq $q && $x > $f;
22f3ae8c 95print "ok 15\n";
0f4b6630 96
22f3ae8c 97$x = sprintf("%Lu", $q);
20fe1ea2 98print "not " unless $x == $q && $x eq $q && $x > $f;
22f3ae8c 99print "ok 16\n";
0f4b6630 100
22f3ae8c 101$x = sprintf("%qu", $q);
20fe1ea2 102print "not " unless $x == $q && $x eq $q && $x > $f;
22f3ae8c 103print "ok 17\n";
0f4b6630
JH
104
105
29fe7a80 106$x = sprintf("%D", $q);
20fe1ea2 107print "not " unless $x == $q && $x eq $q && $x > $f;
22f3ae8c 108print "ok 18\n";
29fe7a80
JH
109
110$x = sprintf("%U", $q);
20fe1ea2 111print "not " unless $x == $q && $x eq $q && $x > $f;
22f3ae8c 112print "ok 19\n";
29fe7a80
JH
113
114$x = sprintf("%O", $q);
20fe1ea2 115print "not " unless oct($x) == $q && oct($x) > $f;
22f3ae8c 116print "ok 20\n";
29fe7a80
JH
117
118
0f4b6630 119$x = $q + $r;
20fe1ea2 120print "not " unless $x == 35802467913 && $x > $f;
22f3ae8c 121print "ok 21\n";
0f4b6630
JH
122
123$x = $q - $r;
20fe1ea2 124print "not " unless $x == -11111110111 && -$x > $f;
22f3ae8c 125print "ok 22\n";
0f4b6630 126
2d4389e4
JH
127$x = $q * 1234567;
128print "not " unless $x == 15241567763770867 && $x > $f;
22f3ae8c 129print "ok 23\n";
0f4b6630 130
2d4389e4 131$x /= 1234567;
20fe1ea2 132print "not " unless $x == $q && $x > $f;
22f3ae8c 133print "ok 24\n";
0f4b6630
JH
134
135$x = 98765432109 % 12345678901;
136print "not " unless $x == 901;
22f3ae8c 137print "ok 25\n";
2d4389e4
JH
138
139# The following six adapted from op/inc.
140
141$a = 9223372036854775807;
142$c = $a++;
143print "not " unless $a == 9223372036854775808;
22f3ae8c 144print "ok 26\n";
2d4389e4
JH
145
146$a = 9223372036854775807;
147$c = ++$a;
148print "not " unless $a == 9223372036854775808;
22f3ae8c 149print "ok 27\n";
2d4389e4
JH
150
151$a = 9223372036854775807;
152$c = $a + 1;
153print "not " unless $a == 9223372036854775808;
22f3ae8c 154print "ok 28\n";
2d4389e4
JH
155
156$a = -9223372036854775808;
157$c = $a--;
158print "not " unless $a == -9223372036854775809;
22f3ae8c 159print "ok 29\n";
2d4389e4
JH
160
161$a = -9223372036854775808;
162$c = --$a;
163print "not " unless $a == -9223372036854775809;
22f3ae8c 164print "ok 30\n";
2d4389e4
JH
165
166$a = -9223372036854775808;
167$c = $a - 1;
168print "not " unless $a == -9223372036854775809;
22f3ae8c 169print "ok 31\n";
2d4389e4
JH
170
171
c5a0f51a
JH
172$x = '';
173print "not " unless (vec($x, 1, 64) = $q) == $q;
22f3ae8c 174print "ok 32\n";
c5a0f51a
JH
175
176print "not " unless vec($x, 1, 64) == $q && vec($x, 1, 64) > $f;
22f3ae8c 177print "ok 33\n";
c5a0f51a
JH
178
179print "not " unless vec($x, 0, 64) == 0 && vec($x, 2, 64) == 0;
22f3ae8c 180print "ok 34\n";
c5a0f51a
JH
181
182# eof