[t] Convert an exception test to PIR
[parrot.git] / t / pmc / float.t
blobe55fbdb257fd8a8aaf758db4e3743dd2e20eaab3
1 #! parrot
2 # Copyright (C) 2001-2009, Parrot Foundation.
3 # $Id$
5 =head1 NAME
7 t/pmc/float.t - Floating-point Numbers
9 =head1 SYNOPSIS
11     % prove t/pmc/float.t
13 =head1 DESCRIPTION
15 Tests the Float PMC.
17 =cut
19 .const int TESTS = 159
20 .const num PRECISION = 0.000001
22 .sub 'test' :main
23     .include 'test_more.pir'
25     plan(TESTS)
26     basic_assignment()
27     add_number_to_self()
28     sub_number_from_self()
29     multiply_number_by_self()
30     divide_number_by_self()
31     divide_by_zero()
32     truth_positive_float()
33     truth_negative_float()
34     truth_positive_integer()
35     truth_negative_integer()
36     falseness_0()
37     'falseness_0.000'()
38     integer_addition()
39     integer_substraction()
40     integer_multiplication()
41     integer_division()
42     number_addition()
43     number_substraction()
44     number_multiplication()
45     number_division()
46     increment_decrement()
47     'neg'()
48     negative_zero()
49     equality()
50     is_interface_done()
51     'abs'()
52     'lt'()
53     'lt_num'()
54     'le'()
55     'le_num'()
56     'gt'()
57     'gt_num'()
58     'ge'()
59     'ge_num'()
60     cmp_p_n()
61     'isgt'()
62     'isge'()
63     'islt'()
64     'isle'()
65     'iseq'()
66     'isne'()
67     instantiate_str()
68     cmp_subclasses()
69     acos_method()
70     cos_method()
71     asec_method()
72     asin_method()
73     atan_method()
74     atan2_method()
75     cosh_method()
76     exp_method()
77     ln_method()
78     log10_method()
79     log2_method()
80     sec_method()
81     sech_method()
82     sin_method()
83     sinh_method()
84     tan_method()
85     tanh_method()
86     sqrt_method()
87 .end
89 .include 'fp_equality.pasm'
91 .sub 'basic_assignment'
92     $P0 = new ['Float']
94     $P0 = 0.001
95     is($P0, 0.001, 'basic float assignment 1', PRECISION)
97     $P0 = 12.5
98     is($P0, 12.5, 'basic assignment 2', PRECISION)
100     $P0 = 1000
101     is($P0, 1000.0, 'basic integer assignment', PRECISION)
103     $P0 = 'Twelve point five'
104     is($P0, 0.0, 'basic string assignment', PRECISION)
106     $P0 = 123.45
107     $I0 = $P0
108     is($I0, 123, 'rounding to integer')
110     $P0 = 123.45
111     $N0 = $P0
112     is($N0, 123.45, 'get_float_value', PRECISION)
114     $P0 = 123.45
115     $S0 = $P0
116     is($S0, '123.45', 'get string')
118     $P0 = "12.49"
119     $P1 = get_class ['Float']
120     is($P0, 12.49, 'setting value from string', PRECISION)
121 .end
123 .sub 'add_number_to_self'
124     $P0 = new ['Float']
125     $P0 = 0.001
126     $P0 = $P0 + $P0
128     is($P0, 0.002, 'add number to self', PRECISION)
129 .end
131 .sub 'sub_number_from_self'
132     $P0 = new ['Float']
133     $P0 = -1000.2
134     $P0 = $P0 - $P0
136     is($P0, 0.0, 'sub number from self', PRECISION)
137 .end
139 .sub 'multiply_number_by_self'
140     $P0 = new ['Float']
141     $P0 = 123.4
142     $P0 = $P0 * $P0
144     is($P0, 15227.56, 'multiply number by self', PRECISION)
145 .end
147 .sub 'divide_number_by_self'
148     $P0 = new ['Float']
149     $P0 = 1829354.988
150     $P0 = $P0 / $P0
152     is($P0, 1.0, 'divide number by self', PRECISION)
153 .end
155 .sub 'divide_by_zero'
156     $P0 = new ['Float']
157     $P0 = 12.0
159     $P1 = new ['Float']
161     $P2 = new ['Float']
162     $P2 = 0.0
164     push_eh divide_by_zero_handler
165     $P1 = $P0 / $P2
166     pop_eh
167     nok(1, 'divide by zero')
168     .return ()
170   divide_by_zero_handler:
171     .get_results ($P1)
172     $S1 = $P1
173     say $S1
174     like($S1, ':s division by zero', 'divide by zero')
175 .end
177 .sub 'truth_positive_float'
178     .local pmc float_1
179     float_1 = new ['Float']
180     float_1 = 123.123
181     ok(float_1, 'Truth of a positive float')
182 .end
184 .sub 'truth_negative_float'
185     .local pmc float_1
186     float_1 = new ['Float']
187     float_1 = -123.123
188     ok(float_1, 'Truth of a negative float')
189 .end
191 .sub 'truth_positive_integer'
192     .local pmc float_1
193     float_1 = new ['Float']
194     float_1 = 1
195     ok(float_1, 'Truth of a positive integer')
196 .end
198 .sub 'truth_negative_integer'
199     .local pmc float_1
200     float_1 = new ['Float']
201     float_1 = -1
202     ok(float_1, 'Truth of a negative integer')
203 .end
205 .sub 'falseness_0'
206     .local pmc float_1
207     float_1 = new ['Float']
208     float_1 = 0
209     nok(float_1, 'Falseness of 0')
210 .end
212 .sub 'falseness_0.000'
213     .local pmc float_1
214     float_1 = new ['Float']
215     float_1 = 0.000
216     nok(float_1, 'Falseness of 0.000')
217 .end
219 .sub 'integer_addition'
220     $P0 = new ['Float']
222     $P0 = 0.001
223     $P0 += 1
224     is($P0, 1.001, 'Basic integer arithmetic: addition (1)', PRECISION)
226     $P0 += -2
227     is($P0, -0.999, 'Basic integer arithmetic: addition (2)', PRECISION)
228 .end
230 .sub 'integer_substraction'
231     $P0 = new ['Float']
233     $P0 = 103.45
234     $P0 -= 77
235     is($P0, 26.45, 'Basic integer arithmetic: subtraction (1)', PRECISION)
237     $P0 -= -24
238     is($P0, 50.45, 'Basic integer arithmetic: subtraction (2)', PRECISION)
239 .end
241 .sub 'integer_multiplication'
242     $P0 = new ['Float']
244     $P0 = 0.001
245     $P0 *= 10000
246     is($P0, 10.0, 'Basic integer arithmetic: multiplication (1)', PRECISION)
248     $P0 *= -1
249     is($P0, -10.0, 'Basic integer arithmetic: multiplication (2)', PRECISION)
251     $P0 *= 0
252     is($P0, 0.0, 'Basic integer arithmetic: multiplication (3)', PRECISION)
253 .end
255 .sub 'integer_division'
256     $P0 = new ['Float']
258     $P0 = 1e8
259     $P0 /= 10000
260     is($P0, 10000.0, 'Basic integer arithmetic: division (1)', PRECISION)
262     $P0 /= 1000000
263     is($P0, 0.01, 'Basic integer arithmetic: division (2)', PRECISION)
264 .end
266 .sub 'number_addition'
267     $P0 = new ['Float']
269     $P0 = 0.001
270     $P0 += 1.2
271     is($P0, 1.201, 'Basic numeric arithmetic: addition (1)', PRECISION)
273     $P0 += -2.4
274     is($P0, -1.199, 'Basic numeric arithmetic: addition (2)', PRECISION)
275 .end
277 .sub 'number_substraction'
278     $P0 = new ['Float']
280     $P0 = 103.45
281     $P0 -= 3.46
282     is($P0, 99.99, 'Basic numeric arithmetic: subtraction (1)', PRECISION)
284     $P0 -= -0.01
285     is($P0, 100.0, 'Basic numeric arithmetic: subtraction (2)', PRECISION)
286 .end
288 .sub 'number_multiplication'
289     $P0 = new ['Float']
291     $P0 = 0.001
292     $P0 *= 123.5
293     is($P0, 0.1235, 'Basic numeric arithmetic: multiplication (1)', PRECISION)
295     $P0 *= -2.6
296     is($P0, -0.3211, 'Basic numeric arithmetic: multiplication (2)', PRECISION)
298     $P0 *= 0.0
299     is($P0, 0.0, 'Basic numeric arithmetic: multiplication (3)', PRECISION)
300 .end
302 .sub 'number_division'
303     $P0 = new ['Float']
305     $P0 = 1e8
306     $P0 /= 0.5
307     is($P0, 2e8, 'Basic numeric arithmetic: division (1)', PRECISION)
309     $P0 /= 4000.0
310     is($P0, 50000.0, 'Basic numeric arithmetic: division (2)', PRECISION)
311 .end
313 .sub 'increment_decrement'
314     $P0 = new ['Float']
316     $P0 = 0.5
317     inc $P0
318     is($P0, 1.5, 'increment (1)', PRECISION)
319     dec $P0
320     is($P0, 0.5, 'decrement (1)', PRECISION)
321     dec $P0
322     is($P0, -.5, 'decrement (2)', PRECISION)
323     inc $P0
324     is($P0, 0.5, 'increment (2)', PRECISION)
325 .end
327 .sub 'neg'
328     $P0 = new ['Float']
329     $P0 = 0.5
330     neg $P0
331     is($P0, -0.5, 'Neg', PRECISION)
333     $P1 = new ['Float']
334     $P1 = - $P0
335     is($P1, 0.5, 'Neg is involutive', PRECISION)
336 .end
338 .sub 'negative_zero'
339     load_bytecode 'config.pbc'
340     $P1 = _config()
341     $P2 = $P1['has_negative_zero']
342     unless $P2 goto negative_zero_todoed
344     $P0 = new ['Float']
345     $P0 = 0.0
346     neg $P0
348     $S0 = $P0
349     like($S0, '^\-0', 'negative zero')
350     .return ()
352   negative_zero_todoed:
353     todo(1, '-0.0 not implemented, TT#313')
354 .end
356 .sub 'equality'
357     $P0 = new ['Float']
358     $P0 = 1e8
360     $P1 = new ['Float']
361     $P1 = 1e8
363     $P2 = new ['Float']
364     $P2 = 2.4
366     $I0 = 1
367     if $P0 == $P1 goto equality_1
368     $I0 = 0
369   equality_1:
370     ok($I0, 'equal floats')
372     $I0 = 0
373     if $P0 == $P2 goto equality_2
374     $I0 = 1
375   equality_2:
376     ok($I0, 'different floats are not equal')
378     $I0 = 1
379     if $P0 != $P2 goto equality_3
380     $I0 = 0
381   equality_3:
382     ok($I0, "different floats are different")
384     $I0 = 0
385     if $P0 != $P1 goto equality_4
386     $I0 = 1
387   equality_4:
388     ok($I0, "equal floats aren't different")
390     $I0 = 1
391     eq_num $P0, $P1, equality_5
392     $I0 = 0
393   equality_5:
394     ok($I0, "equal floats are eq_num")
396     $I0 = 0
397     eq_num $P0, $P2, equality_6
398     $I0 = 1
399   equality_6:
400     ok($I0, "different floats aren't eq_num")
402     $I0 = 1
403     ne_num $P0, $P2, equality_7
404     $I0 = 0
405   equality_7:
406     ok($I0, "different floats are ne_num")
408     $I0 = 0
409     ne_num $P0, $P1, equality_8
410     $I0 = 1
411   equality_8:
412     ok($I0, "equal floats aren't ne_num")
413 .end
415 .sub 'is_interface_done'
416     .local pmc pmc1
417     .local int bool1
418     pmc1 = new ['Float']
420     bool1 = does pmc1, "scalar"
421     ok(bool1, 'Float does "scalar"')
423     bool1 = does pmc1, "float"
424     ok(bool1, 'Float does "float"')
426     bool1 = does pmc1, "no_interface"
427     nok(bool1, 'Float does not "no_interface"')
428 .end
430 .sub 'abs'
431     $P0 = new ['Float']
432     $P0 = 1.0
433     abs $P0
434     is($P0, $P0, 'abs does not change positive floats')
436     $P0 = -1.0
437     abs $P0
438     is($P0, 1.0, 'abs of -1.0', PRECISION)
440     $P0 = -5.0
441     abs $P0
442     is($P0, 5.0, 'abs of -5.0', PRECISION)
443 .end
445 .sub 'lt'
446     $P1 = new ['Float']
447     $P1 = 111.11
448     $N1 = $P1
450     $I0 = 1
451     lt $P1, 111.12, lt_1
452     $I0 = 0
453   lt_1:
454     ok($I0, 'lt ok')
456     $I0 = 0
457     lt $P1, $N1, lt_2
458     $I0 = 1
459   lt_2:
460     ok($I0, 'lt irreflexive')
462     $I0 = 0
463     lt $P1, 111.0, lt_3
464     $I0 = 1
465   lt_3:
466     ok($I0, 'not lt')
467 .end
469 .sub 'lt_num'
470     $P1 = new ['Float']
471     $P1 = 1.1
473     $P2 = new ['Float']
474     $P2 = 1.2
476     $P3 = new ['Float']
477     $P3 = 1.0
479     $P4 = new ['Float']
480     $P4 = $P1
482     $I0 = 1
483     lt_num $P1, $P2, lt_num_1
484     $I0 = 0
485   lt_num_1:
486     ok($I0, 'lt_num true')
488     $I0 = 0
489     lt_num $P1, $P4, lt_num_2
490     $I0 = 1
491   lt_num_2:
492     ok($I0, 'lt_num irreflexive')
494     $I0 = 0
495     lt_num $P1, $P3, lt_num_3
496     $I0 = 1
497   lt_num_3:
498     ok($I0, 'lt_num false')
499 .end
501 .sub 'le'
502     $P1 = new ['Float']
503     $P1 = 111.1
504     $N1 = $P1
506     $I0 = 1
507     le $P1, 111.2, le_1
508     $I0 = 0
509   le_1:
510     ok($I0, 'le_p_nc')
512     $I0 = 1
513     le $P1, $N1, le_2
514     $I0 = 0
515   le_2:
516     ok($I0, 'le_p_n')
518     $I0 = 0
519     le $P1, 111.0, le_3
520     $I0 = 1
521   le_3:
522     ok($I0, 'le_p_nc false')
524     $I0 = 1
525     le $P1, $P1, le_4
526     $I0 = 0
527   le_4:
528     ok($I0, 'le reflexive')
529 .end
531 .sub 'le_num'
532     $P1 = new ['Float']
533     $P1 = 1.1
535     $P2 = new ['Float']
536     $P2 = 1.2
538     $P3 = new ['Float']
539     $P3 = 1.0
541     $P4 = new ['Float']
542     $P4 = $P1
544     $I0 = 1
545     le_num $P1, $P2, le_num_1
546     $I0 = 0
547   le_num_1:
548     ok($I0, 'le_num true')
550     $I0 = 1
551     le_num $P1, $P4, le_num_2
552     $I0 = 0
553   le_num_2:
554     ok($I0, 'le_num reflexive')
556     $I0 = 0
557     le_num $P1, $P3, le_num_3
558     $I0 = 1
559   le_num_3:
560     ok($I0, 'le_num false')
561 .end
563 .sub 'gt'
564     $P1 = new ['Float']
565     $P1 = 111.1
566     $N1 = $P1
568     $I0 = 0
569     gt $P1, 111.2, gt_1
570     $I0 = 1
571   gt_1:
572     ok($I0, 'comparison ops: gt nok')
574     $I0 = 1
575     gt $P1, $N1, gt_2
576     $I0 = 0
577   gt_2:
578     nok($I0, 'comparison ops: gt irreflexive')
580     $I0 = 1
581     gt $P1, 111.0, gt_3
582     $I0 = 0
583   gt_3:
584     ok($I0, 'comparison ops: gt ok')
585 .end
587 .sub 'gt_num'
588     $P1 = new ['Float']
589     $P2 = new ['Float']
590     $P3 = new ['Float']
591     $P4 = new ['Float']
593     $P1 = 1.1
594     $P2 = 1.2
595     $P3 = 1.0
596     $P4 = $P1
598     $I0 = 0
599     gt_num $P1, $P2, gt_num_1
600     $I0 = 1
601   gt_num_1:
602     ok($I0, 'comparison ops: gt_num nok')
604     $I0 = 0
605     gt_num $P1, $P4, gt_num_2
606     $I0 = 1
607   gt_num_2:
608     ok($I0, 'comparison ops: gt_num irreflexive')
610     $I0 = 1
611     gt_num $P1, $P3, gt_num_3
612     $I0 = 0
613   gt_num_3:
614     ok($I0, 'comparison ops: gt_num ok')
615 .end
617 .sub 'ge'
618     $P1 = new ['Float']
619     $P1 = 111.1
620     $N1 = $P1
622     $I0 = 0
623     ge $P1, 111.2, ge_1
624     $I0 = 1
625   ge_1:
626     ok($I0, 'comparison ops: ge nok')
628     $I0 = 1
629     ge $P1, $N1, ge_2
630     $I0 = 0
631   ge_2:
632     ok($I0, 'comparison ops: ge reflexive')
634     $I0 = 1
635     ge $P1, 111.0, ge_3
636     $I0 = 0
637   ge_3:
638     ok($I0, 'comparison ops: ge ok')
639 .end
641 .sub 'ge_num'
642     $P1 = new ['Float']
643     $P2 = new ['Float']
644     $P3 = new ['Float']
645     $P4 = new ['Float']
647     $P1 = 1.1
648     $P2 = 1.2
649     $P3 = 1.0
650     $P4 = $P1
652     $I0 = 0
653     ge_num $P1, $P2, ge_num_1
654     $I0 = 1
655   ge_num_1:
656     ok($I0, 'comparison ops: ge_num nok')
658     $I0 = 1
659     ge_num $P1, $P4, ge_num_2
660     $I0 = 0
661   ge_num_2:
662     ok($I0, 'comparison ops: ge_num reflexive')
664     $I0 = 1
665     ge_num $P1, $P3, ge_num_3
666     $I0 = 0
667   ge_num_3:
668     ok($I0, 'comparison ops: ge_num ok')
669 .end
671 .sub 'cmp_p_n'
672     $P1 = new ['Float']
673     $P1 = 123.45
674     $N1 = 123.45
675     $N2 = -1.0
676     $N3 = 123.54
678     $I0 = cmp $P1, $N1
679     is($I0, 0, 'comparison ops: cmp_p_n: equality')
681     $I0 = cmp $P1, $N2
682     is($I0, 1, 'comparison ops: cmp_p_n: gt')
684     $I0 = cmp $P1, $N3
685     is($I0, -1, 'comparison ops: cmp_p_n: lt')
686 .end
688 .sub 'isgt'
689     $P1 = new ['Float']
690     $P2 = new ['Float']
691     $P3 = new ['Float']
692     $P4 = new ['Integer']
693     $P5 = new ['Integer']
694     $P6 = new ['Float']
696     $P1 = 10.0
697     $P2 = 20.0
698     $P3 = 5.0
699     $P4 = 3
700     $P5 = 12
701     $P6 = 10.0
703     $I0 = isgt $P1, $P2
704     nok($I0, 'comparison ops: isgt nok')
706     $I0 = isgt $P1, $P1
707     nok($I0, 'comparison ops: isgt irreflexive')
709     $I0 = isgt $P1, $P3
710     ok($I0, 'comparison ops: isgt ok')
712     $I0 = isgt $P1, $P4
713     ok($I0, 'comparison ops: isgt ok with Float and Integer')
715     $I0 = isgt $P1, $P5
716     nok($I0, 'comparison ops: isgt nok with Float and Integer')
718     $I0 = isgt $P1, $P6
719     nok($I0, 'comparison ops: isgt irreflexive (different PMCs)')
720 .end
722 .sub 'isge'
723     $P1 = new ['Float']
724     $P2 = new ['Float']
725     $P3 = new ['Float']
726     $P4 = new ['Integer']
727     $P5 = new ['Integer']
728     $P6 = new ['Float']
730     $P1 = 10.0
731     $P2 = 20.0
732     $P3 = 5.0
733     $P4 = 3
734     $P5 = 12
735     $P6 = 10.0
737     $I0 = isge $P1, $P2
738     nok($I0, 'comparison ops: isge nok')
740     $I0 = isge $P1, $P1
741     ok($I0, 'comparison ops: isge reflexive')
743     $I0 = isge $P1, $P3
744     ok($I0, 'comparison ops: isge ok')
746     $I0 = isge $P1, $P4
747     ok($I0, 'comparison ops: isge ok with Float and Integer')
749     $I0 = isge $P1, $P5
750     nok($I0, 'comparison ops: isge nok with Float and Integer')
752     $I0 = isge $P1, $P6
753     ok($I0, 'comparison ops: isge reflexive (different PMCs)')
754 .end
756 .sub 'islt'
757     $P1 = new ['Float']
758     $P2 = new ['Float']
759     $P3 = new ['Float']
760     $P4 = new ['Integer']
761     $P5 = new ['Integer']
762     $P6 = new ['Float']
764     $P1 = 10.0
765     $P2 = 20.0
766     $P3 = 5.0
767     $P4 = 3
768     $P5 = 12
769     $P6 = 10.0
771     $I0 = islt $P1, $P2
772     ok($I0, 'comparison ops: islt ok')
774     $I0 = islt $P1, $P1
775     nok($I0, 'comparison ops: islt irreflexive')
777     $I0 = islt $P1, $P3
778     nok($I0, 'comparison ops: islt nok')
780     $I0 = islt $P1, $P4
781     nok($I0, 'comparison ops: islt nok with Float and Integer')
783     $I0 = islt $P1, $P5
784     ok($I0, 'comparison ops: islt ok with Float and Integer')
786     $I0 = islt $P1, $P6
787     nok($I0, 'comparison ops: islt irreflexive (different PMCs)')
788 .end
790 .sub 'isle'
791     $P1 = new ['Float']
792     $P2 = new ['Float']
793     $P3 = new ['Float']
794     $P4 = new ['Integer']
795     $P5 = new ['Integer']
796     $P6 = new ['Float']
798     $P1 = 10.0
799     $P2 = 20.0
800     $P3 = 5.0
801     $P4 = 3
802     $P5 = 12
803     $P6 = 10.0
805     $I0 = isle $P1, $P2
806     ok($I0, 'comparison ops: isle ok')
808     $I0 = isle $P1, $P1
809     ok($I0, 'comparison ops: isle reflexive')
811     $I0 = isle $P1, $P3
812     nok($I0, 'comparison ops: isle nok')
814     $I0 = isle $P1, $P4
815     nok($I0, 'comparison ops: isle nok with Float and Integer')
817     $I0 = isle $P1, $P5
818     ok($I0, 'comparison ops: isle ok with Float and Integer')
820     $I0 = isle $P1, $P6
821     ok($I0, 'comparison ops: isle reflexive (different PMCs)')
822 .end
824 .sub 'iseq'
825     $P1 = new ['Float']
826     $P2 = new ['Float']
827     $P3 = new ['Float']
828     $P4 = new ['Integer']
830     $P1 = 2.5
831     $P2 = 2.6
832     $P3 = 2.5
833     $P4 = 2
835     $I0 = iseq $P1, $P1
836     ok($I0, 'iseq reflexive, same PMC')
838     $I0 = iseq $P1, $P3
839     ok($I0, 'iseq reflexive, different PMCs')
841     $I0 = iseq $P1, $P2
842     nok($I0, 'iseq nok with two Floats')
844     $I0 = iseq $P1, $P4
845     nok($I0, 'iseq nok between an Integer and a Float')
846 .end
848 .sub 'isne'
849     $P1 = new ['Float']
850     $P2 = new ['Float']
851     $P3 = new ['Float']
852     $P4 = new ['Integer']
854     $P1 = 2.5
855     $P2 = 2.6
856     $P3 = 2.5
857     $P4 = 2
859     $I0 = isne $P1, $P1
860     nok($I0, 'isne irreflexive, same PMC')
862     $I0 = isne $P1, $P3
863     nok($I0, 'isne irreflexive, different PMCs')
865     $I0 = isne $P1, $P2
866     ok($I0, 'isne ok with two Floats')
868     $I0 = isne $P1, $P4
869     ok($I0, 'isne ok between an Integer and a Float')
870 .end
872 .sub 'instantiate_str'
873     .const 'Float' pi = "3.1"
874     $P1 = get_class ['Float']
875     isa_ok(pi, $P1)
876     is(pi, 3.1, 'instantiate_str', PRECISION)
877 .end
879 .sub 'cmp_subclasses'
880     $P0 = subclass 'Float', 'Flt'
882     $P1 = new ['Flt']
883     $P1 = 1.5
885     $P2 = new ['Flt']
886     $P2 = 2.73
888     $I0 = cmp $P1, $P2
889     is(-1, $I0, 'cmp functions for subclasses (lt)')
891     $I0 = cmp $P1, $P1
892     is(0, $I0, 'cmp functions for subclasses (eq)')
894     $I0 = cmp $P2, $P1
895     is(1, $I0, 'cmp functions for subclasses (gt)')
896 .end
898 .sub 'test_method'
899     .param string method
900     .param num number
901     .param num expected
903     .local pmc array
904     array = new 'FixedPMCArray'
905     array = 3
906     array[0] = method
907     array[1] = number
908     array[2] = expected
910     $P0 = new ['Float']
911     $P0 = number
912     $P1 = $P0.method()
914     $S0 = sprintf '%s(%.1f) is %.9f', array
915     is($P1, expected, $S0, PRECISION)
916 .end
918 .sub 'acos_method'
919     test_method('acos', 0.0, 1.570796327)
920     test_method('acos', 0.5, 1.047197551)
921 .end
923 .sub 'cos_method'
924     test_method('cos', 0.0, 1.0)
925     test_method('cos', 0.5, 0.877582562)
926 .end
928 .sub 'asec_method'
929     test_method('asec', 1.0, 0.0)
930     test_method('asec', 3.0, 1.230959417)
931 .end
933 .sub 'asin_method'
934     test_method('asin', 0.0, 0.0)
935     test_method('asin', 0.5, 0.523598776)
936 .end
938 .sub 'atan_method'
939     test_method('atan', 0.0, 0.0)
940     test_method('atan', 0.5, 0.463647609)
941 .end
943 .sub 'atan2_method'
944     $P0 = new ['Float']
945     $P1 = new ['Float']
947     $P0 = 0.7
948     $P1 = 0.5
950     $P2 = $P0.'atan2'($P1)
951     is($P2, 0.950546841, 'atan2 as a method', PRECISION)
952 .end
954 .sub 'cosh_method'
955     test_method('cosh', 0.0, 1.0)
956     test_method('cosh', 0.5, 1.127625965)
957 .end
959 .sub 'exp_method'
960     test_method('exp', 0.0, 1.0)
961     test_method('exp', 0.5, 1.648721271)
962 .end
964 .sub 'ln_method'
965     test_method('ln', 1.0, 0.0)
966     test_method('ln', 45.0, 3.806662490)
967     test_method('ln', 0.5, -0.693147181)
968 .end
970 .sub 'log10_method'
971     test_method('log10', 1000.0, 3.0)
972     test_method('log10', 0.5, -0.301029996)
973 .end
975 .sub 'log2_method'
976     test_method('log2', 32.0, 5.0)
977     test_method('log2', 0.5, -1.0)
978 .end
980 .sub 'sec_method'
981     test_method('sec', 0.0, 1.0)
982     test_method('sec', 0.5, 1.139493927)
983 .end
985 .sub 'sech_method'
986     test_method('sech', 0.0, 1.0)
987     test_method('sech', 0.5, 0.886818884)
988 .end
990 .sub 'sin_method'
991     test_method('sin', 0.0, 0.0)
992     test_method('sin', 0.5, 0.479425539)
993 .end
995 .sub 'sinh_method'
996     test_method('sinh', 0.0, 0.0)
997     test_method('sinh', 0.5, 0.521095305)
998 .end
1000 .sub 'tan_method'
1001     test_method('tan', 0.0, 0.0)
1002     test_method('tan', 0.5, 0.546302490)
1003 .end
1005 .sub 'tanh_method'
1006     test_method('tanh', 0.0, 0.0)
1007     test_method('tanh', 0.5, 0.462117157)
1008 .end
1010 .sub 'sqrt_method'
1011     test_method('sqrt', 16.0, 4.0)
1012     test_method('sqrt', 2.0, 1.414213562)
1013 .end
1015 # Local Variables:
1016 #   mode: pir
1017 #   fill-column: 100
1018 # End:
1019 # vim: expandtab shiftwidth=4 ft=pir: