2 # Copyright (C) 2009, Parrot Foundation.
7 use lib qw( . lib ../lib ../../lib );
15 t/pmc/bignum.t - BigNum PMC
19 % prove t/pmc/bignum.t
27 if ( $PConfig{gmp} ) {
31 plan skip_all => "No BigNum PMC enabled";
34 my $vers_check = <<'EOP';
49 say " is buggy with huge digit multiply - please upgrade"
62 if ( $PConfig{gmp} ) {
65 my $parrot = '.' . $PConfig{slash} . 'parrot' . $PConfig{exe};
66 my $test = 'temp_gmp_vers.pir';
67 open my $O, '>', "$test" or die "can't open $test: $!";
70 my $warn = `$parrot $test`;
75 pasm_output_is( <<'CODE', <<'OUT', "create" );
83 pasm_output_is( <<'CODE', <<'OUT', "set/get int" );
96 pasm_output_is( <<"CODE", <<'OUT', "set int, get double" );
97 .include 'fp_equality.pasm'
101 .fp_eq_pasm(N1, 999999.0, OK1)
107 .fp_eq_pasm(N1, -999999.0, OK2)
113 .fp_eq_pasm(N1, 2.147483646e9, OK3)
119 .fp_eq_pasm(N1, -2.147483646e9, OK4)
130 my @todo_str = ( todo => "bignum strings");
131 pasm_output_is( <<'CODE', <<'OUT', "set double, get str", @todo_str );
135 set P0, "1230000000000.0000000000000000122"
140 1230000000000.0000000000000000122
143 pasm_output_is( <<'CODE', <<'OUT', "add", @todo_str);
152 set P0, "12345678987654321"
153 set P1, "10000000000000000"
163 pasm_output_is( <<'CODE', <<'OUT', "add_int", @todo_str );
170 set P0, "100000000000000000000.01"
177 100000000000001000000.01
180 pasm_output_is( <<'CODE', <<'OUTPUT', "sub bignum" );
191 set P0, "123456789012345678"
194 set P3, "123456789012340000"
198 set P1, "223456789012345678"
200 set P3, "-100000000000000000"
211 pasm_output_is( <<'CODE', <<'OUTPUT', "sub native int" );
220 set P0, "123456789012345678"
223 set P3, "123456789012340000"
233 pasm_output_is( <<'CODE', <<'OUTPUT', "sub other int" );
244 set P0, "123456789012345678"
247 set P3, "123456789012340000"
259 set P0, "9876543219876543"
261 set P3, "9876543219876499"
273 pasm_output_is( <<'CODE', <<'OUT', "mul", @todo_str );
287 pasm_output_is( <<'CODE', <<'OUT', "mul_float", @todo_str);
290 mul P2, P0, 10.000005
297 pasm_output_is( <<'CODE', <<'OUT', "div bignum" );
299 set P0, "100000000000000000000"
301 set P1, "100000000000000000000"
310 set P3, "10000000000000"
318 set P3, "10000000000000000000"
325 set P3, "-100000000000000000000"
338 pasm_output_is( <<'CODE', <<'OUT', "div native int" );
340 set P0, "100000000000000000000"
344 set P2, "10000000000000000000"
349 set P0, "100000000000000"
361 pasm_output_is( <<'CODE', <<'OUT', "div other int" );
363 set P0, "100000000000000000000"
369 set P2, "10000000000000000000"
374 set P0, "100000000000000"
388 pasm_output_is( <<'CODE', <<'OUT', "div float" );
390 set P0, "100000000000000000000"
394 set P2, "10000000000000000000"
399 set P0, "100000000000000"
401 set P2, "-10000000000000"
411 my @todo_sig = ( todo => "missing signature" );
412 for my $op ( "/", "%" ) {
413 for my $type ( "BigNum", "BigInt", "Integer" ) {
414 pir_output_is( <<"CODE", <<OUTPUT, "bignum $op by zero $type", ($op eq '/' and $type ne 'BigInt') ? () : @todo_sig );
416 \$P0 = new ['BigNum']
417 set \$P0, "1000000000000000000000.123"
418 \$P1 = new ['BigNum']
419 ## divide by a zero $type
427 get_results '0', \$P0
440 my ( $a, $b, $c, $d, $e );
441 if ( $PConfig{intvalsize} == 8 ) {
442 $a = '9223372036854775806'; # 2**63-2
444 $c = '9223372036854775807'; # still Integer
445 $d = '9223372036854775808'; # no more Integer
446 $e = '9223372036854775809'; # still no more Integer
448 elsif ( $PConfig{intvalsize} == 4 ) {
449 $a = '2147483646'; # 2**31-2
451 $c = '2147483647'; # still Integer
452 $d = '2147483648'; # no more PerlInt
453 $e = '2147483649'; # still no more PerlInt
456 die "\$PConfig{intvalsize} == $PConfig{intvalsize}?\n";
459 pasm_output_is( <<CODE, <<OUT, "add overflow Integer" );
487 pasm_output_is( <<CODE, <<OUT, "add overflow Integer" );
516 pasm_output_is( <<'CODE', <<'OUT', "abs", @todo_str );
518 set P0, "-1230000000000"
532 pir_output_is( << 'CODE', << 'OUTPUT', "check whether interface is done" );
536 pmc1 = new ['BigNum']
538 does bool1, pmc1, "scalar"
540 does bool1, pmc1, "no_interface"
549 pasm_output_is( <<"CODE", <<'OUTPUT', "Truth" );
551 set P0, "123456789123456789"
565 pasm_output_is( <<"CODE", <<'OUTPUT', "neg" );
568 set P0, "123456789123456789"
570 set P1, "-123456789123456789"
579 pir_output_is( <<'CODE', <<'OUT', "BUG #34949 gt" );
594 pir_output_is( <<'CODE', <<'OUT', "BUG #34949 ge" );
609 pir_output_is( <<'CODE', <<'OUT', "BUG #34949 ne" );
624 pir_output_is( <<'CODE', <<'OUT', "BUG #34949 eq" );
639 pir_output_is( <<'CODE', <<'OUT', "BUG #34949 le" );
654 pir_output_is( <<'CODE', <<'OUT', "BUG #34949 lt" );
671 # cperl-indent-level: 4
674 # vim: expandtab shiftwidth=4: