This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
More 64-bit fixing. One known bug of that kind
[perl5.git] / t / op / 64bit.t
CommitLineData
0f4b6630
JH
1BEGIN {
2 eval { pack "q", 0 };
3 if ($@) {
4 print "1..0\n# no 64-bit types\n";
5 exit(0);
6 }
7}
8
9# This could use a lot of more tests.
10#
11# Nota bene: bit operations are not 64-bit clean. See the beginning
12# of pp.c and the explanation next to IBW/UBW.
13
14print "1..27\n";
15
16my $q = 12345678901;
17my $r = 23456789012;
18my $x;
19
20
21$x = unpack "q", pack "q", $q;
22print "not " unless $x == $q;
23print "ok 1\n";
24
25
26$x = sprintf("%d", 12345678901);
27print "not " unless $x eq "$q";
28print "ok 2\n";
29
30
31$x = sprintf("%d", $q);
32print "not " unless $x == $q && $x eq $q;
33print "ok 3\n";
34
35$x = sprintf("%lld", $q);
36print "not " unless $x == $q && $x eq $q;
37print "ok 4\n";
38
39$x = sprintf("%Ld", $q);
40print "not " unless $x == $q && $x eq $q;
41print "ok 5\n";
42
43$x = sprintf("%qd", $q);
44print "not " unless $x == $q && $x eq $q;
45print "ok 6\n";
46
47
48$x = sprintf("%x", $q);
49print "not " unless hex($x) == 0x2dfdc1c35;
50print "ok 7\n";
51
52$x = sprintf("%llx", $q);
53print "not " unless hex($x) == 0x2dfdc1c35;
54print "ok 8\n";
55
56$x = sprintf("%Lx", $q);
57print "not " unless hex($x) == 0x2dfdc1c35;
58print "ok 9\n";
59
60$x = sprintf("%qx", $q);
61print "not " unless hex($x) == 0x2dfdc1c35;
62print "ok 10\n";
63
64
65$x = sprintf("%o", $q);
66print "not " unless oct("0$x") == 0133767016065;
67print "ok 11\n";
68
69$x = sprintf("%llo", $q);
70print "not " unless oct("0$x") == 0133767016065;
71print "ok 12\n";
72
73$x = sprintf("%Lo", $q);
74print "not " unless oct("0$x") == 0133767016065;
75print "ok 13\n";
76
77$x = sprintf("%qo", $q);
78print "not " unless oct("0$x") == 0133767016065;
79print "ok 14\n";
80
81
82$x = sprintf("%b", $q);
83print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101;
84print "ok 15\n";
85
86$x = sprintf("%llb", $q);
87print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101;
88print "ok 16\n";
89
90$x = sprintf("%Lb", $q);
91print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101;
92print "ok 17\n";
93
94$x = sprintf("%qb", $q);
95print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101;
96print "ok 18\n";
97
98
99$x = sprintf("%u", 12345678901);
100print "not " unless $x eq "$q";
101print "ok 19\n";
102
103$x = sprintf("%u", $q);
104print "not " unless $x == $q && $x eq $q;
105print "ok 20\n";
106
107$x = sprintf("%llu", $q);
108print "not " unless $x == $q && $x eq $q;
109print "ok 21\n";
110
111$x = sprintf("%Lu", $q);
112print "not " unless $x == $q && $x eq $q;
113print "ok 22\n";
114
115
116$x = $q + $r;
117print "not " unless $x == 35802467913;
118print "ok 23\n";
119
120$x = $q - $r;
121print "not " unless $x == -11111110111;
122print "ok 24\n";
123
124$x = $q * $r;
125print "not " unless $x == 289589985190657035812;
126print "ok 25\n";
127
128$x /= $r;
129print "not " unless $x == $q;
130print "ok 26\n";
131
132$x = 98765432109 % 12345678901;
133print "not " unless $x == 901;
134print "ok 27\n";