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|negative|positive|odd|even|nan|int)$/) {
65 } elsif ($f eq "as_number") {
66 $try .= '$x->as_number();';
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
225 # format: number:exponent:modulus:result
226 # bmodpow Data errors
234 # bmodpow Expected results
240 98436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
241 # bmodpow Error cases
272 # sqrt(144) / sqrt(4) = 12/2 = 6/1
339 -123.4567:-1234567/10000
363 000000_0000000_00000:0
370 +00000800/00000010:80
371 -00000800/00000010:-80
372 +00000800/-00000010:-80
373 -00000800/-00000010:80
378 -123456789:-123456789
386 -.0000000004:-1/2500000000
407 +123456789:-123456789
409 +123.456789:-123456789/1000000
410 -123456.789:123456789/1000
420 +123.456789:123456789/1000000
421 -123456.789:123456789/1000
450 +99999999:+1:100000000
451 +999999999:+1:1000000000
452 +9999999999:+1:10000000000
453 +99999999999:+1:100000000000
461 +100000000:-1:99999999
462 +1000000000:-1:999999999
463 +10000000000:-1:9999999999
464 +123456789:+987654321:1111111110
465 -123456789:+987654321:864197532
466 -123456789:-987654321:-1111111110
467 +123456789:-987654321:-864197532
498 +99999999:+1:99999998
499 +999999999:+1:999999998
500 +9999999999:+1:9999999998
501 +99999999999:+1:99999999998
508 +10000000:-1:10000001
509 +100000000:-1:100000001
510 +1000000000:-1:1000000001
511 +10000000000:-1:10000000001
512 +123456789:+987654321:-864197532
513 -123456789:+987654321:-1111111110
514 -123456789:-987654321:864197532
515 +123456789:-987654321:1111111110
547 +123456789123456789:+0:0
548 +0:+123456789123456789:0
558 +10101:+10101:102030201
559 +1001001:+1001001:1002003002001
560 +100010001:+100010001:10002000300020001
561 +10000100001:+10000100001:100002000030000200001
562 +11111111111:+9:99999999999
563 +22222222222:+9:199999999998
564 +33333333333:+9:299999999997
565 +44444444444:+9:399999999996
566 +55555555555:+9:499999999995
567 +66666666666:+9:599999999994
568 +77777777777:+9:699999999993
569 +88888888888:+9:799999999992
570 +99999999999:+9:899999999991
575 $div_scale = 40; $round_mode = 'even'
601 +999999999999:+9:111111111111
602 +999999999999:+99:10101010101
603 +999999999999:+999:1001001001
604 +999999999999:+9999:100010001
605 +999999999999999:+99999:10000100001
606 +1000000000:+9:1000000000/9
607 +2000000000:+9:2000000000/9
608 +3000000000:+9:1000000000/3
609 +4000000000:+9:4000000000/9
610 +5000000000:+9:5000000000/9
611 +6000000000:+9:2000000000/3
612 +7000000000:+9:7000000000/9
613 +8000000000:+9:8000000000/9
614 +9000000000:+9:1000000000
615 +35500000:+113:35500000/113
616 +71000000:+226:35500000/113
617 +106500000:+339:35500000/113
618 +1000000000:+3:1000000000/3
619 2:25.024996000799840031993601279744051189762:1000000000000000000000000000000000000000/12512498000399920015996800639872025594881
622 # reset scale for further tests
640 # it must be exactly /^[+-]inf$/
722 12345678901234567890:20
796 # bpow test for overload of **
806 -123456789:+987654321:-1
807 +123456789:-987654321:-1
808 +987654321:+123456789:1
809 -987654321:+123456789:1