11 print +($_[1] ? "ok" : "not ok"), " $_[0]\n";
17 print "not ok $_[0] # $_[1] != $_[2]\n";
20 sub tryeq_sloppy ($$$) {
24 my $error = abs ($_[1] - $_[2]) / $_[1];
26 print "ok $_[0] # $_[1] is close to $_[2], \$^O eq $^O\n";
28 print "not ok $_[0] # $_[1] != $_[2]\n";
36 tryeq 4, -13 % -4, -1;
40 # Division (and modulo) of floating point numbers
41 # seem to be rather sloppy in Cray.
42 $limit = 1e8 if $^O eq 'unicos';
44 try 5, abs( 13e21 % 4e21 - 1e21) < $limit;
45 try 6, abs(-13e21 % 4e21 - 3e21) < $limit;
46 try 7, abs( 13e21 % -4e21 - -3e21) < $limit;
47 try 8, abs(-13e21 % -4e21 - -1e21) < $limit;
49 # UVs should behave properly
51 tryeq 9, 4063328477 % 65535, 27407;
52 tryeq 10, 4063328477 % 4063328476, 1;
53 tryeq 11, 4063328477 % 2031664238, 1;
54 tryeq 12, 2031664238 % 4063328477, 2031664238;
56 # These should trigger wrapping on 32 bit IVs and UVs
58 tryeq 13, 2147483647 + 0, 2147483647;
60 # IV + IV promote to UV
61 tryeq 14, 2147483647 + 1, 2147483648;
62 tryeq 15, 2147483640 + 10, 2147483650;
63 tryeq 16, 2147483647 + 2147483647, 4294967294;
64 # IV + UV promote to NV
65 tryeq 17, 2147483647 + 2147483649, 4294967296;
66 # UV + IV promote to NV
67 tryeq 18, 4294967294 + 2, 4294967296;
68 # UV + UV promote to NV
69 tryeq 19, 4294967295 + 4294967295, 8589934590;
72 tryeq 20, 2147483648 + -1, 2147483647;
73 tryeq 21, 2147483650 + -10, 2147483640;
75 tryeq 22, -1 + 2147483648, 2147483647;
76 tryeq 23, -10 + 4294967294, 4294967284;
78 tryeq 24, -2147483648 + -2147483648, -4294967296;
79 tryeq 25, -2147483640 + -10, -2147483650;
81 # Hmm. Don't forget the simple stuff
84 tryeq 28, -10 + 100, 90;
85 tryeq 29, -7 + -9, -16;
86 tryeq 30, -63 + +2, -61;
89 tryeq 33, +29 + -29, 0;
91 tryeq 35, +4 + -17, -13;
95 tryeq 37, 3 - 15, -12;
97 tryeq 39, -156 - 5, -161;
98 tryeq 40, -156 - -5, -151;
99 tryeq 41, -5 - -12, 7;
100 tryeq 42, -3 - -3, 0;
101 tryeq 43, 15 - 15, 0;
103 tryeq 44, 2147483647 - 0, 2147483647;
104 tryeq 45, 2147483648 - 0, 2147483648;
105 tryeq 46, -2147483648 - 0, -2147483648;
107 tryeq 47, 0 - -2147483647, 2147483647;
108 tryeq 48, -1 - -2147483648, 2147483647;
109 tryeq 49, 2 - -2147483648, 2147483650;
111 tryeq 50, 4294967294 - 3, 4294967291;
112 tryeq 51, -2147483648 - -1, -2147483647;
114 # IV - IV promote to UV
115 tryeq 52, 2147483647 - -1, 2147483648;
116 tryeq 53, 2147483647 - -2147483648, 4294967295;
117 # UV - IV promote to NV
118 tryeq 54, 4294967294 - -3, 4294967297;
119 # IV - IV promote to NV
120 tryeq 55, -2147483648 - +1, -2147483649;
121 # UV - UV promote to IV
122 tryeq 56, 2147483648 - 2147483650, -2;
123 # IV - UV promote to IV
124 tryeq 57, 2000000000 - 4000000000, -2000000000;
126 # No warnings should appear;
135 tryeq 60, $a, 4294967290;
138 tryeq 61, $a, -4294967290;
141 tryeq 62, $a, 4294967297;
144 tryeq 63, $a, -4294967297;
154 tryeq 66, $s, +4294967290;
157 tryeq 67, $s, -4294967290;
160 tryeq 68, $s, -4294967297;
163 tryeq 69, $s, +4294967297;
168 tryeq 71, -2 * 3, -6;
169 tryeq 72, 3 * -3, -9;
170 tryeq 73, -4 * -3, 12;
172 # check with 0xFFFF and 0xFFFF
173 tryeq 74, 65535 * 65535, 4294836225;
174 tryeq 75, 65535 * -65535, -4294836225;
175 tryeq 76, -65535 * 65535, -4294836225;
176 tryeq 77, -65535 * -65535, 4294836225;
178 # check with 0xFFFF and 0x10001
179 tryeq 78, 65535 * 65537, 4294967295;
180 tryeq 79, 65535 * -65537, -4294967295;
181 tryeq 80, -65535 * 65537, -4294967295;
182 tryeq 81, -65535 * -65537, 4294967295;
184 # check with 0x10001 and 0xFFFF
185 tryeq 82, 65537 * 65535, 4294967295;
186 tryeq 83, 65537 * -65535, -4294967295;
187 tryeq 84, -65537 * 65535, -4294967295;
188 tryeq 85, -65537 * -65535, 4294967295;
190 # These should all be dones as NVs
191 tryeq 86, 65537 * 65537, 4295098369;
192 tryeq 87, 65537 * -65537, -4295098369;
193 tryeq 88, -65537 * 65537, -4295098369;
194 tryeq 89, -65537 * -65537, 4295098369;
196 # will overflow an IV (in 32-bit)
197 tryeq 90, 46340 * 46342, 0x80001218;
198 tryeq 91, 46340 * -46342, -0x80001218;
199 tryeq 92, -46340 * 46342, -0x80001218;
200 tryeq 93, -46340 * -46342, 0x80001218;
202 tryeq 94, 46342 * 46340, 0x80001218;
203 tryeq 95, 46342 * -46340, -0x80001218;
204 tryeq 96, -46342 * 46340, -0x80001218;
205 tryeq 97, -46342 * -46340, 0x80001218;
207 # will overflow a positive IV (in 32-bit)
208 tryeq 98, 65536 * 32768, 0x80000000;
209 tryeq 99, 65536 * -32768, -0x80000000;
210 tryeq 100, -65536 * 32768, -0x80000000;
211 tryeq 101, -65536 * -32768, 0x80000000;
213 tryeq 102, 32768 * 65536, 0x80000000;
214 tryeq 103, 32768 * -65536, -0x80000000;
215 tryeq 104, -32768 * 65536, -0x80000000;
216 tryeq 105, -32768 * -65536, 0x80000000;
218 # 2147483647 is prime. bah.
220 tryeq 106, 46339 * 46341, 0x7ffea80f;
221 tryeq 107, 46339 * -46341, -0x7ffea80f;
222 tryeq 108, -46339 * 46341, -0x7ffea80f;
223 tryeq 109, -46339 * -46341, 0x7ffea80f;
225 # leading space should be ignored
227 tryeq 110, 1 + " 1", 2;
228 tryeq 111, 3 + " -1", 2;
229 tryeq 112, 1.2, " 1.2";
230 tryeq 113, -1.2, " -1.2";
235 tryeq 115, 28/-7, -4;
236 tryeq 116, -28/4, -7;
237 tryeq 117, -28/-2, 14;
239 tryeq 118, 0x80000000/1, 0x80000000;
240 tryeq 119, 0x80000000/-1, -0x80000000;
241 tryeq 120, -0x80000000/1, -0x80000000;
242 tryeq 121, -0x80000000/-1, 0x80000000;
244 # The example for sloppy divide, rigged to avoid the peephole optimiser.
245 tryeq_sloppy 122, "20." / "5.", 4;
247 tryeq 123, 2.5 / 2, 1.25;
248 tryeq 124, 3.5 / -2, -1.75;
249 tryeq 125, -4.5 / 2, -2.25;
250 tryeq 126, -5.5 / -2, 2.75;
252 # Bluuurg if your floating point can't accurately cope with powers of 2
253 # [I suspect this is parsing string->float problems, not actual arith]
254 tryeq_sloppy 127, 18446744073709551616/1, 18446744073709551616; # Bluuurg
255 tryeq_sloppy 128, 18446744073709551616/2, 9223372036854775808;
256 tryeq_sloppy 129, 18446744073709551616/4294967296, 4294967296;
257 tryeq_sloppy 130, 18446744073709551616/9223372036854775808, 2;
260 # The peephole optimiser is wrong to think that it can substitute intops
261 # in place of regular ops, because i_multiply can overflow.
262 # Bug reported by "Sisyphus" <kalinabears@hdc.com.au>
265 my $float = ($n % 1000) * 167772160.0;
266 tryeq 131_sloppy, $float, 21307064320;
268 # On a 32 bit machine, if the i_multiply op is used, you will probably get
269 # -167772160. It's actually undefined behaviour, so anything may happen.
270 my $int = ($n % 1000) * 167772160;
271 tryeq 132, $int, 21307064320;
274 my $t1000 = time() * 1000;
275 try 133, abs($t1000 -1000 * $t) <= 2000;
279 print "not ok 134 # TODO VOS raises SIGFPE instead of producing infinity.\n";
281 # The computation of $v should overflow and produce "infinity"
282 # on any system whose max exponent is less than 10**1506.
283 # The exact string used to represent infinity varies by OS,
284 # so we don't test for it; all we care is that we don't die.
286 # Perl considers it to be an error if SIGFPE is raised.
287 # Chances are the interpreter will die, since it doesn't set
288 # up a handler for SIGFPE. That's why this test is last; to
289 # minimize the number of test failures. --PG