Introduce HAS_LLSEEK.
[p5sagit/p5-mst-13.2.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 (&, |, ^, ~, <<, >>, vec) are not 64-bit clean.
14 # See the beginning of pp.c and the explanation next to IBW/UBW.
15
16 no warning 'overflow'; # so that using > 0xfffffff constants doesn't whine
17
18 print "1..30\n";
19
20 my $q = 12345678901;
21 my $r = 23456789012;
22 my $f = 0xffffffff;
23 my $x;
24
25
26 $x = unpack "q", pack "q", $q;
27 print "not " unless $x == $q && $x > $f;
28 print "ok 1\n";
29
30
31 $x = sprintf("%d", 12345678901);
32 print "not " unless $x eq $q && $x > $f;
33 print "ok 2\n";
34
35
36 $x = sprintf("%d", $q);
37 print "not " unless $x == $q && $x eq $q && $x > $f;
38 print "ok 3\n";
39
40 $x = sprintf("%lld", $q);
41 print "not " unless $x == $q && $x eq $q && $x > $f;
42 print "ok 4\n";
43
44 $x = sprintf("%Ld", $q);
45 print "not " unless $x == $q && $x eq $q && $x > $f;
46 print "ok 5\n";
47
48 $x = sprintf("%qd", $q);
49 print "not " unless $x == $q && $x eq $q && $x > $f;
50 print "ok 6\n";
51
52
53 $x = sprintf("%x", $q);
54 print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
55 print "ok 7\n";
56
57 $x = sprintf("%llx", $q);
58 print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
59 print "ok 8\n";
60
61 $x = sprintf("%Lx", $q);
62 print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
63 print "ok 9\n";
64
65 $x = sprintf("%qx", $q);
66 print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f;
67 print "ok 10\n";
68
69
70 $x = sprintf("%o", $q);
71 print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
72 print "ok 11\n";
73
74 $x = sprintf("%llo", $q);
75 print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
76 print "ok 12\n";
77
78 $x = sprintf("%Lo", $q);
79 print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
80 print "ok 13\n";
81
82 $x = sprintf("%qo", $q);
83 print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f;
84 print "ok 14\n";
85
86
87 $x = sprintf("%b", $q);
88 print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
89                     oct("0b$x") > $f;
90 print "ok 15\n";
91
92 $x = sprintf("%llb", $q);
93 print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
94                     oct("0b$x") > $f;
95 print "ok 16\n";
96
97 $x = sprintf("%Lb", $q);
98 print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
99                                    oct("0b$x") > $f;
100 print "ok 17\n";
101
102 $x = sprintf("%qb", $q);
103 print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 &&
104                     oct("0b$x") > $f;
105 print "ok 18\n";
106
107
108 $x = sprintf("%u", 12345678901);
109 print "not " unless $x eq $q && $x > $f;
110 print "ok 19\n";
111
112 $x = sprintf("%u", $q);
113 print "not " unless $x == $q && $x eq $q && $x > $f;
114 print "ok 20\n";
115
116 $x = sprintf("%llu", $q);
117 print "not " unless $x == $q && $x eq $q && $x > $f;
118 print "ok 21\n";
119
120 $x = sprintf("%Lu", $q);
121 print "not " unless $x == $q && $x eq $q && $x > $f;
122 print "ok 22\n";
123
124
125 $x = sprintf("%D", $q);
126 print "not " unless $x == $q && $x eq $q && $x > $f;
127 print "ok 23\n";
128
129 $x = sprintf("%U", $q);
130 print "not " unless $x == $q && $x eq $q && $x > $f;
131 print "ok 24\n";
132
133 $x = sprintf("%O", $q);
134 print "not " unless oct($x) == $q && oct($x) > $f;
135 print "ok 25\n";
136
137
138 $x = $q + $r;
139 print "not " unless $x == 35802467913 && $x > $f;
140 print "ok 26\n";
141
142 $x = $q - $r;
143 print "not " unless $x == -11111110111 && -$x > $f;
144 print "ok 27\n";
145
146 $x = $q * $r;
147 print "not " unless $x == 289589985190657035812 && $x > $f;
148 print "ok 28\n";
149
150 $x /= $r;
151 print "not " unless $x == $q && $x > $f;
152 print "ok 29\n";
153
154 $x = 98765432109 % 12345678901;
155 print "not " unless $x == 901;
156 print "ok 30\n";