2 # Copyright (C) 2009, Parrot Foundation.
7 t/op/inf_nan.t - Test math properties of Inf and NaN
11 % prove t/op/inf_nan.t
15 Tests for mathematical operations with Inf and Nan.
20 .include 'test_more.pir'
50 test_fdiv_integer_pmc_nan()
51 test_fdiv_float_pmc_nan()
52 test_fdiv_float_integer_pmc_nan()
53 test_cmod_float_integer_pmc_nan()
54 test_mod_float_integer_pmc_nan()
60 is($N0, 'Inf', 'basic arithmetic: =')
62 is($N0, 'NaN', '... -=')
64 is($N0, 'NaN', '... *= -1')
66 is($N0, 'NaN', '... *= 0')
68 is($N0, 'NaN', '... += 5')
70 is($N0, 'NaN', '... -= 42')
72 is($N0, 'NaN', '... inc')
74 is($N0, 'NaN', '... dec')
76 is($N2, 'NaN', '... abs NaN')
79 is($N3, 'Inf', '... abs Inf')
82 is($N3, 'Inf', '... abs -Inf')
89 is($N1, 'Inf', 'exp: exp Inf')
92 is($N1, 0, '... exp -Inf')
95 is($N1, 'NaN', '... exp NaN')
101 is($N1, 'Inf', 'sqrt: assignment')
104 is($N1, 'NaN', '... sqrt -Inf')
107 is($N1, 'NaN', '... sqrt NaN')
110 is($N1, 'NaN', '... sqrt -1')
116 is($N1, 'NaN', 'sin: sin Inf')
119 is($N1, 'NaN', '... sin -Inf')
122 is($N1, 'NaN', '... sin NaN')
128 is($N1, 'Inf', 'sinh: sinh Inf')
131 is($N1, '-Inf', '... sinh -Inf')
134 is($N1, 'NaN', '... sinh NaN')
140 is($N1, 'NaN', 'asin: asin Inf')
143 is($N1, 'NaN', '... asin -Inf')
146 is($N1, 'NaN', '... asin NaN')
149 is($N1, 'NaN', '... asin -2')
152 is($N1, 'NaN', '... asin 2')
158 is($N1, 'NaN', 'cos: cos Inf')
161 is($N1, 'NaN', '... cos -Inf')
164 is($N1, 'NaN', '... cos NaN')
170 is($N1, 'Inf', 'cosh: cosh Inf')
173 is($N1, 'Inf', '... cosh -Inf')
176 is($N1, 'NaN', '... cosh NaN')
182 is($N1, 'NaN', 'acos: acos Inf')
185 is($N1, 'NaN', '... acos -Inf')
188 is($N1, 'NaN', '... acos NaN')
191 is($N1, 'NaN', '... acos -2')
194 is($N1, 'NaN', '... acos 2')
200 is($N1, 'NaN', 'tan: tan Inf')
203 is($N1, 'NaN', '... tan -Inf')
206 is($N1, 'NaN', '... tan NaN')
212 is($N1, 1, 'tanh: tanh Inf')
215 is($N1, -1, '... tanh -Inf')
218 is($N1, 'NaN', '... tanh NaN')
226 is($P1, 1.5707963, 'atan: atan Inf',1e-6)
232 is($P1, -1.5707963, '... atan -Inf',1e-6)
236 is($N1, 'NaN', '... atan NaN')
242 #is($N1, 'NaN', 'cot: cot Inf')
243 todo(0, 'cot Inf', 'cot/coth/acot not implemented for real numbers')
246 #is($N1, 'NaN', '... cot -Inf')
247 todo(0, 'cot -Inf', 'cot/coth/acot not implemented for real numbers')
250 #is($N1, 'NaN', '... cot NaN')
251 todo(0, 'cot NaN', 'cot/coth/acot not implemented for real numbers')
257 #is($N1, 1, 'coth: coth Inf')
258 todo(0, 'coth Inf', 'cot/coth/acot not implemented for real numbers')
261 #is($N1, -1, '... coth -Inf')
262 todo(0, 'coth -Inf', 'cot/coth/acot not implemented for real numbers')
265 #is($N1, 'NaN', '... coth NaN')
266 todo(0, 'coth NaN', 'cot/coth/acot not implemented for real numbers')
272 #is($N1, 'NaN', 'acot: acot Inf')
273 todo(0, 'acot Inf', 'cot/coth/acot not implemented for real numbers')
276 #is($N1, 'NaN', '... acot -Inf')
277 todo(0, 'acot -Inf', 'cot/coth/acot not implemented for real numbers')
280 #is($N1, 'NaN', '... acot NaN')
281 todo(0, 'acot NaN', 'cot/coth/acot not implemented for real numbers')
284 #is($N1, 'NaN', '... acot -2')
285 todo(0, 'acot -2', 'cot/coth/acot not implemented for real numbers')
288 #is($N1, 'NaN', '... acot 2')
289 todo(0, 'acot 2', 'cot/coth/acot not implemented for real numbers')
295 is($N1, 'NaN', 'sec: sec Inf')
298 is($N1, 'NaN', '... sec -Inf')
301 is($N1, 'NaN', '... sec NaN')
307 is($N1, 0, 'sech: sech Inf')
310 is($N1, 0, '... sech -Inf')
313 is($N1, 'NaN', '... sech NaN')
319 like($N1, '1\.5707963.*', 'asec: asec Inf')
322 like($N1, '1\.5707963.*', '... asec -Inf')
325 is($N1, 'NaN', 'asec NaN')
331 is($N1, 'Inf', 'ln: ln Inf')
334 is($N1, 'NaN', '... ln Inf')
337 is($N1, 'NaN', '... ln NaN')
343 is($N1, 'Inf', 'log10: log10 Inf')
346 is($N1, 'NaN', '... log10 -Inf')
349 is($N1, 'NaN', '... log10 NaN')
355 is($N1, 'Inf', 'log2: log2 Inf')
358 is($N1, 'NaN', '... log2 -Inf')
361 is($N1, 'NaN', '... log2 -Inf')
367 is($N1, '-Inf', 'negative: neg Inf')
370 is($N1, 'Inf', '... neg -Inf')
373 is($N1, 'NaN', '... neg NaN')
379 is($N1, 'Inf', 'pow: Inf ^ 2')
381 is($N1, 'Inf', '...: 2 ^ Inf')
384 is($N1, 'NaN', '...: NaN ^ 2')
386 is($N1, 'NaN', '...: 2 ^ NaN')
389 .sub test_mix_nan_inf
393 is($N0, 'NaN', 'mixing NaN and Inf: NaN * Inf')
395 is($N0, 'NaN', '... NaN / Inf')
397 is($N0, 'NaN', '... NaN - Inf')
399 is($N0, 'NaN', '... NaN + Inf')
405 is($N1, 'NaN', 'rounding n: floor NaN')
407 is($N2, 'NaN', '... ceil NaN')
410 is($N1, 'Inf', '... floor Inf')
412 is($N2, 'Inf', '... ceil Inf')
415 is($N1, '-Inf', '... floor -Inf')
417 is($N2, '-Inf', '... ceil -Inf')
420 #pir_output_is(<<'CODE',<<OUTPUT, "TT #370 Rounding inf/nan");
424 #is($I0, 'Inf', 'floor Inf')
425 todo(0, 'floor Inf', 'rounding nan/inf gives something like -2147483648')
428 #is($I0, 'NaN', 'floor Inf')
429 todo(0, 'floor NaN', 'rounding nan/inf gives something like -2147483648')
432 #is($I0, 'Inf', 'floor Inf')
433 todo(0, 'ceil Inf', 'rounding nan/inf gives something like -2147483648')
436 #is($I0, 'NaN', 'floor Inf')
437 todo(0, 'ceil NaN', 'rounding nan/inf gives something like -2147483648')
440 .sub test_nan_complex
441 $P1 = new ["Complex"]
445 #is($P1, 'NaN', '1+i + NaN')
446 todo(0, '1+i + NaN should be NaN')
449 .sub test_fdiv_integer_pmc_nan
455 #is($P1, 'NaN', 'fdiv with Integer PMCs and NaN')
456 todo(0, 'fdiv with Integer PMCs and NaN', 'fdiv/mod/cmod do not play nicely with PMCs and NaN')
459 .sub test_fdiv_float_pmc_nan
465 #is($P1, 'NaN','fdiv with Float PMCs and NaN')
466 todo(0,'fdiv with Float PMCs and NaN', 'fdiv/mod/cmod do not play nicely with PMCs and NaN')
469 .sub test_fdiv_float_integer_pmc_nan
475 #is($P1, 'NaN', 'fdiv with Float and Integer PMCs and NaN')
476 todo(0, 'fdiv with Float and Integer PMCs and NaN', 'fdiv/mod/cmod do not play nicely with PMCs and NaN')
479 .sub test_cmod_float_integer_pmc_nan
485 #is($P1, 'NaN', 'cmod with Float and Integer PMCs and NaN')
486 todo(0, 'cmod with Float and Integer PMCs and NaN', 'fdiv/mod/cmod do not play nicely with PMCs and NaN')
489 .sub test_mod_float_integer_pmc_nan
495 #is($P1, 'NaN', 'mod with Float and Integer PMCs and NaN')
496 todo(0, 'mod with Float and Integer PMCs and NaN', 'fdiv/mod/cmod do not play nicely with PMCs and NaN')
501 # cperl-indent-level: 4
504 # vim: expandtab shiftwidth=4 filetype=pir: