2 # Copyright (C) 2001-2010, 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()
56 test_dot_dig_parsing()
58 test_exception_div_n_n_by_zero()
59 test_exception_div_n_nc_by_zero()
60 test_exception_div_n_n_n_by_zero()
61 test_exception_div_n_nc_n_by_zero()
62 test_exception_div_n_n_nc_by_zero()
63 test_exception_fdiv_n_n_by_zero()
64 test_exception_fdiv_n_nc_by_zero()
65 test_exception_fdiv_n_n_n_by_zero()
66 test_exception_fdiv_n_nc_n_by_zero()
67 test_exception_fdiv_n_n_nc_by_zero()
68 test_mod_n_n_n_by_zero()
69 test_mod_n_nc_n_by_zero()
70 test_mod_n_n_nc_by_zero()
74 .macro exception_is ( M )
77 .get_results (exception)
79 message = exception['message']
99 set $N15, 1073741824.0
100 set $N16, 4294967296.0
101 set $N17, 17179869184.0
102 set $N18, 68719476736.0
103 set $N19, 274877906944.0
104 set $N20, 1099511627776.0
105 set $N21, 4398046511104.0
106 set $N22, 17592186044416.0
107 set $N23, 70368744177664.0
108 set $N24, 281474976710656.0
109 set $N25, 1.12589990684262e+15
110 is( $N0, "1", 'set_n_nc' )
111 is( $N1, "4", 'set_n_nc' )
112 is( $N2, "16", 'set_n_nc' )
113 is( $N3, "64", 'set_n_nc' )
114 is( $N4, "256", 'set_n_nc' )
115 is( $N5, "1024", 'set_n_nc' )
116 is( $N6, "4096", 'set_n_nc' )
117 is( $N7, "16384", 'set_n_nc' )
118 is( $N8, "65536", 'set_n_nc' )
119 is( $N9, "262144", 'set_n_nc' )
120 is( $N10, "1048576", 'set_n_nc' )
121 is( $N11, "4194304", 'set_n_nc' )
122 is( $N12, "16777216", 'set_n_nc' )
123 is( $N13, "67108864", 'set_n_nc' )
124 is( $N14, "268435456", 'set_n_nc' )
125 is( $N15, "1073741824", 'set_n_nc' )
126 is( $N16, "4294967296", 'set_n_nc' )
127 is( $N17, "17179869184", 'set_n_nc' )
128 is( $N18, "68719476736", 'set_n_nc' )
129 is( $N19, "274877906944", 'set_n_nc' )
130 is( $N20, "1099511627776", 'set_n_nc' )
131 is( $N21, "4398046511104", 'set_n_nc' )
132 is( $N22, "17592186044416", 'set_n_nc' )
133 is( $N23, "70368744177664", 'set_n_nc' )
134 is( $N24, "281474976710656", 'set_n_nc' )
135 is( $N25, "1.12589990684262e+15", 'set_n_nc' )
141 is( $N1, "42", 'set_n' )
147 is( $N1, "2", 'add_n_n_n' )
149 is( $N2, "3", 'add_n_n_n' )
151 is( $N2, "6", 'add_n_n_n' )
157 is( $N0, "2", 'add_n_n' )
160 is( $N0, "3", 'add_n_n' )
162 is( $N0, "6", 'add_n_n' )
169 is( $N2, "420042", 'sub_n_n_n' )
176 is( $N0, "420042", 'sub_n_n' )
178 is( $N0, "0", 'sub_n_n' )
181 .sub test_abs_n_i_ic_n_nc
194 is( $N0, "1", 'abs(n, i|ic|n|nc)' )
195 is( $N1, "1", 'abs(n, i|ic|n|nc)' )
196 is( $N2, "1", 'abs(n, i|ic|n|nc)' )
197 is( $N3, "1", 'abs(n, i|ic|n|nc)' )
198 is( $N4, "1", 'abs(n, i|ic|n|nc)' )
199 is( $N5, "1", 'abs(n, i|ic|n|nc)' )
200 is( $N6, "1", 'abs(n, i|ic|n|nc)' )
201 is( $N7, "1", 'abs(n, i|ic|n|nc)' )
213 is( $N1, "256", 'mul_i' )
220 is( $N2, "5", 'div_i' )
224 is( $N3, "3.5", 'div_i' )
228 is( $N7, "-2.25", 'div_i' )
235 is( $N2, "5", 'mod_n' )
239 is( $N2, "0", 'mod_n' )
243 is( $N2, "2", 'mod_n' )
247 is( $N2, "-1", 'mod_n' )
251 is( $N2, "1", 'mod_n' )
255 is( $N2, "-2", 'mod_n' )
264 ok( 0, 'test eq_n_ic bad' )
266 ok( 1, 'eq_n_ic ok 1')
269 ok( 0, 'eq_n_ic bad 1' )
271 ok( 1, 'eq_n_ic ok 2')
274 ok( 0, 'eq_n_ic bad 2' )
284 ok( 1, 'eq_nc_ic ok 1')
285 eq $N0, 1.000001, TWO
289 ok( 1, 'eq_nc_ic ok 2')
304 ok( 1, 'ne_n_ic ok 1')
309 ok( 1, 'ne_n_ic ok 2')
317 set $N0, 1073741824.0
318 ne $N0, 1073741824.0, nok1
319 ok( 1, 'ne_n_nc_ic ok 1')
327 ok( 1, 'ne_n_nc_ic ok 2')
343 ok( 1, 'lt_n_ic ok 1')
348 ok( 1, 'lt_n_ic ok 2')
353 ok( 1, 'lt_n_ic ok 3')
368 ok( 1, 'lt_nc_ic ok 1')
373 ok( 1, 'lt_nc_ic ok 2')
378 ok( 1, 'lt_nc_ic ok 3')
394 ok( 1, 'le_n_ic ok 1')
399 ok( 1, 'le_n_ic ok 2')
404 ok( 1, 'le_n_ic ok 3')
419 ok( 1, 'le_nc_ic ok 1')
424 ok( 1, 'le_nc_ic ok 2')
429 ok( 1, 'le_nc_ic ok 3')
445 ok( 1, 'gt_n_ic ok 1')
450 ok( 1, 'gt_n_ic ok 2')
455 ok( 1, 'gt_n_ic ok 3')
466 gt $N0, 1000.0, ERROR
470 ok( 1, 'gt_nc_ic ok 1')
475 ok( 1, 'gt_nc_ic ok 2')
480 ok( 1, 'gt_nc_ic ok 3')
496 ok( 1, 'ge_n_ic ok 1')
501 ok( 1, 'ge_n_ic ok 2')
506 ok( 1, 'ge_n_ic ok 3')
517 ge $N0, 1000.0, ERROR
521 ok( 1, 'ge_nc_ic ok 1')
526 ok( 1, 'ge_nc_ic ok 2')
531 ok( 1, 'ge_nc_ic ok 3')
546 ok( 1, 'if_n_ic ok 1')
551 ok( 1, 'if_n_ic ok 2')
556 ok( 1, 'if_n_ic ok 3')
566 is( $N0, "1", 'inc_n' )
571 is( $N0, "5", 'inc_n' )
577 is( $N0, "-1", 'dec_n' )
582 is( $N0, "-5", 'dec_n' )
588 is( $I0, "0", 'set_i_n' )
589 set $N1, 2147483647.0
591 is( $I1, "2147483647", 'set_i_n' )
592 set $N2, -2147483648.0
594 is( $I2, "-2147483648", 'set_i_n' )
601 is( $N0, "-3", 'neg_n' )
604 .sub test_neg_0_dot_0
605 load_bytecode 'config.pbc'
607 $P2 = $P1['has_negative_zero']
608 unless $P2 goto negative_zero_todoed
612 is( $N1, "-0", 'neg 0.0' )
615 negative_zero_todoed:
616 todo(0, '-0.0 not implemented, TT #313')
623 is( $N0, "12", 'mul_n_n' )
628 is( $N1, "5", 'op_n_nc_nc' )
630 is( $N1, "-2", 'op_n_nc_nc' )
633 .sub test_lt_nc_nc_ic
635 ok( 1, 'lt_nc_nc_ic ok 1')
638 ok( 0, 'lt_nc_nc_ic')
641 ok( 1, 'lt_nc_nc_ic ok 2')
645 .sub test_string_gt_num
656 is( $N0, "1", 'string -> num' )
657 is( $N1, "12", 'string -> num' )
658 is( $N2, "-2.45", 'string -> num' )
659 is( $N3, "2500", 'string -> num' )
660 is( $N4, "0", 'string -> num' )
665 is( $N31, "12.5", 'null' )
667 is( $N31, "0", 'null' )
670 .sub test_dot_dig_parsing
672 is( $N0, "0.5", '.dig parsing' )
675 # Don't check exact string representation. Last digit part can be different */
681 is( $P0, 1.414213562373, 'sqrt_n_n',1e-6 )
685 is( $P0, 1.414213562373, 'sqrt_n_n',1e-6 )
688 .sub test_exception_div_n_n_by_zero
694 .exception_is( 'Divide by zero' )
697 .sub test_exception_div_n_nc_by_zero
702 .exception_is( 'Divide by zero' )
705 .sub test_exception_div_n_n_n_by_zero
711 .exception_is( 'Divide by zero' )
714 .sub test_exception_div_n_nc_n_by_zero
719 .exception_is( 'Divide by zero' )
722 .sub test_exception_div_n_n_nc_by_zero
727 .exception_is( 'Divide by zero' )
730 .sub test_exception_fdiv_n_n_by_zero
736 .exception_is( 'Divide by zero' )
739 .sub test_exception_fdiv_n_nc_by_zero
744 .exception_is( 'Divide by zero' )
747 .sub test_exception_fdiv_n_n_n_by_zero
753 .exception_is( 'Divide by zero' )
756 .sub test_exception_fdiv_n_nc_n_by_zero
761 .exception_is( 'Divide by zero' )
764 .sub test_exception_fdiv_n_n_nc_by_zero
769 .exception_is( 'Divide by zero' )
772 .sub test_mod_n_n_n_by_zero
776 is( $N2, "10", 'mod_n_n_n by zero' )
779 .sub test_mod_n_nc_n_by_zero
782 is( $N2, 10, 'mod_n_nc_n by zero' )
785 .sub test_mod_n_n_nc_by_zero
788 is( $N2, '10', 'mod_n_n_nc by zero' )
795 # vim: expandtab shiftwidth=4 ft=pir: