Commit | Line | Data |
0f4b6630 |
1 | BEGIN { |
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 | |
29fe7a80 |
14 | print "1..30\n"; |
0f4b6630 |
15 | |
16 | my $q = 12345678901; |
17 | my $r = 23456789012; |
18 | my $x; |
19 | |
20 | |
21 | $x = unpack "q", pack "q", $q; |
22 | print "not " unless $x == $q; |
23 | print "ok 1\n"; |
24 | |
25 | |
26 | $x = sprintf("%d", 12345678901); |
27 | print "not " unless $x eq "$q"; |
28 | print "ok 2\n"; |
29 | |
30 | |
31 | $x = sprintf("%d", $q); |
32 | print "not " unless $x == $q && $x eq $q; |
33 | print "ok 3\n"; |
34 | |
35 | $x = sprintf("%lld", $q); |
36 | print "not " unless $x == $q && $x eq $q; |
37 | print "ok 4\n"; |
38 | |
39 | $x = sprintf("%Ld", $q); |
40 | print "not " unless $x == $q && $x eq $q; |
41 | print "ok 5\n"; |
42 | |
43 | $x = sprintf("%qd", $q); |
44 | print "not " unless $x == $q && $x eq $q; |
45 | print "ok 6\n"; |
46 | |
47 | |
48 | $x = sprintf("%x", $q); |
49 | print "not " unless hex($x) == 0x2dfdc1c35; |
50 | print "ok 7\n"; |
51 | |
52 | $x = sprintf("%llx", $q); |
53 | print "not " unless hex($x) == 0x2dfdc1c35; |
54 | print "ok 8\n"; |
55 | |
56 | $x = sprintf("%Lx", $q); |
57 | print "not " unless hex($x) == 0x2dfdc1c35; |
58 | print "ok 9\n"; |
59 | |
60 | $x = sprintf("%qx", $q); |
61 | print "not " unless hex($x) == 0x2dfdc1c35; |
62 | print "ok 10\n"; |
63 | |
64 | |
65 | $x = sprintf("%o", $q); |
66 | print "not " unless oct("0$x") == 0133767016065; |
67 | print "ok 11\n"; |
68 | |
69 | $x = sprintf("%llo", $q); |
70 | print "not " unless oct("0$x") == 0133767016065; |
71 | print "ok 12\n"; |
72 | |
73 | $x = sprintf("%Lo", $q); |
74 | print "not " unless oct("0$x") == 0133767016065; |
75 | print "ok 13\n"; |
76 | |
77 | $x = sprintf("%qo", $q); |
78 | print "not " unless oct("0$x") == 0133767016065; |
79 | print "ok 14\n"; |
80 | |
81 | |
82 | $x = sprintf("%b", $q); |
83 | print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101; |
84 | print "ok 15\n"; |
85 | |
86 | $x = sprintf("%llb", $q); |
87 | print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101; |
88 | print "ok 16\n"; |
89 | |
90 | $x = sprintf("%Lb", $q); |
91 | print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101; |
92 | print "ok 17\n"; |
93 | |
94 | $x = sprintf("%qb", $q); |
95 | print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101; |
96 | print "ok 18\n"; |
97 | |
98 | |
99 | $x = sprintf("%u", 12345678901); |
100 | print "not " unless $x eq "$q"; |
101 | print "ok 19\n"; |
102 | |
103 | $x = sprintf("%u", $q); |
104 | print "not " unless $x == $q && $x eq $q; |
105 | print "ok 20\n"; |
106 | |
107 | $x = sprintf("%llu", $q); |
108 | print "not " unless $x == $q && $x eq $q; |
109 | print "ok 21\n"; |
110 | |
111 | $x = sprintf("%Lu", $q); |
112 | print "not " unless $x == $q && $x eq $q; |
113 | print "ok 22\n"; |
114 | |
115 | |
29fe7a80 |
116 | $x = sprintf("%D", $q); |
117 | print "not " unless $x == $q && $x eq $q; |
118 | print "ok 23\n"; |
119 | |
120 | $x = sprintf("%U", $q); |
121 | print "not " unless $x == $q && $x eq $q; |
122 | print "ok 24\n"; |
123 | |
124 | $x = sprintf("%O", $q); |
125 | print "not " unless oct($x) == $q; |
126 | print "ok 25\n"; |
127 | |
128 | |
0f4b6630 |
129 | $x = $q + $r; |
130 | print "not " unless $x == 35802467913; |
29fe7a80 |
131 | print "ok 26\n"; |
0f4b6630 |
132 | |
133 | $x = $q - $r; |
134 | print "not " unless $x == -11111110111; |
29fe7a80 |
135 | print "ok 27\n"; |
0f4b6630 |
136 | |
137 | $x = $q * $r; |
138 | print "not " unless $x == 289589985190657035812; |
29fe7a80 |
139 | print "ok 28\n"; |
0f4b6630 |
140 | |
141 | $x /= $r; |
142 | print "not " unless $x == $q; |
29fe7a80 |
143 | print "ok 29\n"; |
0f4b6630 |
144 | |
145 | $x = 98765432109 % 12345678901; |
146 | print "not " unless $x == 901; |
29fe7a80 |
147 | print "ok 30\n"; |