2 # Copyright (C) 2001-2009, Parrot Foundation.
7 t/op/number.t - Number Registers
15 Tests the use of Parrot floating-point number registers.
20 .include 'test_more.pir'
29 test_abs_n_i_ic_n_nc()
61 test_dot_dig_parsing()
63 test_exception_div_n_n_by_zero()
64 test_exception_div_n_nc_by_zero()
65 test_exception_div_n_n_n_by_zero()
66 test_exception_div_n_nc_n_by_zero()
67 test_exception_div_n_n_nc_by_zero()
68 test_exception_fdiv_n_n_by_zero()
69 test_exception_fdiv_n_nc_by_zero()
70 test_exception_fdiv_n_n_n_by_zero()
71 test_exception_fdiv_n_nc_n_by_zero()
72 test_exception_fdiv_n_n_nc_by_zero()
73 test_exception_cmod_n_n_n_by_zero()
74 test_exception_cmod_n_nc_n_by_zero()
75 test_exception_cmod_n_n_nc_by_zero()
76 test_mod_n_n_n_by_zero()
77 test_mod_n_nc_n_by_zero()
78 test_mod_n_n_nc_by_zero()
82 .macro exception_is ( M )
85 .get_results (exception)
87 message = exception['message']
106 set $N14, 268435456.0
107 set $N15, 1073741824.0
108 set $N16, 4294967296.0
109 set $N17, 17179869184.0
110 set $N18, 68719476736.0
111 set $N19, 274877906944.0
112 set $N20, 1099511627776.0
113 set $N21, 4398046511104.0
114 set $N22, 17592186044416.0
115 set $N23, 70368744177664.0
116 set $N24, 281474976710656.0
117 set $N25, 1.12589990684262e+15
118 is( $N0, "1", 'set_n_nc' )
119 is( $N1, "4", 'set_n_nc' )
120 is( $N2, "16", 'set_n_nc' )
121 is( $N3, "64", 'set_n_nc' )
122 is( $N4, "256", 'set_n_nc' )
123 is( $N5, "1024", 'set_n_nc' )
124 is( $N6, "4096", 'set_n_nc' )
125 is( $N7, "16384", 'set_n_nc' )
126 is( $N8, "65536", 'set_n_nc' )
127 is( $N9, "262144", 'set_n_nc' )
128 is( $N10, "1048576", 'set_n_nc' )
129 is( $N11, "4194304", 'set_n_nc' )
130 is( $N12, "16777216", 'set_n_nc' )
131 is( $N13, "67108864", 'set_n_nc' )
132 is( $N14, "268435456", 'set_n_nc' )
133 is( $N15, "1073741824", 'set_n_nc' )
134 is( $N16, "4294967296", 'set_n_nc' )
135 is( $N17, "17179869184", 'set_n_nc' )
136 is( $N18, "68719476736", 'set_n_nc' )
137 is( $N19, "274877906944", 'set_n_nc' )
138 is( $N20, "1099511627776", 'set_n_nc' )
139 is( $N21, "4398046511104", 'set_n_nc' )
140 is( $N22, "17592186044416", 'set_n_nc' )
141 is( $N23, "70368744177664", 'set_n_nc' )
142 is( $N24, "281474976710656", 'set_n_nc' )
143 is( $N25, "1.12589990684262e+15", 'set_n_nc' )
149 is( $N1, "42", 'set_n' )
155 is( $N1, "2", 'add_n_n_n' )
157 is( $N2, "3", 'add_n_n_n' )
159 is( $N2, "6", 'add_n_n_n' )
165 is( $N0, "2", 'add_n_n' )
168 is( $N0, "3", 'add_n_n' )
170 is( $N0, "6", 'add_n_n' )
177 is( $N2, "420042", 'sub_n_n_n' )
184 is( $N0, "420042", 'sub_n_n' )
186 is( $N0, "0", 'sub_n_n' )
189 .sub test_abs_n_i_ic_n_nc
202 is( $N0, "1", 'abs(n, i|ic|n|nc)' )
203 is( $N1, "1", 'abs(n, i|ic|n|nc)' )
204 is( $N2, "1", 'abs(n, i|ic|n|nc)' )
205 is( $N3, "1", 'abs(n, i|ic|n|nc)' )
206 is( $N4, "1", 'abs(n, i|ic|n|nc)' )
207 is( $N5, "1", 'abs(n, i|ic|n|nc)' )
208 is( $N6, "1", 'abs(n, i|ic|n|nc)' )
209 is( $N7, "1", 'abs(n, i|ic|n|nc)' )
221 is( $N1, "256", 'mul_i' )
228 is( $N2, "5", 'div_i' )
232 is( $N3, "3.5", 'div_i' )
236 is( $N7, "-2.25", 'div_i' )
243 is( $N2, "5", 'mod_n' )
247 is( $N2, "0", 'mod_n' )
251 is( $N2, "2", 'mod_n' )
255 is( $N2, "-1", 'mod_n' )
259 is( $N2, "1", 'mod_n' )
263 is( $N2, "-2", 'mod_n' )
270 is( $N2, "2", 'cmod_n' )
279 ok( 0, 'test eq_n_ic bad' )
281 ok( 1, 'eq_n_ic ok 1')
284 ok( 0, 'eq_n_ic bad 1' )
286 ok( 1, 'eq_n_ic ok 2')
289 ok( 0, 'eq_n_ic bad 2' )
299 ok( 1, 'eq_nc_ic ok 1')
300 eq $N0, 1.000001, TWO
304 ok( 1, 'eq_nc_ic ok 2')
319 ok( 1, 'ne_n_ic ok 1')
324 ok( 1, 'ne_n_ic ok 2')
332 set $N0, 1073741824.0
333 ne $N0, 1073741824.0, nok1
334 ok( 1, 'ne_n_nc_ic ok 1')
342 ok( 1, 'ne_n_nc_ic ok 2')
358 ok( 1, 'lt_n_ic ok 1')
363 ok( 1, 'lt_n_ic ok 2')
368 ok( 1, 'lt_n_ic ok 3')
383 ok( 1, 'lt_nc_ic ok 1')
388 ok( 1, 'lt_nc_ic ok 2')
393 ok( 1, 'lt_nc_ic ok 3')
409 ok( 1, 'le_n_ic ok 1')
414 ok( 1, 'le_n_ic ok 2')
419 ok( 1, 'le_n_ic ok 3')
434 ok( 1, 'le_nc_ic ok 1')
439 ok( 1, 'le_nc_ic ok 2')
444 ok( 1, 'le_nc_ic ok 3')
460 ok( 1, 'gt_n_ic ok 1')
465 ok( 1, 'gt_n_ic ok 2')
470 ok( 1, 'gt_n_ic ok 3')
481 gt $N0, 1000.0, ERROR
485 ok( 1, 'gt_nc_ic ok 1')
490 ok( 1, 'gt_nc_ic ok 2')
495 ok( 1, 'gt_nc_ic ok 3')
511 ok( 1, 'ge_n_ic ok 1')
516 ok( 1, 'ge_n_ic ok 2')
521 ok( 1, 'ge_n_ic ok 3')
532 ge $N0, 1000.0, ERROR
536 ok( 1, 'ge_nc_ic ok 1')
541 ok( 1, 'ge_nc_ic ok 2')
546 ok( 1, 'ge_nc_ic ok 3')
561 ok( 1, 'if_n_ic ok 1')
566 ok( 1, 'if_n_ic ok 2')
571 ok( 1, 'if_n_ic ok 3')
581 is( $N0, "1", 'inc_n' )
586 is( $N0, "5", 'inc_n' )
592 is( $N0, "-1", 'dec_n' )
597 is( $N0, "-5", 'dec_n' )
603 is( $I0, "0", 'set_i_n' )
604 set $N1, 2147483647.0
606 is( $I1, "2147483647", 'set_i_n' )
607 set $N2, -2147483648.0
609 is( $I2, "-2147483648", 'set_i_n' )
646 is( $N0, "0", 'clearn' )
647 is( $N1, "0", 'clearn' )
648 is( $N2, "0", 'clearn' )
649 is( $N3, "0", 'clearn' )
650 is( $N4, "0", 'clearn' )
651 is( $N5, "0", 'clearn' )
652 is( $N6, "0", 'clearn' )
653 is( $N7, "0", 'clearn' )
654 is( $N8, "0", 'clearn' )
655 is( $N9, "0", 'clearn' )
656 is( $N10, "0", 'clearn' )
657 is( $N11, "0", 'clearn' )
658 is( $N12, "0", 'clearn' )
659 is( $N13, "0", 'clearn' )
660 is( $N14, "0", 'clearn' )
661 is( $N15, "0", 'clearn' )
662 is( $N16, "0", 'clearn' )
663 is( $N17, "0", 'clearn' )
664 is( $N18, "0", 'clearn' )
665 is( $N19, "0", 'clearn' )
666 is( $N20, "0", 'clearn' )
667 is( $N21, "0", 'clearn' )
668 is( $N22, "0", 'clearn' )
669 is( $N23, "0", 'clearn' )
670 is( $N24, "0", 'clearn' )
671 is( $N25, "0", 'clearn' )
672 is( $N26, "0", 'clearn' )
673 is( $N27, "0", 'clearn' )
674 is( $N28, "0", 'clearn' )
675 is( $N29, "0", 'clearn' )
676 is( $N30, "0", 'clearn' )
677 is( $N31, "0", 'clearn' )
684 is( $N0, "-3", 'neg_n' )
687 .sub test_neg_0_dot_0
688 load_bytecode 'config.pbc'
690 $P2 = $P1['has_negative_zero']
691 unless $P2 goto negative_zero_todoed
695 is( $N1, "-0", 'neg 0.0' )
698 negative_zero_todoed:
699 todo(0, '-0.0 not implemented, TT #313')
706 is( $N0, "12", 'mul_n_n' )
715 is( $N5, "6", 'fact_n_i' )
717 is( $N6, "39916800", 'fact_n_i' )
719 is( $N7, "1", 'fact_n_i' )
721 is( $N8, "1", 'fact_n_i' )
726 is( $N5, "6", 'fact_n_ic' )
728 is( $N6, "39916800", 'fact_n_ic' )
730 is( $N7, "1", 'fact_n_ic' )
732 is( $N8, "1", 'fact_n_ic' )
739 is( $N1, "9.87654", 'exchange' )
740 is( $N2, "1.23456", 'exchange' )
743 is( $N3, "-100.2003", 'exchange' )
748 is( $N1, "5", 'op_n_nc_nc' )
750 is( $N1, "-2", 'op_n_nc_nc' )
753 .sub test_lt_nc_nc_ic
755 ok( 1, 'lt_nc_nc_ic ok 1')
758 ok( 0, 'lt_nc_nc_ic')
761 ok( 1, 'lt_nc_nc_ic ok 2')
765 .sub test_string_gt_num
776 is( $N0, "1", 'string -> num' )
777 is( $N1, "12", 'string -> num' )
778 is( $N2, "-2.45", 'string -> num' )
779 is( $N3, "2500", 'string -> num' )
780 is( $N4, "0", 'string -> num' )
785 is( $N31, "12.5", 'null' )
787 is( $N31, "0", 'null' )
790 .sub test_dot_dig_parsing
792 is( $N0, "0.5", '.dig parsing' )
795 # Don't check exact string representation. Last digit part can be different */
801 is( $P0, 1.414213562373, 'sqrt_n_n',1e-6 )
805 is( $P0, 1.414213562373, 'sqrt_n_n',1e-6 )
808 .sub test_exception_div_n_n_by_zero
814 .exception_is( 'Divide by zero' )
817 .sub test_exception_div_n_nc_by_zero
822 .exception_is( 'Divide by zero' )
825 .sub test_exception_div_n_n_n_by_zero
831 .exception_is( 'Divide by zero' )
834 .sub test_exception_div_n_nc_n_by_zero
839 .exception_is( 'Divide by zero' )
842 .sub test_exception_div_n_n_nc_by_zero
847 .exception_is( 'Divide by zero' )
850 .sub test_exception_fdiv_n_n_by_zero
856 .exception_is( 'Divide by zero' )
859 .sub test_exception_fdiv_n_nc_by_zero
864 .exception_is( 'Divide by zero' )
867 .sub test_exception_fdiv_n_n_n_by_zero
873 .exception_is( 'Divide by zero' )
876 .sub test_exception_fdiv_n_nc_n_by_zero
881 .exception_is( 'Divide by zero' )
884 .sub test_exception_fdiv_n_n_nc_by_zero
889 .exception_is( 'Divide by zero' )
892 .sub test_exception_cmod_n_n_n_by_zero
898 .exception_is( 'Divide by zero' )
901 .sub test_exception_cmod_n_nc_n_by_zero
906 .exception_is( 'Divide by zero' )
909 .sub test_exception_cmod_n_n_nc_by_zero
914 .exception_is( 'Divide by zero' )
917 .sub test_mod_n_n_n_by_zero
921 is( $N2, "10", 'mod_n_n_n by zero' )
924 .sub test_mod_n_nc_n_by_zero
927 is( $N2, 10, 'mod_n_nc_n by zero' )
930 .sub test_mod_n_n_nc_by_zero
933 is( $N2, '10', 'mod_n_n_nc by zero' )
938 # cperl-indent-level: 4
941 # vim: expandtab shiftwidth=4 ft=pir: