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