Commit | Line | Data |
---|---|---|
0f4b6630 | 1 | BEGIN { |
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 | 16 | # so that using > 0xfffffff constants and |
972b05a9 | 17 | # 32+ bit integers don't cause noise |
4438c4b7 | 18 | no warnings qw(overflow portable); |
ea2b5ef6 | 19 | |
972b05a9 | 20 | print "1..42\n"; |
0f4b6630 JH |
21 | |
22 | my $q = 12345678901; | |
23 | my $r = 23456789012; | |
20fe1ea2 | 24 | my $f = 0xffffffff; |
0f4b6630 | 25 | my $x; |
2d4389e4 | 26 | my $y; |
0f4b6630 JH |
27 | |
28 | $x = unpack "q", pack "q", $q; | |
20fe1ea2 | 29 | print "not " unless $x == $q && $x > $f; |
0f4b6630 JH |
30 | print "ok 1\n"; |
31 | ||
32 | ||
22f3ae8c | 33 | $x = sprintf("%lld", 12345678901); |
20fe1ea2 | 34 | print "not " unless $x eq $q && $x > $f; |
0f4b6630 JH |
35 | print "ok 2\n"; |
36 | ||
37 | ||
0f4b6630 | 38 | $x = sprintf("%lld", $q); |
20fe1ea2 | 39 | print "not " unless $x == $q && $x eq $q && $x > $f; |
22f3ae8c | 40 | print "ok 3\n"; |
0f4b6630 JH |
41 | |
42 | $x = sprintf("%Ld", $q); | |
20fe1ea2 | 43 | print "not " unless $x == $q && $x eq $q && $x > $f; |
22f3ae8c | 44 | print "ok 4\n"; |
0f4b6630 JH |
45 | |
46 | $x = sprintf("%qd", $q); | |
20fe1ea2 | 47 | print "not " unless $x == $q && $x eq $q && $x > $f; |
22f3ae8c | 48 | print "ok 5\n"; |
0f4b6630 | 49 | |
0f4b6630 JH |
50 | |
51 | $x = sprintf("%llx", $q); | |
20fe1ea2 | 52 | print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f; |
22f3ae8c | 53 | print "ok 6\n"; |
0f4b6630 JH |
54 | |
55 | $x = sprintf("%Lx", $q); | |
20fe1ea2 | 56 | print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f; |
22f3ae8c | 57 | print "ok 7\n"; |
0f4b6630 JH |
58 | |
59 | $x = sprintf("%qx", $q); | |
20fe1ea2 | 60 | print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f; |
22f3ae8c | 61 | print "ok 8\n"; |
0f4b6630 | 62 | |
0f4b6630 JH |
63 | |
64 | $x = sprintf("%llo", $q); | |
20fe1ea2 | 65 | print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f; |
22f3ae8c | 66 | print "ok 9\n"; |
0f4b6630 JH |
67 | |
68 | $x = sprintf("%Lo", $q); | |
20fe1ea2 | 69 | print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f; |
22f3ae8c | 70 | print "ok 10\n"; |
0f4b6630 JH |
71 | |
72 | $x = sprintf("%qo", $q); | |
20fe1ea2 | 73 | print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f; |
22f3ae8c | 74 | print "ok 11\n"; |
0f4b6630 | 75 | |
0f4b6630 JH |
76 | |
77 | $x = sprintf("%llb", $q); | |
20fe1ea2 JH |
78 | print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 && |
79 | oct("0b$x") > $f; | |
22f3ae8c | 80 | print "ok 12\n"; |
0f4b6630 JH |
81 | |
82 | $x = sprintf("%Lb", $q); | |
20fe1ea2 JH |
83 | print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 && |
84 | oct("0b$x") > $f; | |
22f3ae8c | 85 | print "ok 13\n"; |
0f4b6630 JH |
86 | |
87 | $x = sprintf("%qb", $q); | |
20fe1ea2 JH |
88 | print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 && |
89 | oct("0b$x") > $f; | |
22f3ae8c | 90 | print "ok 14\n"; |
0f4b6630 JH |
91 | |
92 | ||
22f3ae8c | 93 | $x = sprintf("%llu", $q); |
20fe1ea2 | 94 | print "not " unless $x eq $q && $x > $f; |
22f3ae8c | 95 | print "ok 15\n"; |
0f4b6630 | 96 | |
22f3ae8c | 97 | $x = sprintf("%Lu", $q); |
20fe1ea2 | 98 | print "not " unless $x == $q && $x eq $q && $x > $f; |
22f3ae8c | 99 | print "ok 16\n"; |
0f4b6630 | 100 | |
22f3ae8c | 101 | $x = sprintf("%qu", $q); |
20fe1ea2 | 102 | print "not " unless $x == $q && $x eq $q && $x > $f; |
22f3ae8c | 103 | print "ok 17\n"; |
0f4b6630 JH |
104 | |
105 | ||
29fe7a80 | 106 | $x = sprintf("%D", $q); |
20fe1ea2 | 107 | print "not " unless $x == $q && $x eq $q && $x > $f; |
22f3ae8c | 108 | print "ok 18\n"; |
29fe7a80 JH |
109 | |
110 | $x = sprintf("%U", $q); | |
20fe1ea2 | 111 | print "not " unless $x == $q && $x eq $q && $x > $f; |
22f3ae8c | 112 | print "ok 19\n"; |
29fe7a80 JH |
113 | |
114 | $x = sprintf("%O", $q); | |
20fe1ea2 | 115 | print "not " unless oct($x) == $q && oct($x) > $f; |
22f3ae8c | 116 | print "ok 20\n"; |
29fe7a80 JH |
117 | |
118 | ||
0f4b6630 | 119 | $x = $q + $r; |
20fe1ea2 | 120 | print "not " unless $x == 35802467913 && $x > $f; |
22f3ae8c | 121 | print "ok 21\n"; |
0f4b6630 JH |
122 | |
123 | $x = $q - $r; | |
20fe1ea2 | 124 | print "not " unless $x == -11111110111 && -$x > $f; |
22f3ae8c | 125 | print "ok 22\n"; |
0f4b6630 | 126 | |
2d4389e4 JH |
127 | $x = $q * 1234567; |
128 | print "not " unless $x == 15241567763770867 && $x > $f; | |
22f3ae8c | 129 | print "ok 23\n"; |
0f4b6630 | 130 | |
2d4389e4 | 131 | $x /= 1234567; |
20fe1ea2 | 132 | print "not " unless $x == $q && $x > $f; |
22f3ae8c | 133 | print "ok 24\n"; |
0f4b6630 JH |
134 | |
135 | $x = 98765432109 % 12345678901; | |
136 | print "not " unless $x == 901; | |
22f3ae8c | 137 | print "ok 25\n"; |
2d4389e4 JH |
138 | |
139 | # The following six adapted from op/inc. | |
140 | ||
141 | $a = 9223372036854775807; | |
142 | $c = $a++; | |
143 | print "not " unless $a == 9223372036854775808; | |
22f3ae8c | 144 | print "ok 26\n"; |
2d4389e4 JH |
145 | |
146 | $a = 9223372036854775807; | |
147 | $c = ++$a; | |
44d27a6e | 148 | print "not " unless $a == 9223372036854775808 && $c == $a; |
22f3ae8c | 149 | print "ok 27\n"; |
2d4389e4 JH |
150 | |
151 | $a = 9223372036854775807; | |
152 | $c = $a + 1; | |
44d27a6e | 153 | print "not " unless $a == 9223372036854775807 && $c == 9223372036854775808; |
22f3ae8c | 154 | print "ok 28\n"; |
2d4389e4 JH |
155 | |
156 | $a = -9223372036854775808; | |
157 | $c = $a--; | |
44d27a6e | 158 | print "not " unless $a == -9223372036854775809 && $c == -9223372036854775808; |
22f3ae8c | 159 | print "ok 29\n"; |
2d4389e4 JH |
160 | |
161 | $a = -9223372036854775808; | |
162 | $c = --$a; | |
44d27a6e | 163 | print "not " unless $a == -9223372036854775809 && $c == $a; |
22f3ae8c | 164 | print "ok 30\n"; |
2d4389e4 JH |
165 | |
166 | $a = -9223372036854775808; | |
167 | $c = $a - 1; | |
44d27a6e | 168 | print "not " unless $a == -9223372036854775808 && $c == -9223372036854775809; |
22f3ae8c | 169 | print "ok 31\n"; |
2d4389e4 JH |
170 | |
171 | ||
c5a0f51a JH |
172 | $x = ''; |
173 | print "not " unless (vec($x, 1, 64) = $q) == $q; | |
22f3ae8c | 174 | print "ok 32\n"; |
c5a0f51a JH |
175 | |
176 | print "not " unless vec($x, 1, 64) == $q && vec($x, 1, 64) > $f; | |
22f3ae8c | 177 | print "ok 33\n"; |
c5a0f51a JH |
178 | |
179 | print "not " unless vec($x, 0, 64) == 0 && vec($x, 2, 64) == 0; | |
22f3ae8c | 180 | print "ok 34\n"; |
c5a0f51a | 181 | |
972b05a9 JH |
182 | |
183 | print "not " unless ~0 == 0xffffffffffffffff; | |
184 | print "ok 35\n"; | |
185 | ||
186 | print "not " unless (0xffffffff<<32) == 0xffffffff00000000; | |
187 | print "ok 36\n"; | |
188 | ||
189 | print "not " unless ((0xffffffff)<<32)>>32 == 0xffffffff; | |
190 | print "ok 37\n"; | |
191 | ||
192 | print "not " unless 1<<63 == 0x8000000000000000; | |
193 | print "ok 38\n"; | |
194 | ||
195 | print "not " unless (sprintf "%#Vx", 1<<63) eq '0x8000000000000000'; | |
196 | print "ok 39\n"; | |
197 | ||
198 | print "not " unless (0x8000000000000000 | 1) == 0x8000000000000001; | |
199 | print "ok 40\n"; | |
200 | ||
201 | print "not " unless (0xf000000000000000 & 0x8000000000000000) == 0x8000000000000000; | |
202 | print "ok 41\n"; | |
203 | ||
204 | print "not " unless (0xf000000000000000 ^ 0xfffffffffffffff0) == 0x0ffffffffffffff0; | |
205 | print "ok 42\n"; | |
206 | ||
c5a0f51a | 207 | # eof |