This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove an obsolete note.
[perl5.git] / t / op / 64bit.t
CommitLineData
e312add1
GS
1#./perl
2
0f4b6630 3BEGIN {
ea2b5ef6 4 eval { my $q = pack "q", 0 };
0f4b6630
JH
5 if ($@) {
6 print "1..0\n# no 64-bit types\n";
7 exit(0);
8 }
ea2b5ef6
JH
9 chdir 't' if -d 't';
10 unshift @INC, '../lib';
0f4b6630
JH
11}
12
13# This could use a lot of more tests.
0f4b6630 14
d0ba1bd2 15# so that using > 0xfffffff constants and
972b05a9 16# 32+ bit integers don't cause noise
4438c4b7 17no warnings qw(overflow portable);
ea2b5ef6 18
e312add1 19print "1..48\n";
0f4b6630
JH
20
21my $q = 12345678901;
22my $r = 23456789012;
20fe1ea2 23my $f = 0xffffffff;
0f4b6630 24my $x;
2d4389e4 25my $y;
0f4b6630
JH
26
27$x = unpack "q", pack "q", $q;
20fe1ea2 28print "not " unless $x == $q && $x > $f;
0f4b6630
JH
29print "ok 1\n";
30
31
22f3ae8c 32$x = sprintf("%lld", 12345678901);
20fe1ea2 33print "not " unless $x eq $q && $x > $f;
0f4b6630
JH
34print "ok 2\n";
35
36
0f4b6630 37$x = sprintf("%lld", $q);
20fe1ea2 38print "not " unless $x == $q && $x eq $q && $x > $f;
22f3ae8c 39print "ok 3\n";
0f4b6630
JH
40
41$x = sprintf("%Ld", $q);
20fe1ea2 42print "not " unless $x == $q && $x eq $q && $x > $f;
22f3ae8c 43print "ok 4\n";
0f4b6630
JH
44
45$x = sprintf("%qd", $q);
20fe1ea2 46print "not " unless $x == $q && $x eq $q && $x > $f;
22f3ae8c 47print "ok 5\n";
0f4b6630 48
0f4b6630
JH
49
50$x = sprintf("%llx", $q);
20fe1ea2 51print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
22f3ae8c 52print "ok 6\n";
0f4b6630
JH
53
54$x = sprintf("%Lx", $q);
20fe1ea2 55print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
22f3ae8c 56print "ok 7\n";
0f4b6630
JH
57
58$x = sprintf("%qx", $q);
20fe1ea2 59print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
22f3ae8c 60print "ok 8\n";
0f4b6630 61
0f4b6630
JH
62
63$x = sprintf("%llo", $q);
20fe1ea2 64print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
22f3ae8c 65print "ok 9\n";
0f4b6630
JH
66
67$x = sprintf("%Lo", $q);
20fe1ea2 68print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
22f3ae8c 69print "ok 10\n";
0f4b6630
JH
70
71$x = sprintf("%qo", $q);
20fe1ea2 72print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
22f3ae8c 73print "ok 11\n";
0f4b6630 74
0f4b6630
JH
75
76$x = sprintf("%llb", $q);
20fe1ea2
JH
77print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
78 oct("0b$x") > $f;
22f3ae8c 79print "ok 12\n";
0f4b6630
JH
80
81$x = sprintf("%Lb", $q);
20fe1ea2
JH
82print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
83 oct("0b$x") > $f;
22f3ae8c 84print "ok 13\n";
0f4b6630
JH
85
86$x = sprintf("%qb", $q);
20fe1ea2
JH
87print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
88 oct("0b$x") > $f;
22f3ae8c 89print "ok 14\n";
0f4b6630
JH
90
91
22f3ae8c 92$x = sprintf("%llu", $q);
20fe1ea2 93print "not " unless $x eq $q && $x > $f;
22f3ae8c 94print "ok 15\n";
0f4b6630 95
22f3ae8c 96$x = sprintf("%Lu", $q);
20fe1ea2 97print "not " unless $x == $q && $x eq $q && $x > $f;
22f3ae8c 98print "ok 16\n";
0f4b6630 99
22f3ae8c 100$x = sprintf("%qu", $q);
20fe1ea2 101print "not " unless $x == $q && $x eq $q && $x > $f;
22f3ae8c 102print "ok 17\n";
0f4b6630
JH
103
104
29fe7a80 105$x = sprintf("%D", $q);
20fe1ea2 106print "not " unless $x == $q && $x eq $q && $x > $f;
22f3ae8c 107print "ok 18\n";
29fe7a80
JH
108
109$x = sprintf("%U", $q);
20fe1ea2 110print "not " unless $x == $q && $x eq $q && $x > $f;
22f3ae8c 111print "ok 19\n";
29fe7a80
JH
112
113$x = sprintf("%O", $q);
20fe1ea2 114print "not " unless oct($x) == $q && oct($x) > $f;
22f3ae8c 115print "ok 20\n";
29fe7a80
JH
116
117
0f4b6630 118$x = $q + $r;
20fe1ea2 119print "not " unless $x == 35802467913 && $x > $f;
22f3ae8c 120print "ok 21\n";
0f4b6630
JH
121
122$x = $q - $r;
20fe1ea2 123print "not " unless $x == -11111110111 && -$x > $f;
22f3ae8c 124print "ok 22\n";
0f4b6630 125
2d4389e4
JH
126$x = $q * 1234567;
127print "not " unless $x == 15241567763770867 && $x > $f;
22f3ae8c 128print "ok 23\n";
0f4b6630 129
2d4389e4 130$x /= 1234567;
20fe1ea2 131print "not " unless $x == $q && $x > $f;
22f3ae8c 132print "ok 24\n";
0f4b6630
JH
133
134$x = 98765432109 % 12345678901;
135print "not " unless $x == 901;
22f3ae8c 136print "ok 25\n";
2d4389e4 137
e312add1 138# The following 12 tests adapted from op/inc.
2d4389e4
JH
139
140$a = 9223372036854775807;
141$c = $a++;
142print "not " unless $a == 9223372036854775808;
22f3ae8c 143print "ok 26\n";
2d4389e4
JH
144
145$a = 9223372036854775807;
146$c = ++$a;
44d27a6e 147print "not " unless $a == 9223372036854775808 && $c == $a;
22f3ae8c 148print "ok 27\n";
2d4389e4
JH
149
150$a = 9223372036854775807;
151$c = $a + 1;
44d27a6e 152print "not " unless $a == 9223372036854775807 && $c == 9223372036854775808;
22f3ae8c 153print "ok 28\n";
2d4389e4
JH
154
155$a = -9223372036854775808;
156$c = $a--;
44d27a6e 157print "not " unless $a == -9223372036854775809 && $c == -9223372036854775808;
22f3ae8c 158print "ok 29\n";
2d4389e4
JH
159
160$a = -9223372036854775808;
161$c = --$a;
44d27a6e 162print "not " unless $a == -9223372036854775809 && $c == $a;
22f3ae8c 163print "ok 30\n";
2d4389e4
JH
164
165$a = -9223372036854775808;
166$c = $a - 1;
44d27a6e 167print "not " unless $a == -9223372036854775808 && $c == -9223372036854775809;
22f3ae8c 168print "ok 31\n";
2d4389e4 169
e312add1
GS
170$a = 9223372036854775808;
171$a = -$a;
172$c = $a--;
173print "not " unless $a == -9223372036854775809 && $c == -9223372036854775808;
174print "ok 32\n";
175
176$a = 9223372036854775808;
177$a = -$a;
178$c = --$a;
179print "not " unless $a == -9223372036854775809 && $c == $a;
180print "ok 33\n";
181
182$a = 9223372036854775808;
183$a = -$a;
184$c = $a - 1;
185print "not " unless $a == -9223372036854775808 && $c == -9223372036854775809;
186print "ok 34\n";
187
188$a = 9223372036854775808;
189$b = -$a;
190$c = $b--;
191print "not " unless $b == -$a-1 && $c == -$a;
192print "ok 35\n";
193
194$a = 9223372036854775808;
195$b = -$a;
196$c = --$b;
197print "not " unless $b == -$a-1 && $c == $b;
198print "ok 36\n";
199
200$a = 9223372036854775808;
201$b = -$a;
202$b = $b - 1;
203print "not " unless $b == -(++$a);
204print "ok 37\n";
205
2d4389e4 206
c5a0f51a
JH
207$x = '';
208print "not " unless (vec($x, 1, 64) = $q) == $q;
e312add1 209print "ok 38\n";
c5a0f51a
JH
210
211print "not " unless vec($x, 1, 64) == $q && vec($x, 1, 64) > $f;
e312add1 212print "ok 39\n";
c5a0f51a
JH
213
214print "not " unless vec($x, 0, 64) == 0 && vec($x, 2, 64) == 0;
e312add1 215print "ok 40\n";
c5a0f51a 216
972b05a9
JH
217
218print "not " unless ~0 == 0xffffffffffffffff;
e312add1 219print "ok 41\n";
972b05a9
JH
220
221print "not " unless (0xffffffff<<32) == 0xffffffff00000000;
e312add1 222print "ok 42\n";
972b05a9
JH
223
224print "not " unless ((0xffffffff)<<32)>>32 == 0xffffffff;
e312add1 225print "ok 43\n";
972b05a9
JH
226
227print "not " unless 1<<63 == 0x8000000000000000;
e312add1 228print "ok 44\n";
972b05a9
JH
229
230print "not " unless (sprintf "%#Vx", 1<<63) eq '0x8000000000000000';
e312add1 231print "ok 45\n";
972b05a9
JH
232
233print "not " unless (0x8000000000000000 | 1) == 0x8000000000000001;
e312add1 234print "ok 46\n";
972b05a9
JH
235
236print "not " unless (0xf000000000000000 & 0x8000000000000000) == 0x8000000000000000;
e312add1 237print "ok 47\n";
972b05a9
JH
238
239print "not " unless (0xf000000000000000 ^ 0xfffffffffffffff0) == 0x0ffffffffffffff0;
e312add1 240print "ok 48\n";
972b05a9 241
c5a0f51a 242# eof