This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Create subdirectory t/opbasic. Move 5 test files there.
[perl5.git] / t / opbasic / arith.t
CommitLineData
7dca457a 1#!./perl -w
54310121 2
7f45fac2
PG
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
7
43089d1e 8print "1..167\n";
54310121 9
84721e93
JK
10sub try ($$$) {
11 print +($_[1] ? "ok" : "not ok"), " $_[0] - $_[2]\n";
54310121 12}
84721e93 13sub tryeq ($$$$) {
7dca457a 14 if ($_[1] == $_[2]) {
84721e93 15 print "ok $_[0]";
7dca457a 16 } else {
84721e93 17 print "not ok $_[0] # $_[1] != $_[2]";
7dca457a 18 }
84721e93 19 print " - $_[3]\n";
7dca457a 20}
84721e93 21sub tryeq_sloppy ($$$$) {
800e6488 22 if ($_[1] == $_[2]) {
84721e93 23 print "ok $_[0]";
800e6488 24 } else {
66d2c7cb 25 my $error = abs (($_[1] - $_[2]) / $_[1]);
fbe3e8bd 26 if ($error < 1e-9) {
84721e93 27 print "ok $_[0] # $_[1] is close to $_[2], \$^O eq $^O";
800e6488 28 } else {
84721e93 29 print "not ok $_[0] # $_[1] != $_[2]";
800e6488
JH
30 }
31 }
84721e93 32 print " - $_[3]\n";
800e6488 33}
54310121 34
a4474c9e 35my $T = 1;
84721e93
JK
36tryeq $T++, 13 % 4, 1, 'modulo: positive positive';
37tryeq $T++, -13 % 4, 3, 'modulo: negative positive';
38tryeq $T++, 13 % -4, -3, 'modulo: positive negative';
39tryeq $T++, -13 % -4, -1, 'modulo: negative negative';
a4474c9e
DD
40
41# Give abs() a good work-out before using it in anger
84721e93
JK
42tryeq $T++, abs(0), 0, 'abs(): 0 0';
43tryeq $T++, abs(1), 1, 'abs(): 1 1';
44tryeq $T++, abs(-1), 1, 'abs(): -1 1';
45tryeq $T++, abs(2147483647), 2147483647, 'abs(): 2**31-1: pos pos';
46tryeq $T++, abs(-2147483647), 2147483647, 'abs(): 2**31-1: neg pos';
47tryeq $T++, abs(4294967295), 4294967295, 'abs(): 2**32-1: pos pos';
48tryeq $T++, abs(-4294967295), 4294967295, 'abs(): 2**32-1: neg pos';
49tryeq $T++, abs(9223372036854775807), 9223372036854775807,
50 'abs(): 2**63-1: pos pos';
51tryeq $T++, abs(-9223372036854775807), 9223372036854775807,
52 'abs(): 2**63-1: neg pos';
53# Assume no change whatever; no slop needed
54tryeq $T++, abs(1e50), 1e50, 'abs(): 1e50: pos pos';
55# Assume only sign bit flipped
56tryeq $T++, abs(-1e50), 1e50, 'abs(): 1e50: neg pos';
65843c0f
JH
57
58my $limit = 1e6;
59
60# Division (and modulo) of floating point numbers
61# seem to be rather sloppy in Cray.
62$limit = 1e8 if $^O eq 'unicos';
63
84721e93
JK
64try $T++, abs( 13e21 % 4e21 - 1e21) < $limit, 'abs() for floating point';
65try $T++, abs(-13e21 % 4e21 - 3e21) < $limit, 'abs() for floating point';
66try $T++, abs( 13e21 % -4e21 - -3e21) < $limit, 'abs() for floating point';
67try $T++, abs(-13e21 % -4e21 - -1e21) < $limit, 'abs() for floating point';
68
69tryeq $T++, 4063328477 % 65535, 27407, 'UV behaves properly: modulo';
70tryeq $T++, 4063328477 % 4063328476, 1, 'UV behaves properly: modulo';
71tryeq $T++, 4063328477 % 2031664238, 1, 'UV behaves properly: modulo';
72tryeq $T++, 2031664238 % 4063328477, 2031664238,
73 'UV behaves properly: modulo';
74
75tryeq $T++, 2147483647 + 0, 2147483647,
76 'trigger wrapping on 32 bit IVs and UVs';
77
78tryeq $T++, 2147483647 + 1, 2147483648, 'IV + IV promotes to UV';
79tryeq $T++, 2147483640 + 10, 2147483650, 'IV + IV promotes to UV';
80tryeq $T++, 2147483647 + 2147483647, 4294967294, 'IV + IV promotes to UV';
81tryeq $T++, 2147483647 + 2147483649, 4294967296, 'IV + UV promotes to NV';
82tryeq $T++, 4294967294 + 2, 4294967296, 'UV + IV promotes to NV';
83tryeq $T++, 4294967295 + 4294967295, 8589934590, 'UV + UV promotes to NV';
84
85tryeq $T++, 2147483648 + -1, 2147483647, 'UV + IV promotes to IV';
86tryeq $T++, 2147483650 + -10, 2147483640, 'UV + IV promotes to IV';
87tryeq $T++, -1 + 2147483648, 2147483647, 'IV + UV promotes to IV';
88tryeq $T++, -10 + 4294967294, 4294967284, 'IV + UV promotes to IV';
89tryeq $T++, -2147483648 + -2147483648, -4294967296, 'IV + IV promotes to NV';
90tryeq $T++, -2147483640 + -10, -2147483650, 'IV + IV promotes to NV';
91
92# Hmm. Do not forget the simple stuff
93# addition
94tryeq $T++, 1 + 1, 2, 'addition of 2 positive integers';
95tryeq $T++, 4 + -2, 2, 'addition of positive and negative integer';
96tryeq $T++, -10 + 100, 90, 'addition of negative and positive integer';
97tryeq $T++, -7 + -9, -16, 'addition of 2 negative integers';
98tryeq $T++, -63 + +2, -61, 'addition of signed negative and positive integers';
99tryeq $T++, 4 + -1, 3, 'addition of positive and negative integer';
100tryeq $T++, -1 + 1, 0, 'addition which sums to 0';
101tryeq $T++, +29 + -29, 0, 'addition which sums to 0';
102tryeq $T++, -1 + 4, 3, 'addition of signed negative and positive integers';
103tryeq $T++, +4 + -17, -13, 'addition of signed positive and negative integers';
7dca457a
NC
104
105# subtraction
84721e93
JK
106tryeq $T++, 3 - 1, 2, 'subtraction of two positive integers';
107tryeq $T++, 3 - 15, -12,
108 'subtraction of two positive integers: minuend smaller';
109tryeq $T++, 3 - -7, 10, 'subtraction of positive and negative integer';
110tryeq $T++, -156 - 5, -161, 'subtraction of negative and positive integer';
111tryeq $T++, -156 - -5, -151, 'subtraction of two negative integers';
112tryeq $T++, -5 - -12, 7,
113 'subtraction of two negative integers: minuend smaller';
114tryeq $T++, -3 - -3, 0, 'subtraction of two negative integers with result of 0';
115tryeq $T++, 15 - 15, 0, 'subtraction of two positive integers with result of 0';
116tryeq $T++, 2147483647 - 0, 2147483647, 'subtraction from large integer';
117tryeq $T++, 2147483648 - 0, 2147483648, 'subtraction from large integer';
118tryeq $T++, -2147483648 - 0, -2147483648,
119 'subtraction from large negative integer';
120tryeq $T++, 0 - -2147483647, 2147483647,
121 'subtraction of large negative integer from 0';
122tryeq $T++, -1 - -2147483648, 2147483647,
123 'subtraction of large negative integer from negative integer';
124tryeq $T++, 2 - -2147483648, 2147483650,
125 'subtraction of large negative integer from positive integer';
126tryeq $T++, 4294967294 - 3, 4294967291, 'subtraction from large integer';
127tryeq $T++, -2147483648 - -1, -2147483647,
128 'subtraction from large negative integer';
129tryeq $T++, 2147483647 - -1, 2147483648, 'IV - IV promote to UV';
130tryeq $T++, 2147483647 - -2147483648, 4294967295, 'IV - IV promote to UV';
131tryeq $T++, 4294967294 - -3, 4294967297, 'UV - IV promote to NV';
132tryeq $T++, -2147483648 - +1, -2147483649, 'IV - IV promote to NV';
133tryeq $T++, 2147483648 - 2147483650, -2, 'UV - UV promote to IV';
134tryeq $T++, 2000000000 - 4000000000, -2000000000, 'IV - UV promote to IV';
7dca457a
NC
135
136# No warnings should appear;
137my $a;
138$a += 1;
84721e93 139tryeq $T++, $a, 1, '+= with positive';
7dca457a
NC
140undef $a;
141$a += -1;
84721e93 142tryeq $T++, $a, -1, '+= with negative';
7dca457a
NC
143undef $a;
144$a += 4294967290;
84721e93 145tryeq $T++, $a, 4294967290, '+= with positive';
7dca457a
NC
146undef $a;
147$a += -4294967290;
84721e93 148tryeq $T++, $a, -4294967290, '+= with negative';
7dca457a
NC
149undef $a;
150$a += 4294967297;
84721e93 151tryeq $T++, $a, 4294967297, '+= with positive';
7dca457a
NC
152undef $a;
153$a += -4294967297;
84721e93 154tryeq $T++, $a, -4294967297, '+= with negative';
7dca457a
NC
155
156my $s;
157$s -= 1;
84721e93 158tryeq $T++, $s, -1, '-= with positive';
7dca457a
NC
159undef $s;
160$s -= -1;
84721e93 161tryeq $T++, $s, +1, '-= with negative';
7dca457a
NC
162undef $s;
163$s -= -4294967290;
84721e93 164tryeq $T++, $s, +4294967290, '-= with negative';
7dca457a
NC
165undef $s;
166$s -= 4294967290;
84721e93 167tryeq $T++, $s, -4294967290, '-= with negative';
7dca457a
NC
168undef $s;
169$s -= 4294967297;
84721e93 170tryeq $T++, $s, -4294967297, '-= with positive';
7dca457a
NC
171undef $s;
172$s -= -4294967297;
84721e93 173tryeq $T++, $s, +4294967297, '-= with positive';
7dca457a 174
84721e93
JK
175# multiplication
176tryeq $T++, 1 * 3, 3, 'multiplication of two positive integers';
177tryeq $T++, -2 * 3, -6, 'multiplication of negative and positive integer';
178tryeq $T++, 3 * -3, -9, 'multiplication of positive and negative integer';
179tryeq $T++, -4 * -3, 12, 'multiplication of two negative integers';
7dca457a
NC
180
181# check with 0xFFFF and 0xFFFF
84721e93
JK
182tryeq $T++, 65535 * 65535, 4294836225,
183 'multiplication: 0xFFFF and 0xFFFF: pos pos';
184tryeq $T++, 65535 * -65535, -4294836225,
185 'multiplication: 0xFFFF and 0xFFFF: pos neg';
186tryeq $T++, -65535 * 65535, -4294836225,
187 'multiplication: 0xFFFF and 0xFFFF: pos neg';
188tryeq $T++, -65535 * -65535, 4294836225,
189 'multiplication: 0xFFFF and 0xFFFF: neg neg';
7dca457a
NC
190
191# check with 0xFFFF and 0x10001
84721e93
JK
192tryeq $T++, 65535 * 65537, 4294967295,
193 'multiplication: 0xFFFF and 0x10001: pos pos';
194tryeq $T++, 65535 * -65537, -4294967295,
195 'multiplication: 0xFFFF and 0x10001: pos neg';
196tryeq $T++, -65535 * 65537, -4294967295,
197 'multiplication: 0xFFFF and 0x10001: neg pos';
198tryeq $T++, -65535 * -65537, 4294967295,
199 'multiplication: 0xFFFF and 0x10001: neg neg';
7dca457a
NC
200
201# check with 0x10001 and 0xFFFF
84721e93
JK
202tryeq $T++, 65537 * 65535, 4294967295,
203 'multiplication: 0x10001 and 0xFFFF: pos pos';
204tryeq $T++, 65537 * -65535, -4294967295,
205 'multiplication: 0x10001 and 0xFFFF: pos neg';
206tryeq $T++, -65537 * 65535, -4294967295,
207 'multiplication: 0x10001 and 0xFFFF: neg pos';
208tryeq $T++, -65537 * -65535, 4294967295,
209 'multiplication: 0x10001 and 0xFFFF: neg neg';
7dca457a
NC
210
211# These should all be dones as NVs
84721e93
JK
212tryeq $T++, 65537 * 65537, 4295098369, 'multiplication: NV: pos pos';
213tryeq $T++, 65537 * -65537, -4295098369, 'multiplication: NV: pos neg';
214tryeq $T++, -65537 * 65537, -4295098369, 'multiplication: NV: neg pos';
215tryeq $T++, -65537 * -65537, 4295098369, 'multiplication: NV: neg neg';
7dca457a
NC
216
217# will overflow an IV (in 32-bit)
84721e93
JK
218tryeq $T++, 46340 * 46342, 0x80001218,
219 'multiplication: overflow an IV in 32-bit: pos pos';
220tryeq $T++, 46340 * -46342, -0x80001218,
221 'multiplication: overflow an IV in 32-bit: pos neg';
222tryeq $T++, -46340 * 46342, -0x80001218,
223 'multiplication: overflow an IV in 32-bit: neg pos';
224tryeq $T++, -46340 * -46342, 0x80001218,
225 'multiplication: overflow an IV in 32-bit: neg neg';
226
227tryeq $T++, 46342 * 46340, 0x80001218,
228 'multiplication: overflow an IV in 32-bit: pos pos';
229tryeq $T++, 46342 * -46340, -0x80001218,
230 'multiplication: overflow an IV in 32-bit: pos neg';
231tryeq $T++, -46342 * 46340, -0x80001218,
232 'multiplication: overflow an IV in 32-bit: neg pos';
233tryeq $T++, -46342 * -46340, 0x80001218,
234 'multiplication: overflow an IV in 32-bit: neg neg';
7dca457a
NC
235
236# will overflow a positive IV (in 32-bit)
84721e93
JK
237tryeq $T++, 65536 * 32768, 0x80000000,
238 'multiplication: overflow a positive IV in 32-bit: pos pos';
239tryeq $T++, 65536 * -32768, -0x80000000,
240 'multiplication: overflow a positive IV in 32-bit: pos neg';
241tryeq $T++, -65536 * 32768, -0x80000000,
242 'multiplication: overflow a positive IV in 32-bit: neg pos';
243tryeq $T++, -65536 * -32768, 0x80000000,
244 'multiplication: overflow a positive IV in 32-bit: neg neg';
245
246tryeq $T++, 32768 * 65536, 0x80000000,
247 'multiplication: overflow a positive IV in 32-bit: pos pos';
248tryeq $T++, 32768 * -65536, -0x80000000,
249 'multiplication: overflow a positive IV in 32-bit: pos neg';
250tryeq $T++, -32768 * 65536, -0x80000000,
251 'multiplication: overflow a positive IV in 32-bit: neg pos';
252tryeq $T++, -32768 * -65536, 0x80000000,
253 'multiplication: overflow a positive IV in 32-bit: neg neg';
7dca457a
NC
254
255# 2147483647 is prime. bah.
256
84721e93
JK
257tryeq $T++, 46339 * 46341, 0x7ffea80f,
258 'multiplication: hex product: pos pos';
259tryeq $T++, 46339 * -46341, -0x7ffea80f,
260 'multiplication: hex product: pos neg';
261tryeq $T++, -46339 * 46341, -0x7ffea80f,
262 'multiplication: hex product: neg pos';
263tryeq $T++, -46339 * -46341, 0x7ffea80f,
264 'multiplication: hex product: neg neg';
96a05aee
HS
265
266# leading space should be ignored
267
84721e93
JK
268tryeq $T++, 1 + " 1", 2, 'ignore leading space: addition';
269tryeq $T++, 3 + " -1", 2, 'ignore leading space: subtraction';
270tryeq $T++, 1.2, " 1.2", 'floating point and string equivalent: positive';
271tryeq $T++, -1.2, " -1.2", 'floating point and string equivalent: negative';
272
273# division
274tryeq $T++, 28/14, 2, 'division of two positive integers';
275tryeq $T++, 28/-7, -4, 'division of positive integer by negative';
276tryeq $T++, -28/4, -7, 'division of negative integer by positive';
277tryeq $T++, -28/-2, 14, 'division of negative integer by negative';
278
279tryeq $T++, 0x80000000/1, 0x80000000,
280 'division of positive hex by positive integer';
281tryeq $T++, 0x80000000/-1, -0x80000000,
282 'division of positive hex by negative integer';
283tryeq $T++, -0x80000000/1, -0x80000000,
284 'division of negative hex by negative integer';
285tryeq $T++, -0x80000000/-1, 0x80000000,
286 'division of negative hex by positive integer';
5479d192
NC
287
288# The example for sloppy divide, rigged to avoid the peephole optimiser.
84721e93
JK
289tryeq_sloppy $T++, "20." / "5.", 4, 'division of floating point without fractional part';
290
291tryeq $T++, 2.5 / 2, 1.25,
292 'division of positive floating point by positive integer';
293tryeq $T++, 3.5 / -2, -1.75,
294 'division of positive floating point by negative integer';
295tryeq $T++, -4.5 / 2, -2.25,
296 'division of negative floating point by positive integer';
297tryeq $T++, -5.5 / -2, 2.75,
298 'division of negative floating point by negative integer';
299
300# Bluuurg if your floating point can not accurately cope with powers of 2
e7311069 301# [I suspect this is parsing string->float problems, not actual arith]
84721e93
JK
302tryeq_sloppy $T++, 18446744073709551616/1, 18446744073709551616,
303 'division of very large number by 1'; # Bluuurg
304tryeq_sloppy $T++, 18446744073709551616/2, 9223372036854775808,
305 'division of very large number by 2';
306tryeq_sloppy $T++, 18446744073709551616/4294967296, 4294967296,
307 'division of two very large numbers';
308tryeq_sloppy $T++, 18446744073709551616/9223372036854775808, 2,
309 'division of two very large numbers';
e7311069
NC
310
311{
312 # The peephole optimiser is wrong to think that it can substitute intops
313 # in place of regular ops, because i_multiply can overflow.
314 # Bug reported by "Sisyphus" <kalinabears@hdc.com.au>
315 my $n = 1127;
316
317 my $float = ($n % 1000) * 167772160.0;
84721e93 318 tryeq_sloppy $T++, $float, 21307064320, 'integer times floating point';
e7311069
NC
319
320 # On a 32 bit machine, if the i_multiply op is used, you will probably get
84721e93 321 # -167772160. It is actually undefined behaviour, so anything may happen.
e7311069 322 my $int = ($n % 1000) * 167772160;
84721e93 323 tryeq $T++, $int, 21307064320, 'integer times integer';
e228fed9 324
43089d1e 325 my $float2 = ($n % 1000 + 0.0) * 167772160;
84721e93 326 tryeq $T++, $float2, 21307064320, 'floating point times integer';
43089d1e
NC
327
328 my $int2 = ($n % 1000 + 0) * 167772160;
84721e93 329 tryeq $T++, $int2, 21307064320, 'integer plus zero times integer';
43089d1e
NC
330
331 # zero, but in a way that ought to be able to defeat any future optimizer:
332 my $zero = $$ - $$;
333 my $int3 = ($n % 1000 + $zero) * 167772160;
84721e93 334 tryeq $T++, $int3, 21307064320, 'defeat any future optimizer';
43089d1e 335
e228fed9
MG
336 my $t = time;
337 my $t1000 = time() * 1000;
84721e93 338 try $T++, abs($t1000 -1000 * $t) <= 2000, 'absolute value';
e7311069 339}
7f45fac2 340
43089d1e
NC
341{
342 # 64 bit variants
343 my $n = 1127;
344
345 my $float = ($n % 1000) * 720575940379279360.0;
84721e93
JK
346 tryeq_sloppy $T++, $float, 9.15131444281685e+19,
347 '64 bit: integer times floating point';
43089d1e
NC
348
349 my $int = ($n % 1000) * 720575940379279360;
84721e93
JK
350 tryeq_sloppy $T++, $int, 9.15131444281685e+19,
351 '64 bit: integer times integer';
43089d1e
NC
352
353 my $float2 = ($n % 1000 + 0.0) * 720575940379279360;
84721e93
JK
354 tryeq_sloppy $T++, $float2, 9.15131444281685e+19,
355 '64 bit: floating point times integer';
43089d1e
NC
356
357 my $int2 = ($n % 1000 + 0) * 720575940379279360;
84721e93
JK
358 tryeq_sloppy $T++, $int2, 9.15131444281685e+19,
359 '64 bit: integer plus zero times integer';
43089d1e
NC
360
361 # zero, but in a way that ought to be able to defeat any future optimizer:
362 my $zero = $$ - $$;
363 my $int3 = ($n % 1000 + $zero) * 720575940379279360;
84721e93
JK
364 tryeq_sloppy $T++, $int3, 9.15131444281685e+19,
365 '64 bit: defeat any future optimizer';
7f45fac2 366}
01f91bf2
FC
367
368# [perl #109542] $1 and "$1" should be treated the same way
369"976562500000000" =~ /(\d+)/;
370$a = ($1 * 1024);
371$b = ("$1" * 1024);
372print "not "x($a ne $b), "ok ", $T++, qq ' - \$1 vs "\$1" * something\n';
373$a = (1024 * $1);
374$b = (1024 * "$1");
375print "not "x($a ne $b), "ok ", $T++, qq ' - something * \$1 vs "\$1"\n';
376$a = ($1 + 102400000000000);
377$b = ("$1" + 102400000000000);
378print "not "x($a ne $b), "ok ", $T++, qq ' - \$1 vs "\$1" + something\n';
379$a = (102400000000000 + $1);
380$b = (102400000000000 + "$1");
381print "not "x($a ne $b), "ok ", $T++, qq ' - something + \$1 vs "\$1"\n';
382$a = ($1 - 10240000000000000);
383$b = ("$1" - 10240000000000000);
384print "not "x($a ne $b), "ok ", $T++, qq ' - \$1 vs "\$1" - something\n';
385$a = (10240000000000000 - $1);
386$b = (10240000000000000 - "$1");
387print "not "x($a ne $b), "ok ", $T++, qq ' - something - \$1 vs "\$1"\n';
388"976562500" =~ /(\d+)/;
389$a = ($1 ** 2);
390$b = ("$1" ** 2);
391print "not "x($a ne $b), "ok ", $T++, qq ' - \$1 vs "\$1" ** something\n';
392"32" =~ /(\d+)/;
393$a = (3 ** $1);
394$b = (3 ** "$1");
395print "not "x($a ne $b), "ok ", $T++, qq ' - something ** \$1 vs "\$1"\n';
396"97656250000000000" =~ /(\d+)/;
397$a = ($1 / 10);
398$b = ("$1" / 10);
399print "not "x($a ne $b), "ok ", $T++, qq ' - \$1 vs "\$1" / something\n';
400"10" =~ /(\d+)/;
401$a = (97656250000000000 / $1);
402$b = (97656250000000000 / "$1");
403print "not "x($a ne $b), "ok ", $T++, qq ' - something / \$1 vs "\$1"\n';
404"97656250000000000" =~ /(\d+)/;
405$a = ($1 <=> 97656250000000001);
406$b = ("$1" <=> 97656250000000001);
407print "not "x($a ne $b), "ok ", $T++, qq ' - \$1 vs "\$1" <=> something\n';
408$a = (97656250000000001 <=> $1);
409$b = (97656250000000001 <=> "$1");
410print "not "x($a ne $b), "ok ", $T++, qq ' - something <=> \$1 vs "\$1"\n';
411"97656250000000001" =~ /(\d+)/;
412$a = ($1 % 97656250000000002);
413$b = ("$1" % 97656250000000002);
414print "not "x($a ne $b), "ok ", $T++, qq ' - \$1 vs "\$1" % something\n';
415$a = (97656250000000000 % $1);
416$b = (97656250000000000 % "$1");
417print "not "x($a ne $b), "ok ", $T++, qq ' - something % \$1 vs "\$1"\n';
84721e93
JK
418
419my $vms_no_ieee;
420if ($^O eq 'VMS') {
421 use vars '%Config';
422 eval {require Config; import Config};
423 $vms_no_ieee = 1 unless defined($Config{useieee});
424}
425
426if ($^O eq 'vos') {
427 print "not ok ", $T++, " # TODO VOS raises SIGFPE instead of producing infinity.\n";
428}
429elsif ($vms_no_ieee) {
430 print $T++, " # SKIP -- the IEEE infinity model is unavailable in this configuration.\n"
431}
432elsif ($^O eq 'ultrix') {
433 print "not ok ", $T++, " # TODO Ultrix enters deep nirvana instead of producing infinity.\n";
434}
435else {
436 # The computation of $v should overflow and produce "infinity"
437 # on any system whose max exponent is less than 10**1506.
438 # The exact string used to represent infinity varies by OS,
439 # so we don't test for it; all we care is that we don't die.
440 #
441 # Perl considers it to be an error if SIGFPE is raised.
442 # Chances are the interpreter will die, since it doesn't set
443 # up a handler for SIGFPE. That's why this test is last; to
444 # minimize the number of test failures. --PG
445
446 my $n = 5000;
447 my $v = 2;
448 while (--$n)
449 {
450 $v *= 2;
451 }
452 print "ok ", $T++, " - infinity\n";
453}
454