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 $try .= "\$x->finf('$args[1]');";
39 } elsif ($f eq "is_inf") {
40 $try .= "\$x->is_inf('$args[1]');";
41 } elsif ($f eq "fone") {
42 $try .= "\$x->bone('$args[1]');";
43 } elsif ($f eq "fstr") {
44 $try .= "\$x->accuracy($args[1]); \$x->precision($args[2]);";
45 $try .= '$x->fstr();';
46 } elsif ($f eq "parts") {
47 # ->bstr() to see if an object is returned
48 $try .= '($a,$b) = $x->parts(); $a = $a->bstr(); $b = $b->bstr();';
50 } elsif ($f eq "exponent") {
51 # ->bstr() to see if an object is returned
52 $try .= '$x->exponent()->bstr();';
53 } elsif ($f eq "mantissa") {
54 # ->bstr() to see if an object is returned
55 $try .= '$x->mantissa()->bstr();';
56 } elsif ($f =~ /^(numify|length|as_number|as_hex|as_bin)$/) {
58 # some unary ops (test the fxxx form, since that is done by AUTOLOAD)
59 } elsif ($f =~ /^f(nan|sstr|neg|floor|ceil|abs)$/) {
60 $try .= "\$x->f$1();";
61 # some is_xxx test function
62 } elsif ($f =~ /^is_(zero|one|negative|positive|odd|even|nan|int)$/) {
64 } elsif ($f eq "finc") {
66 } elsif ($f eq "fdec") {
68 }elsif ($f eq "fround") {
69 $try .= "$setup; \$x->fround($args[1]);";
70 } elsif ($f eq "ffround") {
71 $try .= "$setup; \$x->ffround($args[1]);";
72 } elsif ($f eq "fsqrt") {
73 $try .= "$setup; \$x->fsqrt();";
74 } elsif ($f eq "flog") {
75 $try .= "$setup; \$x->flog();";
76 } elsif ($f eq "ffac") {
77 $try .= "$setup; \$x->ffac();";
81 $try .= "\$y = new $class \"$args[1]\";";
84 } elsif ($f eq "facmp") {
85 $try .= '$x->facmp($y);';
86 } elsif ($f eq "fpow") {
88 } elsif ($f eq "fadd") {
90 } elsif ($f eq "fsub") {
92 } elsif ($f eq "fmul") {
94 } elsif ($f eq "fdiv") {
95 $try .= "$setup; \$x / \$y;";
96 } elsif ($f eq "fdiv-list") {
97 $try .= "$setup; join(',',\$x->fdiv(\$y));";
98 } elsif ($f eq "frsft") {
100 } elsif ($f eq "flsft") {
102 } elsif ($f eq "fmod") {
104 } else { warn "Unknown op '$f'"; }
106 # print "# Trying: '$try'\n";
108 if ($ans =~ m|^/(.*)$|)
117 print "# '$try' expected: /$pat/ got: '$ans1'\n" if !ok(1,0);
128 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
129 if (ref($ans1) eq "$class")
131 # float numbers are normalized (for now), so mantissa shouldn't have
133 #print $ans1->_trailing_zeros(),"\n";
134 print "# Has trailing zeros after '$try'\n"
135 if !ok ($ans1->{_m}->_trailing_zeros(), 0);
138 } # end pattern or string
142 # check whether $class->new( Math::BigInt->new()) destroys it
143 # ($y == 12 in this case)
144 $x = Math::BigInt->new(1200); $y = $class->new($x);
145 ok ($y,1200); ok ($x,1200);
147 ###############################################################################
148 # Really huge, big, ultra-mega-biggy-monster exponents
149 # Technically, the exponents should not be limited (they are BigInts), but
150 # practically there are a few places were they are limited to a Perl scalar.
151 # This is sometimes for speed, sometimes because otherwise the number wouldn't
152 # fit into your memory (just think of 1e123456789012345678901234567890 + 1!)
153 # anyway. We don't test everything here, but let's make sure it just basically
156 my $monster = '1e1234567890123456789012345678901234567890';
159 ok ($class->new($monster)->bsstr(),
160 '1e+1234567890123456789012345678901234567890');
162 ok ($class->new($monster) > 0,1);
165 ok ($class->new($monster)->bsub( $monster),0);
166 ok ($class->new($monster)->bmul(2)->bsstr(),
167 '2e+1234567890123456789012345678901234567890');
169 ###############################################################################
172 $x = $class->new(2); $x->fzero(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
173 $x = $class->new(2); $x->finf(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
174 $x = $class->new(2); $x->fone(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
175 $x = $class->new(2); $x->fnan(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
177 ###############################################################################
178 # bone/binf etc as plain calls (Lite failed them)
180 ok ($class->fzero(),0);
181 ok ($class->fone(),1);
182 ok ($class->fone('+'),1);
183 ok ($class->fone('-'),-1);
184 ok ($class->fnan(),'NaN');
185 ok ($class->finf(),'inf');
186 ok ($class->finf('+'),'inf');
187 ok ($class->finf('-'),'-inf');
188 ok ($class->finf('-inf'),'-inf');
190 $class->accuracy(undef); $class->precision(undef); # reset
192 ###############################################################################
193 # bug in bsstr()/numify() showed up in after-rounding in bdiv()
195 $x = $class->new('0.008'); $y = $class->new(2);
199 ###############################################################################
200 # fsqrt() with set global A/P or A/P enabled on $x, also a test whether fsqrt()
201 # correctly modifies $x
204 $x = $class->new(12); $class->precision(-2); $x->fsqrt(); ok ($x,'3.46');
206 $class->precision(undef);
207 $x = $class->new(12); $class->precision(0); $x->fsqrt(); ok ($x,'3');
209 $class->precision(-3); $x = $class->new(12); $x->fsqrt(); ok ($x,'3.464');
214 ${${class}.'::accuracy'} = 4; $x = $class->new(12);
215 $x->fsqrt(3); ok ($x,'NaN');
216 # supplied arg overrides set global
217 $class->precision(undef); $x = $class->new(12); $x->fsqrt(3); ok ($x,'3.46');
218 $class->accuracy(undef); $class->precision(undef); # reset for further tests
221 #############################################################################
222 # can we call objectify (broken until v1.52)
227 '@args' . " = $class" . "::objectify(2,$class,4,5);".'join(" ",@args);';
229 ok ($ans,"$class 4 5");
234 ###############################################################################
235 # Perl 5.005 does not like ok ($x,undef)
241 ok (1,1) and return if !defined $x;
252 # this is too slow for the testsuite
253 #2:0.6931471805599453094172321214581765680755
254 #2.718281828:0.9999999998311266953289851340574956564911
256 #2.718281828:0.99999999983112669533
257 # too slow, too (or hangs?)
261 #1000:0:6.90775527898214
262 #100:0:4.60517018598809
264 #3.1415:0:1.14470039286086
265 #12345:0:9.42100640177928
266 #0.001:0:-6.90775527898214
267 # reset for further tests
309 # test for bug in brsft() not handling cases that return 0
349 # uses bsstr() so 5 => 5e+0 to be compatible w/ Perls output
386 1234.567:9::1234.56700
387 1234.567::-6:1234.567000
389 0.001234:6::0.00123400
390 0.001234::-8:0.00123400
409 000000_0000000_00000:0
420 -123456789:-123456789
428 -.0000000004:-0.0000000004
443 -3e111:-3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
444 -4e-1111:-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004
451 123.456:2:15241.383936
454 128:-2:0.00006103515625
461 # 2 ** 0.5 == sqrt(2)
462 # 1.41..7 and not 1.4170 since fallback (bsqrt(9) is '3', not 3.0...0)
463 2:0.5:1.41421356237309504880168872420969807857
464 #2:0.2:1.148698354997035006798626946777927589444
465 #6:1.5:14.6969384566990685891837044482353483518
467 #62.5:12.5:26447206647554886213592.3959144
476 +123456789:-123456789
478 +123.456789:-123.456789
479 -123456.789:123456.789
489 +123.456789:123.456789
490 -123456.789:123456.789
492 $round_mode = "trunc"
497 +10123456789:5:10123000000
498 -10123456789:5:-10123000000
499 +10123456789.123:5:10123000000
500 -10123456789.123:5:-10123000000
501 +10123456789:9:10123456700
502 -10123456789:9:-10123456700
503 +101234500:6:101234000
504 -101234500:6:-101234000
506 +20123456789:5:20123000000
507 -20123456789:5:-20123000000
508 +20123456789.123:5:20123000000
509 -20123456789.123:5:-20123000000
510 +20123456789:9:20123456800
511 -20123456789:9:-20123456800
512 +201234500:6:201234000
513 -201234500:6:-201234000
515 +30123456789:5:30123000000
516 -30123456789:5:-30123000000
517 +30123456789.123:5:30123000000
518 -30123456789.123:5:-30123000000
519 +30123456789:9:30123456800
520 -30123456789:9:-30123456800
521 +301234500:6:301235000
522 -301234500:6:-301234000
524 +40123456789:5:40123000000
525 -40123456789:5:-40123000000
526 +40123456789.123:5:40123000000
527 -40123456789.123:5:-40123000000
528 +40123456789:9:40123456800
529 -40123456789:9:-40123456800
530 +401234500:6:401234000
531 -401234500:6:-401235000
533 +50123456789:5:50123000000
534 -50123456789:5:-50123000000
535 +50123456789.123:5:50123000000
536 -50123456789.123:5:-50123000000
537 +50123456789:9:50123456800
538 -50123456789:9:-50123456800
539 +501234500:6:501235000
540 -501234500:6:-501235000
542 +60123456789:5:60123000000
543 -60123456789:5:-60123000000
544 +60123456789:9:60123456800
545 -60123456789:9:-60123456800
546 +601234500:6:601234000
547 -601234500:6:-601234000
548 +60123456789.0123:5:60123000000
549 -60123456789.0123:5:-60123000000
551 $round_mode = "trunc"
572 -0.0061234567890:-1:0.0
580 -0.0065:-3:/-0\.006|-6e-03
581 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
582 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
588 +2.23:-1:/2.2(?:0{5}\d+)?
589 -2.23:-1:/-2.2(?:0{5}\d+)?
590 +2.27:-1:/2.(?:3|29{5}\d+)
591 -2.27:-1:/-2.(?:3|29{5}\d+)
592 +2.25:-1:/2.2(?:0{5}\d+)?
593 -2.25:-1:/-2.2(?:0{5}\d+)?
594 +2.35:-1:/2.(?:3|29{5}\d+)
595 -2.35:-1:/-2.(?:3|29{5}\d+)
597 -0.0065:-2:/-0\.01|-1e-02
598 -0.0065:-3:/-0\.006|-6e-03
599 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
600 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
606 +3.23:-1:/3.2(?:0{5}\d+)?
607 -3.23:-1:/-3.2(?:0{5}\d+)?
608 +3.27:-1:/3.(?:3|29{5}\d+)
609 -3.27:-1:/-3.(?:3|29{5}\d+)
610 +3.25:-1:/3.(?:3|29{5}\d+)
611 -3.25:-1:/-3.2(?:0{5}\d+)?
612 +3.35:-1:/3.(?:4|39{5}\d+)
613 -3.35:-1:/-3.(?:3|29{5}\d+)
615 -0.0065:-2:/-0\.01|-1e-02
616 -0.0065:-3:/-0\.006|-6e-03
617 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
618 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
624 +4.23:-1:/4.2(?:0{5}\d+)?
625 -4.23:-1:/-4.2(?:0{5}\d+)?
626 +4.27:-1:/4.(?:3|29{5}\d+)
627 -4.27:-1:/-4.(?:3|29{5}\d+)
628 +4.25:-1:/4.2(?:0{5}\d+)?
629 -4.25:-1:/-4.(?:3|29{5}\d+)
630 +4.35:-1:/4.(?:3|29{5}\d+)
631 -4.35:-1:/-4.(?:4|39{5}\d+)
633 -0.0065:-2:/-0\.01|-1e-02
634 -0.0065:-3:/-0\.007|-7e-03
635 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
636 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
642 +5.23:-1:/5.2(?:0{5}\d+)?
643 -5.23:-1:/-5.2(?:0{5}\d+)?
644 +5.27:-1:/5.(?:3|29{5}\d+)
645 -5.27:-1:/-5.(?:3|29{5}\d+)
646 +5.25:-1:/5.(?:3|29{5}\d+)
647 -5.25:-1:/-5.(?:3|29{5}\d+)
648 +5.35:-1:/5.(?:3|29{5}\d+)
649 -5.35:-1:/-5.(?:3|29{5}\d+)
651 -0.0065:-2:/-0\.01|-1e-02
652 -0.0065:-3:/-0\.007|-7e-03
653 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
654 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
660 +6.23:-1:/6.2(?:0{5}\d+)?
661 -6.23:-1:/-6.2(?:0{5}\d+)?
662 +6.27:-1:/6.(?:3|29{5}\d+)
663 -6.27:-1:/-6.(?:3|29{5}\d+)
664 +6.25:-1:/6.(?:2(?:0{5}\d+)?|29{5}\d+)
665 -6.25:-1:/-6.(?:2(?:0{5}\d+)?|29{5}\d+)
666 +6.35:-1:/6.(?:4|39{5}\d+|29{8}\d+)
667 -6.35:-1:/-6.(?:4|39{5}\d+|29{8}\d+)
669 -0.0065:-2:/-0\.01|-1e-02
670 -0.0065:-3:/-0\.006|-7e-03
671 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
672 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
679 0.01234567:-5:0.01235
680 0.01234567:-6:0.012346
681 0.01234567:-7:0.0123457
682 0.01234567:-8:0.01234567
683 0.01234567:-9:0.012345670
684 0.01234567:-12:0.012345670000
886 +99999999:+1:100000000
887 +999999999:+1:1000000000
888 +9999999999:+1:10000000000
889 +99999999999:+1:100000000000
897 +100000000:-1:99999999
898 +1000000000:-1:999999999
899 +10000000000:-1:9999999999
900 +123456789:+987654321:1111111110
901 -123456789:+987654321:864197532
902 -123456789:-987654321:-1111111110
903 +123456789:-987654321:-864197532
904 0.001234:0.0001234:0.0013574
933 +99999999:+1:99999998
934 +999999999:+1:999999998
935 +9999999999:+1:9999999998
936 +99999999999:+1:99999999998
943 +10000000:-1:10000001
944 +100000000:-1:100000001
945 +1000000000:-1:1000000001
946 +10000000000:-1:10000000001
947 +123456789:+987654321:-864197532
948 -123456789:+987654321:-1111111110
949 -123456789:-987654321:864197532
950 +123456789:-987654321:1111111110
976 +123456789123456789:+0:0
977 +0:+123456789123456789:0
987 +10101:+10101:102030201
988 +1001001:+1001001:1002003002001
989 +100010001:+100010001:10002000300020001
990 +10000100001:+10000100001:100002000030000200001
991 +11111111111:+9:99999999999
992 +22222222222:+9:199999999998
993 +33333333333:+9:299999999997
994 +44444444444:+9:399999999996
995 +55555555555:+9:499999999995
996 +66666666666:+9:599999999994
997 +77777777777:+9:699999999993
998 +88888888888:+9:799999999992
999 +99999999999:+9:899999999991
1008 $div_scale = 40; $round_mode = 'even'
1034 +999999999999:+9:111111111111
1035 +999999999999:+99:10101010101
1036 +999999999999:+999:1001001001
1037 +999999999999:+9999:100010001
1038 +999999999999999:+99999:10000100001
1039 +1000000000:+9:111111111.1111111111111111111111111111111
1040 +2000000000:+9:222222222.2222222222222222222222222222222
1041 +3000000000:+9:333333333.3333333333333333333333333333333
1042 +4000000000:+9:444444444.4444444444444444444444444444444
1043 +5000000000:+9:555555555.5555555555555555555555555555556
1044 +6000000000:+9:666666666.6666666666666666666666666666667
1045 +7000000000:+9:777777777.7777777777777777777777777777778
1046 +8000000000:+9:888888888.8888888888888888888888888888889
1047 +9000000000:+9:1000000000
1048 +35500000:+113:314159.2920353982300884955752212389380531
1049 +71000000:+226:314159.2920353982300884955752212389380531
1050 +106500000:+339:314159.2920353982300884955752212389380531
1051 +1000000000:+3:333333333.3333333333333333333333333333333
1052 2:25.024996000799840031993601279744051189762:0.07992009269196593320152084692285869265447
1055 +1000000000:+9:111111111.11111111111
1056 +2000000000:+9:222222222.22222222222
1057 +3000000000:+9:333333333.33333333333
1058 +4000000000:+9:444444444.44444444444
1059 +5000000000:+9:555555555.55555555556
1060 +6000000000:+9:666666666.66666666667
1061 +7000000000:+9:777777777.77777777778
1062 +8000000000:+9:888888888.88888888889
1063 +9000000000:+9:1000000000
1068 1:504:0.001984126984126984127
1069 2:1.987654321:1.0062111801179738436
1070 123456789.123456789123456789123456789:1:123456789.12345678912
1071 # the next two cases are the "old" behaviour, but are now (>v0.01) different
1072 #+35500000:+113:314159.292035398230088
1073 #+71000000:+226:314159.292035398230088
1074 +35500000:+113:314159.29203539823009
1075 +71000000:+226:314159.29203539823009
1076 +106500000:+339:314159.29203539823009
1077 +1000000000:+3:333333333.33333333333
1079 # round to accuracy 1 after bdiv
1081 123456789.1234:1:100000000
1082 # reset scale for further tests
1089 # inf handling, see table in doc
1108 # exceptions to reminder rule
1147 999999999999999:99999:0
1161 152403346:12345:4321
1163 # now some floating point tests
1191 2:1.41421356237309504880168872420969807857
1196 123.456:11.11107555549866648462149404118219234119
1197 15241.38393:123.4559999756998444766131352122991626468
1199 # sqrt(1.44) = 1.2, sqrt(e10) = e5 => 12e4
1201 2e10:141421.356237309504880168872420969807857
1203 # proved to be an endless loop under 7-9
1204 12:3.464101615137754587054892683011744733886
1221 # it must be exactly /^[+-]inf$/
1317 12345678901234567890:20