tagged release 0.7.1
[parrot.git] / t / op / trans.t
blob4867cab14d15a37cd9974a4d43888c3e4cd16717
1 #!perl
2 # Copyright (C) 2001-2005, The Perl Foundation.
3 # $Id$
5 use strict;
6 use warnings;
7 use lib qw( . lib ../lib ../../lib );
8 use Test::More;
9 use Parrot::Test tests => 22;
10 use Math::Trig qw( tan sec atan asin acos asec cosh sinh tanh sech );
12 =head1 NAME
14 t/op/trans.t - Transcendental Mathematical Ops
16 =head1 SYNOPSIS
18         % prove t/op/trans.t
20 =head1 DESCRIPTION
22 Tests the transcendental mathematical operations.
24 =cut
26 # This defines two macros:
27 # fp_eq N, N, LABEL
28 # fp_ne N, N, LABEL
29 # which will conditionally branch
30 # to LABEL if abs(n,n) < epsilon
32 pasm_output_is( <<"CODE", <<OUTPUT, "sin" );
33         .include 'include/fp_equality.pasm'
34         set     N1, 1.0
35         sin     N2, N1
36         .fp_eq  (N2, 0.841471, EQ1)
37         print   "not "
38 EQ1:    print   "ok 1\\n"
40         set     I1, 1
41         sin     N2, I1
42         .fp_eq  (N2, 0.841471, EQ2)
43         print   "not "
44 EQ2:    print   "ok 2\\n"
46         end
47 CODE
48 ok 1
49 ok 2
50 OUTPUT
52 pasm_output_is( <<"CODE", <<OUTPUT, "cos" );
53         .include 'include/fp_equality.pasm'
54         set     N1, 1.0
55         cos     N2, N1
56         .fp_eq  (N2, 0.540302, EQ1)
57         print   "not "
58 EQ1:    print   "ok 1\\n"
60         set     I1, 1
61         cos     N2, I1
62         .fp_eq  (N2, 0.540302, EQ2)
63         print   "not "
64 EQ2:    print   "ok 2\\n"
65         end
66 CODE
67 ok 1
68 ok 2
69 OUTPUT
71 pasm_output_is( <<"CODE", <<OUTPUT, "tan" );
72         .include 'include/fp_equality.pasm'
73         set     N1, 1.0
74         tan     N2, N1
75         .fp_eq  (N2, 1.557408, EQ1)
76         print   "not "
77 EQ1:    print   "ok 1\\n"
79         set     I1, 1
80         tan     N2, I1
81         .fp_eq  (N2, 1.557408, EQ2)
82         print   "not "
83 EQ2:    print   "ok 2\\n"
84         end
85 CODE
86 ok 1
87 ok 2
88 OUTPUT
90 pasm_output_is( <<"CODE", <<OUTPUT, "sec" );
91         .include 'include/fp_equality.pasm'
92         set N1, 1.0
93         sec N2, N1
94         .fp_eq  (N2, 1.850816, EQ1)
95         print "not "
96 EQ1:    print "ok 1\\n"
98         set I1, 1
99         sec N2, I1
100         .fp_eq  (N2, 1.850816, EQ2)
101         print "not "
102 EQ2:    print "ok 2\\n"
103         end
104 CODE
105 ok 1
106 ok 2
107 OUTPUT
109 pasm_output_is( <<"CODE", <<OUTPUT, "atan" );
110         .include 'include/fp_equality.pasm'
111         set N1, 1.0
112         atan N2, N1
113         .fp_eq  (N2, 0.785398, EQ1)
114         print "not "
115 EQ1:    print "ok 1\\n"
117         set I1, 1
118         atan N2, I1
119         .fp_eq  (N2,0.785398 , EQ2)
120         print "not "
121 EQ2:    print "ok 2\\n"
122         end
123 CODE
124 ok 1
125 ok 2
126 OUTPUT
128 pasm_output_is( <<"CODE", <<OUTPUT, "asin" );
129         .include 'include/fp_equality.pasm'
130         set N1, 1.0
131         asin N2, N1
132         .fp_eq  (N2, 1.570796, EQ1)
133         print "not "
134 EQ1:    print "ok 1\\n"
136         set I1, 1
137         asin N2, I1
138         .fp_eq  (N2, 1.570796 , EQ2)
139         print "not "
140 EQ2:    print "ok 2\\n"
142         end
143 CODE
144 ok 1
145 ok 2
146 OUTPUT
148 pasm_output_is( <<"CODE", <<OUTPUT, "acos" );
149         .include 'include/fp_equality.pasm'
150         set N1, 1.0
151         acos N2, N1
152         .fp_eq  (N2, 0.000000, EQ1)
153         print "not "
154 EQ1:    print "ok 1\\n"
156         set I1, 1
157         acos N2, I1
158         .fp_eq  (N2, 0.000000, EQ2)
159         print "not "
160 EQ2:    print "ok 2\\n"
162         end
163 CODE
164 ok 1
165 ok 2
166 OUTPUT
168 pasm_output_is( <<"CODE", <<OUTPUT, "asec" );
169         .include 'include/fp_equality.pasm'
170         set N1, 1.0
171         asec N2, N1
172         .fp_eq  (N2, 0.000000, EQ1)
173         print "not "
174 EQ1:    print "ok 1\\n"
176         set I1, 1
177         asec N2, I1
178         .fp_eq  (N2, 0.000000, EQ2)
179         print "not "
180 EQ2:    print "ok 2\\n"
182         end
183 CODE
184 ok 1
185 ok 2
186 OUTPUT
188 pasm_output_is( <<"CODE", <<OUTPUT, "cosh" );
189         .include 'include/fp_equality.pasm'
190         set N1, 1.0
191         cosh N2, N1
192         .fp_eq  (N2, 1.543081, EQ1)
193         print "not "
194 EQ1:    print "ok 1\\n"
196         set I1, 1
197         cosh N2, I1
198         .fp_eq  (N2, 1.543081, EQ2)
199         print "not "
200 EQ2:    print "ok 2\\n"
202         end
203 CODE
204 ok 1
205 ok 2
206 OUTPUT
208 pasm_output_is( <<"CODE", <<OUTPUT, "sinh" );
209         .include 'include/fp_equality.pasm'
210         set N1, 1.0
211         sinh N2, N1
212         .fp_eq  (N2, 1.175201, EQ1)
213         print "not "
214 EQ1:    print "ok 1\\n"
216         set I1, 1
217         sinh N2, I1
218         .fp_eq  (N2, 1.175201, EQ2)
219         print "not "
220 EQ2:    print "ok 2\\n"
222         end
223 CODE
224 ok 1
225 ok 2
226 OUTPUT
228 pasm_output_is( <<"CODE", <<OUTPUT, "tanh" );
229         .include 'include/fp_equality.pasm'
230         set N1, 1.0
231         tanh N2, N1
232         .fp_eq  (N2, 0.761594, EQ1)
233         print "not "
234 EQ1:    print "ok 1\\n"
236         set I1, 1
237         tanh N2, I1
238         .fp_eq  (N2, 0.761594, EQ2)
239         print "not "
240 EQ2:    print "ok 2\\n"
242         end
243 CODE
244 ok 1
245 ok 2
246 OUTPUT
248 pasm_output_is( <<"CODE", <<OUTPUT, "sech" );
249         .include 'include/fp_equality.pasm'
250         set N1, 1.0
251         sech N2, N1
252         .fp_eq  (N2, 0.648054, EQ1)
253         print "not "
254 EQ1:    print "ok 1\\n"
256         set I1, 1
257         sech N2, I1
258         .fp_eq  (N2, 0.648054, EQ2)
259         print "not "
260 EQ2:    print "ok 2\\n"
262         end
263 CODE
264 ok 1
265 ok 2
266 OUTPUT
268 pasm_output_is( <<"CODE", <<OUTPUT, "atan2" );
269         .include 'include/fp_equality.pasm'
270         set N0, 0.0
271         set I0, 0
272         set N1, 1.0
273         set I1, 1
274         set N2, 1.0
275         set I2, 1
276         set I3, -1
277         set N3, -1.0
279         atan N4, N1, N2
280         .fp_eq  (N4, 0.785398, EQ1)
281         print "not "
282 EQ1:    print "ok 1\\n"
284         atan N4, N1, I2
285         .fp_eq  (N4, 0.785398, EQ2)
286         print "not "
287 EQ2:    print "ok 2\\n"
289         atan N4, I1, N2
290         .fp_eq  (N4, 0.785398, EQ3)
291         print "not "
292 EQ3:    print "ok 3\\n"
294         atan N4, I1, I2
295         .fp_eq  (N4, 0.785398, EQ4)
296         print "not "
297 EQ4:    print "ok 4\\n"
299         atan N4, N3, 1.0
300         .fp_eq   (N4, -0.785398, EQ5)
301         print "not "
302 EQ5:    print "ok 5\\n"
304         atan N4, N1, 0
305         .fp_eq   (N4, 1.570796, EQ6)
306         print "not "
307 EQ6:    print "ok 6\\n"
309         atan N4, I3, 0.0
310         .fp_eq   (N4, -1.570796, EQ7)
311         print "not "
312 EQ7:    print "ok 7\\n"
314         atan N4, I3, -1
315         .fp_eq   (N4, -2.356194, EQ8)
316         print "not "
317 EQ8:    print "ok 8\\n"
319         atan N4, 1.0, N3
320         .fp_eq   (N4, 2.356194, EQ9)
321         print "not "
322 EQ9:    print "ok 9\\n"
324         atan N4, 1.0, I0
325         .fp_eq   (N4, 1.570796, EQ10)
326         print "not "
327 EQ10:   print "ok 10\\n"
329         atan N4, 1, N1
330         .fp_eq   (N4, 0.785398, EQ11)
331         print "not "
332 EQ11:   print "ok 11\\n"
334         atan N4, 1, I1
335         .fp_eq   (N4, 0.785398, EQ12)
336         print "not "
337 EQ12:   print "ok 12\\n"
339         atan N4, 0.0, 1.0
340         .fp_eq   (N4, 0.000000, EQ13)
341         print "not "
342 EQ13:   print "ok 13\\n"
344         atan N4, -1.0, 0
345         .fp_eq   (N4, -1.570796, EQ14)
346         print "not "
347 EQ14:   print "ok 14\\n"
349         atan N4, 1, -1.0
350         .fp_eq   (N4, 2.356194, EQ15)
351         print "not "
352 EQ15:   print "ok 15\\n"
354         atan N4, 0, 1
355         .fp_eq   (N4, 0.000000, EQ16)
356         print "not "
357 EQ16:   print "ok 16\\n"
358         end
359 CODE
360 ok 1
361 ok 2
362 ok 3
363 ok 4
364 ok 5
365 ok 6
366 ok 7
367 ok 8
368 ok 9
369 ok 10
370 ok 11
371 ok 12
372 ok 13
373 ok 14
374 ok 15
375 ok 16
376 OUTPUT
378 TODO: {
379 local $TODO = 'fails on netbsd' if $^O =~ /netbsd/;
381 pasm_output_is( <<"CODE", <<'OUTPUT', 'atan, part 2' );
382         .include 'include/fp_equality.pasm'
383         atan N4, -0.0, -0.0
384         .fp_eq   (N4, -3.1415926, EQ1)
385         print "not "
386         print N4
387 EQ1:    print "ok 1\\n"
388         end
389 CODE
390 ok 1
391 OUTPUT
395 pasm_output_is( <<"CODE", <<OUTPUT, "log2" );
396         .include 'include/fp_equality.pasm'
397         set N1, 10.0
398         log2 N2, N1
399         .fp_eq  (N2, 3.321928, EQ1)
400         print "not "
401 EQ1:    print "ok 1\\n"
403         set I1, 10
404         log2 N2, I1
405         .fp_eq  (N2, 3.321928, EQ2)
406         print "not "
407 EQ2:    print "ok 2\\n"
409         end
410 CODE
411 ok 1
412 ok 2
413 OUTPUT
415 pasm_output_is( <<"CODE", <<OUTPUT, "log10" );
416         .include 'include/fp_equality.pasm'
417         set N1, 15.0
418         log10 N2, N1
419         .fp_eq  (N2, 1.176091, EQ1)
420         print "not "
421 EQ1:    print "ok 1\\n"
423         set I1, 15
424         log10 N2, I1
425         .fp_eq  (N2, 1.176091, EQ2)
426         print "not "
427 EQ2:    print "ok 2\\n"
429         end
430 CODE
431 ok 1
432 ok 2
433 OUTPUT
435 pasm_output_is( <<"CODE", <<OUTPUT, "ln" );
436         .include 'include/fp_equality.pasm'
437         set N1, 10.0
438         ln N2, N1
439         .fp_eq  (N2, 2.302585, EQ1)
440         print "not "
441 EQ1:    print "ok 1\\n"
443         set I1, 10
444         ln N2, I1
445         .fp_eq  (N2, 2.302585, EQ2)
446         print "not "
447 EQ2:    print "ok 2\\n"
448         end
449 CODE
450 ok 1
451 ok 2
452 OUTPUT
454 pasm_output_is( <<"CODE", <<OUTPUT, "exp" );
455         .include 'include/fp_equality.pasm'
456         set N1, 10.0
457         exp N2, N1
458         .fp_eq  (N2, 22026.465795, EQ1)
459         print "not "
460 EQ1:    print "ok 1\\n"
462         set I1, 10
463         exp N2, I1
464         .fp_eq (N2, 22026.465795, EQ2)
465         print "not "
466 EQ2:    print "ok 2\\n"
467         end
468 CODE
469 ok 1
470 ok 2
471 OUTPUT
473 pasm_output_is( <<"CODE", <<OUTPUT, "pow" );
474         .include 'include/fp_equality.pasm'
475         set N1, 3.0
476         set I1, 3
477         set N2, 5.0
478         set I2, 5
479         pow N3, N1, N2
480         .fp_eq  (N3, 243.0, EQ1)
481         print "not "
482 EQ1:    print "ok 1\\n"
484         pow N3, N1, I2
485         .fp_eq  (N3, 243.0, EQ2)
486         print "not "
487 EQ2:    print "ok 2\\n"
489         pow N3, I1, N2
490         .fp_eq  (N3, 243.0, EQ3)
491         print "not "
492 EQ3:    print "ok 3\\n"
494         pow N3, I1, I2
495         .fp_eq  (N3, 243.0, EQ4)
496         print "not "
497 EQ4:    print "ok 4\\n"
499         set N0, 0.0
500         set I0, 0
501         set N1, 1.0
502         set I1, 1
503         set N2, 4.0
504         set I2, 4
505         pow N3, N2, 2.5
506         .fp_eq  (N3, 32.0, EQ5)
507         print "not "
508 EQ5:    print "ok 5\\n"
510         pow N3, N2, -2
511         .fp_eq  (N3, 0.0625, EQ6)
512         print "not "
513 EQ6:    print "ok 6\\n"
515         pow N3, I2, 0.5
516         .fp_eq  (N3, 2.0, EQ7)
517         print "not "
518 EQ7:    print "ok 7\\n"
520         pow N3, I2, 0
521         .fp_eq  (N3, 1.0, EQ8)
522         print "not "
523 EQ8:    print "ok 8\\n"
525         pow N3, 0.0, N2
526         .fp_eq  (N3, 0.0, EQ9)
527         print "not "
528 EQ9:    print "ok 9\\n"
530         pow N3, 2.5, 0.0
531         .fp_eq  (N3, 1.0, EQ10)
532         print "not "
533 EQ10:   print "ok 10\\n"
535         pow N3, 2.5, I2
536         .fp_eq  (N3, 39.0625, EQ11)
537         print "not "
538 EQ11:   print "ok 11\\n"
540         pow N3, 2.0, -4
541         .fp_eq  (N3, 0.0625, EQ12)
542         print "not "
543 EQ12:   print "ok 12\\n"
545         pow N3, 0, N2
546         .fp_eq  (N3, 0.0, EQ13)
547         print "not "
548 EQ13:   print "ok 13\\n"
550         pow N3, 4, -0.5
551         .fp_eq  (N3, 0.5, EQ14)
552         print "not "
553 EQ14:   print "ok 14\\n"
555         pow N3, 4, I2
556         .fp_eq  (N3, 256.0, EQ15)
557         print "not "
558 EQ15:   print "ok 15\\n"
560         pow N3, 4, -1
561         .fp_eq  (N3, 0.25, EQ16)
562         print "not "
563 EQ16:   print "ok 16\\n"
564         end
565 CODE
566 ok 1
567 ok 2
568 ok 3
569 ok 4
570 ok 5
571 ok 6
572 ok 7
573 ok 8
574 ok 9
575 ok 10
576 ok 11
577 ok 12
578 ok 13
579 ok 14
580 ok 15
581 ok 16
582 OUTPUT
584 pasm_output_is( <<"CODE", <<OUTPUT, "sqrt" );
585        .include 'include/fp_equality.pasm'
586        set N1, 9.0
587        sqrt N2, N1
588        .fp_eq  (N2, 3.0, EQ1)
589        print "not "
590 EQ1:   print "ok 1\\n"
592        set I1, 9
593        sqrt N2, I1
594        .fp_eq  (N2, 3.0, EQ2)
595        print "not "
596 EQ2:   print "ok 2\\n"
598        end
599 CODE
600 ok 1
601 ok 2
602 OUTPUT
604 pasm_output_is( <<'CODE', <<OUTPUT, "pow_n_n_ic" );
605     set N0, 2.0
606     pow N1, N0, 0
607     print N1
608     print "\n"
609     pow N1, N0, 1
610     print N1
611     print "\n"
612     pow N1, N0, 2
613     print N1
614     print "\n"
615     pow N1, N0, 3
616     print N1
617     print "\n"
618     pow N1, N0, 4
619     print N1
620     print "\n"
621     pow N1, N0, 5
622     print N1
623     print "\n"
624     pow N1, N0, 6
625     print N1
626     print "\n"
627     pow N1, N0, 7
628     print N1
629     print "\n"
630     pow N1, N0, -1
631     print N1
632     print "\n"
633     pow N1, N0, -2
634     print N1
635     print "\n"
636     pow N1, N0, -3
637     print N1
638     print "\n"
639     pow N1, N0, -4
640     print N1
641     print "\n"
642     pow N1, N0, -5
643     end
644 CODE
645 1.000000
646 2.000000
647 4.000000
648 8.000000
649 16.000000
650 32.000000
651 64.000000
652 128.000000
653 0.500000
654 0.250000
655 0.125000
656 0.062500
657 OUTPUT
659 pasm_output_is( <<'CODE', <<OUTPUT, "pow_n_n_i" );
660     set N0, 2.0
661     set I0, 0
662     pow N1, N0, I0
663     print N1
664     print "\n"
665     inc I0
666     pow N1, N0, I0
667     print N1
668     print "\n"
669     inc I0
670     pow N1, N0, I0
671     print N1
672     print "\n"
673     inc I0
674     pow N1, N0, I0
675     print N1
676     print "\n"
677     inc I0
678     pow N1, N0, I0
679     print N1
680     print "\n"
681     inc I0
682     pow N1, N0, I0
683     print N1
684     print "\n"
685     inc I0
686     pow N1, N0, I0
687     print N1
688     print "\n"
689     set I0, -1
690     pow N1, N0, I0
691     print N1
692     print "\n"
693     dec I0
694     pow N1, N0, I0
695     print N1
696     print "\n"
697     dec I0
698     pow N1, N0, I0
699     print N1
700     print "\n"
701     dec I0
702     pow N1, N0, I0
703     print N1
704     print "\n"
705     dec I0
706     pow N1, N0, I0
707     print N1
708     print "\n"
709     dec I0
710     pow N1, N0, I0
711     print N1
712     print "\n"
713     end
714 CODE
715 1.000000
716 2.000000
717 4.000000
718 8.000000
719 16.000000
720 32.000000
721 64.000000
722 0.500000
723 0.250000
724 0.125000
725 0.062500
726 0.031250
727 0.015625
728 OUTPUT
730 # Local Variables:
731 #   mode: cperl
732 #   cperl-indent-level: 4
733 #   fill-column: 100
734 # End:
735 # vim: expandtab shiftwidth=4: