Hints and test tweaks for Unicos.
[p5sagit/p5-mst-13.2.git] / t / op / 64bitint.t
1 #./perl
2
3 BEGIN {
4         eval { my $q = pack "q", 0 };
5         if ($@) {
6                 print "1..0\n# no 64-bit types\n";
7                 exit(0);
8         }
9         chdir 't' if -d 't';
10         unshift @INC, '../lib';
11 }
12
13 # This could use many more tests.
14
15 # so that using > 0xfffffff constants and
16 # 32+ bit integers don't cause noise
17 no warnings qw(overflow portable);
18
19 print "1..52\n";
20
21 my $q = 12345678901;
22 my $r = 23456789012;
23 my $f = 0xffffffff;
24 my $x;
25 my $y;
26
27 $x = unpack "q", pack "q", $q;
28 print "not " unless $x == $q && $x > $f;
29 print "ok 1\n";
30
31
32 $x = sprintf("%lld", 12345678901);
33 print "not " unless $x eq $q && $x > $f;
34 print "ok 2\n";
35
36
37 $x = sprintf("%lld", $q);
38 print "not " unless $x == $q && $x eq $q && $x > $f;
39 print "ok 3\n";
40
41 $x = sprintf("%Ld", $q);
42 print "not " unless $x == $q && $x eq $q && $x > $f;
43 print "ok 4\n";
44
45 $x = sprintf("%qd", $q);
46 print "not " unless $x == $q && $x eq $q && $x > $f;
47 print "ok 5\n";
48
49
50 $x = sprintf("%llx", $q);
51 print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
52 print "ok 6\n";
53
54 $x = sprintf("%Lx", $q);
55 print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
56 print "ok 7\n";
57
58 $x = sprintf("%qx", $q);
59 print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
60 print "ok 8\n";
61
62
63 $x = sprintf("%llo", $q);
64 print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
65 print "ok 9\n";
66
67 $x = sprintf("%Lo", $q);
68 print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
69 print "ok 10\n";
70
71 $x = sprintf("%qo", $q);
72 print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
73 print "ok 11\n";
74
75
76 $x = sprintf("%llb", $q);
77 print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
78                     oct("0b$x") > $f;
79 print "ok 12\n";
80
81 $x = sprintf("%Lb", $q);
82 print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
83                                    oct("0b$x") > $f;
84 print "ok 13\n";
85
86 $x = sprintf("%qb", $q);
87 print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
88                     oct("0b$x") > $f;
89 print "ok 14\n";
90
91
92 $x = sprintf("%llu", $q);
93 print "not " unless $x eq $q && $x > $f;
94 print "ok 15\n";
95
96 $x = sprintf("%Lu", $q);
97 print "not " unless $x == $q && $x eq $q && $x > $f;
98 print "ok 16\n";
99
100 $x = sprintf("%qu", $q);
101 print "not " unless $x == $q && $x eq $q && $x > $f;
102 print "ok 17\n";
103
104
105 $x = sprintf("%D", $q);
106 print "not " unless $x == $q && $x eq $q && $x > $f;
107 print "ok 18\n";
108
109 $x = sprintf("%U", $q);
110 print "not " unless $x == $q && $x eq $q && $x > $f;
111 print "ok 19\n";
112
113 $x = sprintf("%O", $q);
114 print "not " unless oct($x) == $q && oct($x) > $f;
115 print "ok 20\n";
116
117
118 $x = $q + $r;
119 print "not " unless $x == 35802467913 && $x > $f;
120 print "ok 21\n";
121
122 $x = $q - $r;
123 print "not " unless $x == -11111110111 && -$x > $f;
124 print "ok 22\n";
125
126 if ($^O ne 'unicos') {
127     $x = $q * 1234567;
128     print "not " unless $x == 15241567763770867 && $x > $f;
129     print "ok 23\n";
130 } else {
131     # Unicos has imprecise doubles (14 decimal digits or so),
132     # the multiplication mangles the low-order bits.
133     $x = $q * 1234;
134     print "not " unless $x == 15234567763834 && $x > $f;
135     print "ok 23\n";
136 }
137
138 $x /= 1234567;
139 print "not " unless $x == $q && $x > $f;
140 print "ok 24\n";
141
142 $x = 98765432109 % 12345678901;
143 print "not " unless $x == 901;
144 print "ok 25\n";
145
146 # The following 12 tests adapted from op/inc.
147
148 if ($^O ne 'unicos') {
149     $a = 9223372036854775807;
150     $c = $a++;
151     print "not " unless $a == 9223372036854775808;
152     print "ok 26\n";
153
154     $a = 9223372036854775807;
155     $c = ++$a;
156     print "not "
157         unless $a == 9223372036854775808 && $c == $a;
158     print "ok 27\n";
159
160     $a = 9223372036854775807;
161     $c = $a + 1;
162     print "not "
163         unless $a == 9223372036854775807 && $c == 9223372036854775808;
164     print "ok 28\n";
165
166     $a = -9223372036854775808;
167     $c = $a--;
168     print "not "
169         unless $a == -9223372036854775809 && $c == -9223372036854775808;
170     print "ok 29\n";
171
172     $a = -9223372036854775808;
173     $c = --$a;
174     print "not "
175         unless $a == -9223372036854775809 && $c == $a;
176     print "ok 30\n";
177
178     $a = -9223372036854775808;
179     $c = $a - 1;
180     print "not "
181         unless $a == -9223372036854775808 && $c == -9223372036854775809;
182     print "ok 31\n";
183     
184     $a = 9223372036854775808;
185     $a = -$a;
186     $c = $a--;
187     print "not "
188         unless $a == -9223372036854775809 && $c == -9223372036854775808;
189     print "ok 32\n";
190     
191     $a = 9223372036854775808;
192     $a = -$a;
193     $c = --$a;
194     print "not "
195         unless $a == -9223372036854775809 && $c == $a;
196     print "ok 33\n";
197     
198     $a = 9223372036854775808;
199     $a = -$a;
200     $c = $a - 1;
201     print "not "
202         unless $a == -9223372036854775808 && $c == -9223372036854775809;
203     print "ok 34\n";
204
205     $a = 9223372036854775808;
206     $b = -$a;
207     $c = $b--;
208     print "not "
209         unless $b == -$a-1 && $c == -$a;
210     print "ok 35\n";
211
212     $a = 9223372036854775808;
213     $b = -$a;
214     $c = --$b;
215     print "not "
216         unless $b == -$a-1 && $c == $b;
217     print "ok 36\n";
218
219     $a = 9223372036854775808;
220     $b = -$a;
221     $b = $b - 1;
222     print "not "
223         unless $b == -(++$a);
224     print "ok 37\n";
225
226 } else {
227     # Unicos has imprecise doubles (14 decimal digits or so),
228     # near the UV/IV limites the low-order bits become mangled
229     # even by simple additions and subtractions.
230     for (26..37) {
231         print "ok #_ # skipped: too imprecise numbers\n";
232     }
233 }
234
235
236 $x = '';
237 print "not " unless (vec($x, 1, 64) = $q) == $q;
238 print "ok 38\n";
239
240 print "not " unless vec($x, 1, 64) == $q && vec($x, 1, 64) > $f;
241 print "ok 39\n";
242
243 print "not " unless vec($x, 0, 64) == 0 && vec($x, 2, 64) == 0;
244 print "ok 40\n";
245
246
247 print "not " unless ~0 == 0xffffffffffffffff;
248 print "ok 41\n";
249
250 print "not " unless (0xffffffff<<32) == 0xffffffff00000000;
251 print "ok 42\n";
252
253 print "not " unless ((0xffffffff)<<32)>>32 == 0xffffffff;
254 print "ok 43\n";
255
256 print "not " unless 1<<63 == 0x8000000000000000;
257 print "ok 44\n";
258
259 print "not " unless (sprintf "%#Vx", 1<<63) eq '0x8000000000000000';
260 print "ok 45\n";
261
262 print "not " unless (0x8000000000000000 | 1) == 0x8000000000000001;
263 print "ok 46\n";
264
265 print "not "
266     unless (0xf000000000000000 & 0x8000000000000000) == 0x8000000000000000;
267 print "ok 47\n";
268
269 print "not "
270     unless (0xf000000000000000 ^ 0xfffffffffffffff0) == 0x0ffffffffffffff0;
271 print "ok 48\n";
272
273
274 print "not "
275     unless (sprintf "%b", ~0)   eq
276            '1111111111111111111111111111111111111111111111111111111111111111';
277 print "ok 49\n";
278
279 print "not "
280     unless (sprintf "%64b", ~0) eq
281            '1111111111111111111111111111111111111111111111111111111111111111';
282 print "ok 50\n";
283
284 print "not " unless (sprintf "%d", ~0>>1) eq '9223372036854775807';
285 print "ok 51\n";
286
287 print "not " unless (sprintf "%u", ~0)    eq '18446744073709551615';
288 print "ok 52\n";
289
290 # eof