1 #include this file into another test for subclass testing...
3 ok ($class->config()->{lib},$CL);
10 $_ =~ s/#.*$//; # remove comments
11 $_ =~ s/\s+$//; # trailing spaces
12 next if /^$/; # skip empty lines & comments
19 $setup = $_; $setup =~ s/\$/\$${class}::/g; # round_mode, div_scale
20 #print "\$setup== $setup\n";
27 @args = split(/:/,$1,99);
31 @args = split(/:/,$_,99); $ans = pop(@args);
33 $try = "\$x = new $class \"$args[0]\";";
37 } elsif ($f eq "finf") {
38 my $a = $args[1] || '';
39 $try .= "\$x->binf('$a');";
40 } elsif ($f eq "is_inf") {
41 $try .= "\$x->is_inf('$args[1]');";
42 } elsif ($f eq "fone") {
43 $try .= "\$x->bone('$args[1]');";
44 } elsif ($f eq "fstr") {
45 $try .= "\$x->accuracy($args[1]); \$x->precision($args[2]);";
46 $try .= '$x->bstr();';
47 } elsif ($f eq "parts") {
48 # ->bstr() to see if an object is returned
49 $try .= '($a,$b) = $x->parts(); $a = $a->bstr(); $b = $b->bstr();';
51 } elsif ($f eq "numerator") {
52 # ->bstr() to see if an object is returned
53 $try .= '$x->numerator()->bstr();';
54 } elsif ($f eq "denominator") {
55 # ->bstr() to see if an object is returned
56 $try .= '$x->denominator()->bstr();';
57 } elsif ($f =~ /^(length|numify)$/) {
59 # some unary ops (can't test the fxxx form, since no AUTOLOAD in BigRat)
60 } elsif ($f =~ /^f(nan|sstr|neg|floor|ceil|abs)$/) {
61 $try .= "\$x->b$1();";
62 # some is_xxx test function
63 } elsif ($f =~ /^is_(zero|one|pos|neg|negative|positive|odd|even|nan|int)\z/) {
65 } elsif ($f =~ /^(as_number|as_int)\z/){
67 } elsif ($f eq "finc") {
69 } elsif ($f eq "fdec") {
71 } elsif ($f eq "digit") {
72 $try .= "\$x->digit($args[1]);";
73 } elsif ($f eq "fround") {
74 $try .= "$setup; \$x->bround($args[1]);";
75 } elsif ($f eq "ffround") {
76 $try .= "$setup; \$x->bfround($args[1]);";
77 } elsif ($f eq "fsqrt") {
78 $try .= "$setup; \$x->bsqrt();";
79 } elsif ($f eq "flog") {
80 $try .= "$setup; \$x->blog();";
81 } elsif ($f eq "ffac") {
82 $try .= "$setup; \$x->bfac();";
86 $try .= "\$y = new $class \"$args[1]\";";
89 } elsif ($f eq "bacmp") {
90 $try .= '$x->bacmp($y);';
91 } elsif ($f eq "bpow") {
93 } elsif ($f eq "fpow") {
94 $try .= '$x->bpow($y);';
95 } elsif ($f eq "badd") {
97 } elsif ($f eq "bsub") {
99 } elsif ($f eq "bmul") {
101 } elsif ($f eq "bdiv") {
102 $try .= "$setup; \$x / \$y;";
103 } elsif ($f eq "fdiv-list") {
104 $try .= "$setup; join(',',\$x->bdiv(\$y));";
105 } elsif ($f eq "brsft") {
107 } elsif ($f eq "blsft") {
109 } elsif ($f eq "bmod") {
111 } elsif( $f eq "bmodinv") {
112 $try .= "\$x->bmodinv(\$y);";
113 } elsif( $f eq "blog") {
114 $try .= "\$x->blog(\$y);";
116 $try .= "\$z = $class->new(\"$args[2]\");";
118 # Functions with three arguments
119 if( $f eq "bmodpow") {
120 $try .= "\$x->bmodpow(\$y,\$z);";
121 } else { warn "Unknown op '$f'"; }
124 # print "# Trying: '$try'\n";
126 if ($ans =~ m|^/(.*)$|)
135 print "# '$try' expected: /$pat/ got: '$ans1'\n" if !ok(1,0);
146 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
147 # if (ref($ans1) eq "$class")
149 # # float numbers are normalized (for now), so mantissa shouldn't have
151 # #print $ans1->_trailing_zeros(),"\n";
152 # print "# Has trailing zeros after '$try'\n"
153 # if !ok ($ans1->{_m}->_trailing_zeros(), 0);
156 } # end pattern or string
160 # check whether $class->new( Math::BigInt->new()) destroys it
161 # ($y == 12 in this case)
162 $x = Math::BigInt->new(1200); $y = $class->new($x);
163 ok ($y,1200); ok ($x,1200);
165 ###############################################################################
168 $x = $class->new(2); $x->bzero(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
169 $x = $class->new(2); $x->binf(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
170 $x = $class->new(2); $x->bone(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
171 $x = $class->new(2); $x->bnan(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
175 ###############################################################################
176 # Perl 5.005 does not like ok ($x,undef)
182 ok (1,1) and return if !defined $x;
200 # format: number:modulus:result
201 # bmodinv Data errors
205 # bmodinv Expected Results from normal use
212 324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
213 ## bmodinv Error cases / useless use of function
236 # format: number:exponent:modulus:result
237 # bmodpow Data errors
245 # bmodpow Expected results
251 98436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
252 # bmodpow Error cases
283 # sqrt(144) / sqrt(4) = 12/2 = 6/1
350 -123.4567:-1234567/10000
374 000000_0000000_00000:0
381 +00000800/00000010:80
382 -00000800/00000010:-80
383 +00000800/-00000010:-80
384 -00000800/-00000010:80
389 -123456789:-123456789
397 -.0000000004:-1/2500000000
418 +123456789:-123456789
420 +123.456789:-123456789/1000000
421 -123456.789:123456789/1000
434 +123.456789:123456789/1000000
435 -123456.789:123456789/1000
464 +99999999:+1:100000000
465 +999999999:+1:1000000000
466 +9999999999:+1:10000000000
467 +99999999999:+1:100000000000
475 +100000000:-1:99999999
476 +1000000000:-1:999999999
477 +10000000000:-1:9999999999
478 +123456789:+987654321:1111111110
479 -123456789:+987654321:864197532
480 -123456789:-987654321:-1111111110
481 +123456789:-987654321:-864197532
512 +99999999:+1:99999998
513 +999999999:+1:999999998
514 +9999999999:+1:9999999998
515 +99999999999:+1:99999999998
522 +10000000:-1:10000001
523 +100000000:-1:100000001
524 +1000000000:-1:1000000001
525 +10000000000:-1:10000000001
526 +123456789:+987654321:-864197532
527 -123456789:+987654321:-1111111110
528 -123456789:-987654321:864197532
529 +123456789:-987654321:1111111110
561 +123456789123456789:+0:0
562 +0:+123456789123456789:0
572 +10101:+10101:102030201
573 +1001001:+1001001:1002003002001
574 +100010001:+100010001:10002000300020001
575 +10000100001:+10000100001:100002000030000200001
576 +11111111111:+9:99999999999
577 +22222222222:+9:199999999998
578 +33333333333:+9:299999999997
579 +44444444444:+9:399999999996
580 +55555555555:+9:499999999995
581 +66666666666:+9:599999999994
582 +77777777777:+9:699999999993
583 +88888888888:+9:799999999992
584 +99999999999:+9:899999999991
589 $div_scale = 40; $round_mode = 'even'
615 +999999999999:+9:111111111111
616 +999999999999:+99:10101010101
617 +999999999999:+999:1001001001
618 +999999999999:+9999:100010001
619 +999999999999999:+99999:10000100001
620 +1000000000:+9:1000000000/9
621 +2000000000:+9:2000000000/9
622 +3000000000:+9:1000000000/3
623 +4000000000:+9:4000000000/9
624 +5000000000:+9:5000000000/9
625 +6000000000:+9:2000000000/3
626 +7000000000:+9:7000000000/9
627 +8000000000:+9:8000000000/9
628 +9000000000:+9:1000000000
629 +35500000:+113:35500000/113
630 +71000000:+226:35500000/113
631 +106500000:+339:35500000/113
632 +1000000000:+3:1000000000/3
633 2:25.024996000799840031993601279744051189762:1000000000000000000000000000000000000000/12512498000399920015996800639872025594881
636 # reset scale for further tests
654 # it must be exactly /^[+-]inf$/
752 12345678901234567890:20
826 # bpow test for overload of **
836 -123456789:+987654321:-1
837 +123456789:-987654321:-1
838 +987654321:+123456789:1
839 -987654321:+123456789:1