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