[t][cage] Remove PGE-dependence from t/op/inf_nan.t since it is part of 'make coretest'
[parrot.git] / t / op / inf_nan.t
blob930e03a9c4dc3c7d6d10dea5e80c8db05d81d2fc
1 #! parrot
2 # Copyright (C) 2009, Parrot Foundation.
3 # $Id$
5 =head1 NAME
7 t/op/inf_nan.t - Test math properties of Inf and NaN
9 =head1 SYNOPSIS
11     % prove t/op/inf_nan.t
13 =head1 DESCRIPTION
15 Tests for mathematical operations with Inf and Nan.
17 =cut
19 .sub main :main
20     .include 'test_more.pir'
21     plan(105)
23     test_basic_arith()
24     test_exp()
25     test_sqrt()
26     test_sin()
27     test_sinh()
28     test_asin()
29     test_cos()
30     test_cosh()
31     test_acos()
32     test_tan()
33     test_tanh()
34     test_atan()
35     test_cot()
36     test_coth()
37     test_acot()
38     test_sec()
39     test_sech()
40     test_asec()
41     test_ln()
42     test_log10()
43     test_log2()
44     test_neg()
45     test_pow()
46     test_mix_nan_inf()
47     test_rounding_n()
48     test_rounding_i()
49     test_nan_complex()
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()
56 .end
58 .sub test_basic_arith
59     $N0 = 'Inf'
60     is($N0, 'Inf', 'basic arithmetic: =')
61     $N0 -= $N0
62     is($N0, 'NaN', '... -=')
63     $N0 *= -1
64     is($N0, 'NaN', '... *= -1')
65     $N0 *= 0
66     is($N0, 'NaN', '... *= 0')
67     $N0 += 5
68     is($N0, 'NaN', '... += 5')
69     $N0 -= 42
70     is($N0, 'NaN', '... -= 42')
71     inc $N0
72     is($N0, 'NaN', '... inc')
73     dec $N0
74     is($N0, 'NaN', '... dec')
75     $N2 = abs $N0
76     is($N2, 'NaN', '... abs NaN')
77     $N1 = 'Inf'
78     $N3 = abs $N1
79     is($N3, 'Inf', '... abs Inf')
80     $N1 = '-Inf'
81     $N3 = abs $N1
82     is($N3, 'Inf', '... abs -Inf')
83 .end
86 .sub test_exp
87     $N0 = 'Inf'
88     $N1 = exp $N0
89     is($N1, 'Inf', 'exp: exp Inf')
90     $N0 = '-Inf'
91     $N1 = exp $N0
92     is($N1, 0, '... exp -Inf')
93     $N0 = 'NaN'
94     $N1 = exp $N0
95     is($N1, 'NaN', '... exp NaN')
96 .end
98 .sub test_sqrt
99     $N0 = 'Inf'
100     $N1 =  $N0
101     is($N1, 'Inf', 'sqrt: assignment')
102     $N0 = '-Inf'
103     $N1 = sqrt $N0
104     is($N1, 'NaN', '... sqrt -Inf')
105     $N0 = 'NaN'
106     $N1 = sqrt $N0
107     is($N1, 'NaN', '... sqrt NaN')
108     $N0 = -1
109     $N1 = sqrt $N0
110     is($N1, 'NaN', '... sqrt -1')
111 .end
113 .sub test_sin
114     $N0 = 'Inf'
115     $N1 = sin $N0
116     is($N1, 'NaN', 'sin: sin Inf')
117     $N0 = '-Inf'
118     $N1 = sin $N0
119     is($N1, 'NaN', '... sin -Inf')
120     $N0 = 'NaN'
121     $N1 = sin $N0
122     is($N1, 'NaN', '... sin NaN')
123 .end
125 .sub test_sinh 
126     $N0 = 'Inf'
127     $N1 = sinh $N0
128     is($N1, 'Inf', 'sinh: sinh Inf')
129     $N0 = '-Inf'
130     $N1 = sinh $N0
131     is($N1, '-Inf', '... sinh -Inf')
132     $N0 = 'NaN'
133     $N1 = sinh $N0
134     is($N1, 'NaN', '... sinh NaN')
135 .end
137 .sub test_asin 
138     $N0 = 'Inf'
139     $N1 = asin $N0
140     is($N1, 'NaN', 'asin: asin Inf')
141     $N0 = '-Inf'
142     $N1 = asin $N0
143     is($N1, 'NaN', '... asin -Inf')
144     $N0 = 'NaN'
145     $N1 = asin $N0
146     is($N1, 'NaN', '... asin NaN')
147     $N0 = '-2'
148     $N1 = asin $N0
149     is($N1, 'NaN', '... asin -2')
150     $N0 = '2'
151     $N1 = asin $N0
152     is($N1, 'NaN', '... asin 2')
153 .end
155 .sub test_cos
156     $N0 = 'Inf'
157     $N1 = cos $N0
158     is($N1, 'NaN', 'cos: cos Inf')
159     $N0 = '-Inf'
160     $N1 = cos $N0
161     is($N1, 'NaN', '... cos -Inf')
162     $N0 = 'NaN'
163     $N1 = cos $N0
164     is($N1, 'NaN', '... cos NaN')
165 .end
167 .sub test_cosh
168     $N0 = 'Inf'
169     $N1 = cosh $N0
170     is($N1, 'Inf', 'cosh: cosh Inf')
171     $N0 = '-Inf'
172     $N1 = cosh $N0
173     is($N1, 'Inf', '... cosh -Inf')
174     $N0 = 'NaN'
175     $N1 = cosh $N0
176     is($N1, 'NaN', '... cosh NaN')
177 .end
179 .sub test_acos
180     $N0 = 'Inf'
181     $N1 = acos $N0
182     is($N1, 'NaN', 'acos: acos Inf')
183     $N0 = '-Inf'
184     $N1 = acos $N0
185     is($N1, 'NaN', '... acos -Inf')
186     $N0 = 'NaN'
187     $N1 = acos $N0
188     is($N1, 'NaN', '... acos NaN')
189     $N0 = '-2'
190     $N1 = acos $N0
191     is($N1, 'NaN', '... acos -2')
192     $N0 = '2'
193     $N1 = acos $N0
194     is($N1, 'NaN', '... acos 2')
195 .end
197 .sub test_tan
198     $N0 = 'Inf'
199     $N1 = tan $N0
200     is($N1, 'NaN', 'tan: tan Inf')
201     $N0 = '-Inf'
202     $N1 = tan $N0
203     is($N1, 'NaN', '... tan -Inf')
204     $N0 = 'NaN'
205     $N1 = tan $N0
206     is($N1, 'NaN', '... tan NaN')
207 .end
209 .sub test_tanh
210     $N0 = 'Inf'
211     $N1 = tanh $N0
212     is($N1, 1, 'tanh: tanh Inf')
213     $N0 = '-Inf'
214     $N1 = tanh $N0
215     is($N1, -1, '... tanh -Inf')
216     $N0 = 'NaN'
217     $N1 = tanh $N0
218     is($N1, 'NaN', '... tanh NaN')
219 .end
221 .sub test_atan
222     $N0 = 'Inf'
223     $N1 = atan $N0
224     $P1 = new 'Float'
225     $P1 = $N1
226     is($P1, 1.5707963, 'atan: atan Inf',1e-6)
228     $N0 = '-Inf'
229     $N1 = atan $N0
230     $P1 = new 'Float'
231     $P1 = $N1
232     is($P1, -1.5707963, '... atan -Inf',1e-6)
234     $N0 = 'NaN'
235     $N1 = atan $N0
236     is($N1, 'NaN', '... atan NaN')
237 .end
239 .sub test_cot
240     $N0 = 'Inf'
241     #$N1 = cot $N0
242     #is($N1, 'NaN', 'cot: cot Inf')
243     todo(0, 'cot Inf', 'cot/coth/acot not implemented for real numbers')
244     $N0 = '-Inf'
245     #$N1 = cot $N0
246     #is($N1, 'NaN', '... cot -Inf')
247     todo(0, 'cot -Inf', 'cot/coth/acot not implemented for real numbers')
248     $N0 = 'NaN'
249     #$N1 = cot $N0
250     #is($N1, 'NaN', '... cot NaN')
251     todo(0, 'cot NaN', 'cot/coth/acot not implemented for real numbers')
252 .end
254 .sub test_coth
255     $N0 = 'Inf'
256     #$N1 = coth $N0
257     #is($N1, 1, 'coth: coth Inf')
258     todo(0, 'coth Inf', 'cot/coth/acot not implemented for real numbers')
259     $N0 = '-Inf'
260     #$N1 = coth $N0
261     #is($N1, -1, '... coth -Inf')
262     todo(0, 'coth -Inf', 'cot/coth/acot not implemented for real numbers')
263     $N0 = 'NaN'
264     #$N1 = coth $N0
265     #is($N1, 'NaN', '... coth NaN')
266     todo(0, 'coth NaN', 'cot/coth/acot not implemented for real numbers')
267 .end
269 .sub test_acot 
270     $N0 = 'Inf'
271     #$N1 = acot $N0
272     #is($N1, 'NaN', 'acot: acot Inf')
273     todo(0, 'acot Inf', 'cot/coth/acot not implemented for real numbers')
274     $N0 = '-Inf'
275     #$N1 = acot $N0
276     #is($N1, 'NaN', '... acot -Inf')
277     todo(0, 'acot -Inf', 'cot/coth/acot not implemented for real numbers')
278     $N0 = 'NaN'
279     #$N1 = acot $N0
280     #is($N1, 'NaN', '... acot NaN')
281     todo(0, 'acot NaN', 'cot/coth/acot not implemented for real numbers')
282     $N0 = '-2'
283     #$N1 = acot $N0
284     #is($N1, 'NaN', '... acot -2')
285     todo(0, 'acot -2', 'cot/coth/acot not implemented for real numbers')
286     $N0 = '2'
287     #$N1 = acot $N0
288     #is($N1, 'NaN', '... acot 2')
289     todo(0, 'acot 2', 'cot/coth/acot not implemented for real numbers')
290 .end
292 .sub test_sec
293     $N0 = 'Inf'
294     $N1 = sec $N0
295     is($N1, 'NaN', 'sec: sec Inf')
296     $N0 = '-Inf'
297     $N1 = sec $N0
298     is($N1, 'NaN', '... sec -Inf')
299     $N0 = 'NaN'
300     $N1 = sec $N0
301     is($N1, 'NaN', '... sec NaN')
302 .end
304 .sub test_sech
305     $N0 = 'Inf'
306     $N1 = sech $N0
307     is($N1, 0, 'sech: sech Inf')
308     $N0 = '-Inf'
309     $N1 = sech $N0
310     is($N1, 0, '... sech -Inf')
311     $N0 = 'NaN'
312     $N1 = sech $N0
313     is($N1, 'NaN', '... sech NaN')
314 .end
316 .sub test_asec
317     $N0 = 'Inf'
318     $N1 = asec $N0
319     like($N1, '1\.5707963.*', 'asec: asec Inf')
320     $N0 = '-Inf'
321     $N1 = asec $N0
322     like($N1, '1\.5707963.*', '... asec -Inf')
323     $N0 = 'NaN'
324     $N1 = asec $N0
325     is($N1, 'NaN', 'asec NaN')
326 .end
328 .sub test_ln
329     $N0 = 'Inf'
330     $N1 = ln $N0
331     is($N1, 'Inf', 'ln: ln Inf')
332     $N0 = '-Inf'
333     $N1 = ln $N0
334     is($N1, 'NaN', '... ln Inf')
335     $N0 = 'NaN'
336     $N1 = ln $N0
337     is($N1, 'NaN', '... ln NaN')
338 .end
340 .sub test_log10
341     $N0 = 'Inf'
342     $N1 = log10 $N0
343     is($N1, 'Inf', 'log10: log10 Inf')
344     $N0 = '-Inf'
345     $N1 = log10 $N0
346     is($N1, 'NaN', '... log10 -Inf')
347     $N0 = 'NaN'
348     $N1 = log10 $N0
349     is($N1, 'NaN', '... log10 NaN')
350 .end
352 .sub test_log2
353     $N0 = 'Inf'
354     $N1 = log2 $N0
355     is($N1, 'Inf', 'log2: log2 Inf')
356     $N0 = '-Inf'
357     $N1 = log2 $N0
358     is($N1, 'NaN', '... log2 -Inf')
359     $N0 = 'NaN'
360     $N1 = log2 $N0
361     is($N1, 'NaN', '... log2 -Inf')
362 .end
364 .sub test_neg
365     $N0 = 'Inf'
366     $N1 = neg $N0
367     is($N1, '-Inf', 'negative: neg Inf')
368     $N0 = '-Inf'
369     $N1 = neg $N0
370     is($N1, 'Inf', '... neg -Inf')
371     $N0 = 'NaN'
372     $N1 = neg $N0
373     is($N1, 'NaN', '... neg NaN')
374 .end
376 .sub test_pow
377     $N0 = 'Inf'
378     pow $N1, $N0, 2
379     is($N1, 'Inf', 'pow: Inf ^ 2')
380     pow $N1, 2, $N0
381     is($N1, 'Inf', '...: 2 ^ Inf')
382     $N0 = 'NaN'
383     pow $N1, $N0, 2
384     is($N1, 'NaN', '...: NaN ^ 2')
385     pow $N1, 2, $N0
386     is($N1, 'NaN', '...: 2 ^ NaN')
387 .end
389 .sub test_mix_nan_inf
390     $N0 = 'NaN'
391     $N1 = 'Inf'
392     $N0 *= $N1
393     is($N0, 'NaN', 'mixing NaN and Inf: NaN * Inf')
394     $N0 /= $N1
395     is($N0, 'NaN', '... NaN / Inf')
396     $N0 -= $N1
397     is($N0, 'NaN', '... NaN - Inf')
398     $N0 += $N1
399     is($N0, 'NaN', '... NaN + Inf')
400 .end
402 .sub test_rounding_n
403     $N0 = 'NaN'
404     $N1 = floor $N0
405     is($N1, 'NaN', 'rounding n: floor NaN') 
406     $N2 = ceil $N0
407     is($N2, 'NaN', '... ceil NaN')
408     $N0 = 'Inf'
409     $N1 = floor $N0
410     is($N1, 'Inf', '... floor Inf')
411     $N2 = ceil $N0
412     is($N2, 'Inf', '... ceil Inf')
413     $N0 = '-Inf'
414     $N1 = floor $N0
415     is($N1, '-Inf', '... floor -Inf')
416     $N2 = ceil $N0
417     is($N2, '-Inf', '... ceil -Inf')
418 .end
420 #pir_output_is(<<'CODE',<<OUTPUT, "TT #370 Rounding inf/nan");
421 .sub test_rounding_i
422     $N0 = 'Inf'
423     $I0 = floor $N0
424     #is($I0, 'Inf', 'floor Inf')
425     todo(0, 'floor Inf', 'rounding nan/inf gives something like -2147483648')
426     $N0 = 'NaN'
427     $I0 = floor $N0
428     #is($I0, 'NaN', 'floor Inf')
429     todo(0, 'floor NaN', 'rounding nan/inf gives something like -2147483648')
430     $N0 = 'Inf'
431     $I0 = ceil $N0
432     #is($I0, 'Inf', 'floor Inf')
433     todo(0, 'ceil Inf', 'rounding nan/inf gives something like -2147483648')
434     $N0 = 'NaN'
435     $I0 = ceil $N0
436     #is($I0, 'NaN', 'floor Inf')
437     todo(0, 'ceil NaN', 'rounding nan/inf gives something like -2147483648')
438 .end
440 .sub test_nan_complex
441     $P1 = new ["Complex"]
442     $N0 = 'NaN'
443     set $P1, "1 + i"
444     $P1 += $N0
445     #is($P1, 'NaN', '1+i + NaN')
446     todo(0, '1+i + NaN should be NaN')
447 .end
449 .sub test_fdiv_integer_pmc_nan
450     $P1 = new "Integer"
451     $P2 = new "Integer"
452     $P2 = 1
453     $N0 = 'NaN'
454     fdiv $P1, $P2, $N0
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')
457 .end
459 .sub test_fdiv_float_pmc_nan
460     $P1 = new 'Float'
461     $P2 = new 'Float'
462     $P2 = 1
463     $N0 = 'NaN'
464     fdiv $P1, $P2, $N0
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')
467 .end
469 .sub test_fdiv_float_integer_pmc_nan
470     $P1 = new 'Float'
471     $P2 = new 'Integer'
472     $P2 = 1
473     $N0 = 'NaN'
474     fdiv $P1, $P2, $N0
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')    
477 .end
479 .sub test_cmod_float_integer_pmc_nan
480     $P1 = new 'Float'
481     $P2 = new 'Integer'
482     $P2 = 1
483     $N0 = 'NaN'
484     cmod $P1, $P2, $N0
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')
487 .end
489 .sub test_mod_float_integer_pmc_nan
490     $P1 = new 'Float'
491     $P2 = new 'Integer'
492     $P2 = 1
493     $N0 = 'NaN'
494     mod $P1, $P2, $N0
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')
497 .end
499 # Local Variables:
500 #   mode: cperl
501 #   cperl-indent-level: 4
502 #   fill-column: 100
503 # End:
504 # vim: expandtab shiftwidth=4 filetype=pir: