1 #include this file into another test for subclass testing...
3 ok ($class->config()->{lib},$CL);
8 $_ =~ s/#.*$//; # remove comments
9 $_ =~ s/\s+$//; # trailing spaces
10 next if /^$/; # skip empty lines & comments
17 $setup = $_; $setup =~ s/\$/\$${class}::/g; # round_mode, div_scale
18 #print "\$setup== $setup\n";
25 @args = split(/:/,$1,99);
29 @args = split(/:/,$_,99); $ans = pop(@args);
31 $try = "\$x = new $class \"$args[0]\";";
35 } elsif ($f eq "finf") {
36 $try .= "\$x->binf('$args[1]');";
37 } elsif ($f eq "is_inf") {
38 $try .= "\$x->is_inf('$args[1]');";
39 } elsif ($f eq "fone") {
40 $try .= "\$x->bone('$args[1]');";
41 } elsif ($f eq "fstr") {
42 $try .= "\$x->accuracy($args[1]); \$x->precision($args[2]);";
43 $try .= '$x->bstr();';
44 } elsif ($f eq "parts") {
45 # ->bstr() to see if an object is returned
46 $try .= '($a,$b) = $x->parts(); $a = $a->bstr(); $b = $b->bstr();';
48 } elsif ($f eq "exponent") {
49 # ->bstr() to see if an object is returned
50 $try .= '$x->exponent()->bstr();';
51 } elsif ($f eq "mantissa") {
52 # ->bstr() to see if an object is returned
53 $try .= '$x->mantissa()->bstr();';
54 } elsif ($f eq "numify") {
55 $try .= "\$x->numify();";
56 } elsif ($f eq "length") {
57 $try .= "\$x->length();";
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->b$1();";
61 # some is_xxx test function
62 } elsif ($f =~ /^is_(zero|one|negative|positive|odd|even|nan|int)$/) {
64 } elsif ($f eq "as_number") {
65 $try .= '$x->as_number();';
66 } elsif ($f eq "finc") {
68 } elsif ($f eq "fdec") {
70 }elsif ($f eq "fround") {
71 $try .= "$setup; \$x->bround($args[1]);";
72 } elsif ($f eq "ffround") {
73 $try .= "$setup; \$x->bfround($args[1]);";
74 } elsif ($f eq "fsqrt") {
75 $try .= "$setup; \$x->bsqrt();";
76 } elsif ($f eq "flog") {
77 $try .= "$setup; \$x->blog();";
78 } elsif ($f eq "ffac") {
79 $try .= "$setup; \$x->bfac();";
83 $try .= "\$y = new $class \"$args[1]\";";
86 } elsif ($f eq "facmp") {
87 $try .= '$x->bacmp($y);';
88 } elsif ($f eq "fpow") {
90 } elsif ($f eq "fadd") {
92 } elsif ($f eq "fsub") {
94 } elsif ($f eq "fmul") {
96 } elsif ($f eq "fdiv") {
97 $try .= "$setup; \$x / \$y;";
98 } elsif ($f eq "fdiv-list") {
99 $try .= "$setup; join(',',\$x->bdiv(\$y));";
100 } elsif ($f eq "frsft") {
102 } elsif ($f eq "flsft") {
104 } elsif ($f eq "fmod") {
106 } else { warn "Unknown op '$f'"; }
108 # print "# Trying: '$try'\n";
110 if ($ans =~ m|^/(.*)$|)
119 print "# '$try' expected: /$pat/ got: '$ans1'\n" if !ok(1,0);
130 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
131 # if (ref($ans1) eq "$class")
133 # # float numbers are normalized (for now), so mantissa shouldn't have
135 # #print $ans1->_trailing_zeros(),"\n";
136 # print "# Has trailing zeros after '$try'\n"
137 # if !ok ($ans1->{_m}->_trailing_zeros(), 0);
140 } # end pattern or string
144 # check whether $class->new( Math::BigInt->new()) destroys it
145 # ($y == 12 in this case)
146 $x = Math::BigInt->new(1200); $y = $class->new($x);
147 ok ($y,1200); ok ($x,1200);
149 ###############################################################################
152 $x = $class->new(2); $x->fzero(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
153 $x = $class->new(2); $x->finf(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
154 $x = $class->new(2); $x->fone(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
155 $x = $class->new(2); $x->fnan(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
157 ###############################################################################
158 # fsqrt() with set global A/P or A/P enabled on $x, also a test whether fsqrt()
159 # correctly modifies $x
161 $class->accuracy(undef); $class->precision(undef); # reset
163 $x = $class->new(12); $class->precision(-2); $x->fsqrt(); ok ($x,'3.46');
165 $class->precision(undef);
166 $x = $class->new(12); $class->precision(0); $x->fsqrt(); ok ($x,'3');
168 $class->precision(-3); $x = $class->new(12); $x->fsqrt(); ok ($x,'3.464');
171 ${${class}.'::accuracy'} = 4; $x = $class->new(12); $x->fsqrt(3); ok ($x,'NaN');
172 # supplied arg overrides set global
173 $class->precision(undef); $x = $class->new(12); $x->fsqrt(3); ok ($x,'3.46');
175 $class->accuracy(undef); $class->precision(undef); # reset for further tests
179 ###############################################################################
180 # Perl 5.005 does not like ok ($x,undef)
186 ok (1,1) and return if !defined $x;
197 # this is too slow for the testsuite
198 #2.718281828:0.9999999998311266953289851340574956564911
200 #2.718281828:0.99999999983112669533
202 # too slow, too (or hangs?)
206 #1000:0:6.90775527898214
207 #100:0:4.60517018598809
208 #2:0:0.693147180559945
209 #3.1415:0:1.14470039286086
210 #12345:0:9.42100640177928
211 #0.001:0:-6.90775527898214
212 # reset for further tests
287 1234.567:9::1234.56700
288 1234.567::-6:1234.567000
290 0.001234:6::0.00123400
291 0.001234::-8:0.00123400
310 000000_0000000_00000:0
321 -123456789:-123456789
329 -.0000000004:-0.0000000004
344 -3e111:-3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
345 -4e-1111:-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004
352 123.456:2:15241.383936
355 128:-2:0.00006103515625
369 +123456789:-123456789
371 +123.456789:-123.456789
372 -123456.789:123456.789
382 +123.456789:123.456789
383 -123456.789:123456.789
385 $round_mode = "trunc"
390 +10123456789:5:10123000000
391 -10123456789:5:-10123000000
392 +10123456789.123:5:10123000000
393 -10123456789.123:5:-10123000000
394 +10123456789:9:10123456700
395 -10123456789:9:-10123456700
396 +101234500:6:101234000
397 -101234500:6:-101234000
399 +20123456789:5:20123000000
400 -20123456789:5:-20123000000
401 +20123456789.123:5:20123000000
402 -20123456789.123:5:-20123000000
403 +20123456789:9:20123456800
404 -20123456789:9:-20123456800
405 +201234500:6:201234000
406 -201234500:6:-201234000
408 +30123456789:5:30123000000
409 -30123456789:5:-30123000000
410 +30123456789.123:5:30123000000
411 -30123456789.123:5:-30123000000
412 +30123456789:9:30123456800
413 -30123456789:9:-30123456800
414 +301234500:6:301235000
415 -301234500:6:-301234000
417 +40123456789:5:40123000000
418 -40123456789:5:-40123000000
419 +40123456789.123:5:40123000000
420 -40123456789.123:5:-40123000000
421 +40123456789:9:40123456800
422 -40123456789:9:-40123456800
423 +401234500:6:401234000
424 -401234500:6:-401235000
426 +50123456789:5:50123000000
427 -50123456789:5:-50123000000
428 +50123456789.123:5:50123000000
429 -50123456789.123:5:-50123000000
430 +50123456789:9:50123456800
431 -50123456789:9:-50123456800
432 +501234500:6:501235000
433 -501234500:6:-501235000
435 +60123456789:5:60123000000
436 -60123456789:5:-60123000000
437 +60123456789:9:60123456800
438 -60123456789:9:-60123456800
439 +601234500:6:601234000
440 -601234500:6:-601234000
441 +60123456789.0123:5:60123000000
442 -60123456789.0123:5:-60123000000
444 $round_mode = "trunc"
465 -0.0061234567890:-1:0.0
473 -0.0065:-3:/-0\.006|-6e-03
474 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
475 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
481 +2.23:-1:/2.2(?:0{5}\d+)?
482 -2.23:-1:/-2.2(?:0{5}\d+)?
483 +2.27:-1:/2.(?:3|29{5}\d+)
484 -2.27:-1:/-2.(?:3|29{5}\d+)
485 +2.25:-1:/2.2(?:0{5}\d+)?
486 -2.25:-1:/-2.2(?:0{5}\d+)?
487 +2.35:-1:/2.(?:3|29{5}\d+)
488 -2.35:-1:/-2.(?:3|29{5}\d+)
490 -0.0065:-2:/-0\.01|-1e-02
491 -0.0065:-3:/-0\.006|-6e-03
492 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
493 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
499 +3.23:-1:/3.2(?:0{5}\d+)?
500 -3.23:-1:/-3.2(?:0{5}\d+)?
501 +3.27:-1:/3.(?:3|29{5}\d+)
502 -3.27:-1:/-3.(?:3|29{5}\d+)
503 +3.25:-1:/3.(?:3|29{5}\d+)
504 -3.25:-1:/-3.2(?:0{5}\d+)?
505 +3.35:-1:/3.(?:4|39{5}\d+)
506 -3.35:-1:/-3.(?:3|29{5}\d+)
508 -0.0065:-2:/-0\.01|-1e-02
509 -0.0065:-3:/-0\.006|-6e-03
510 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
511 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
517 +4.23:-1:/4.2(?:0{5}\d+)?
518 -4.23:-1:/-4.2(?:0{5}\d+)?
519 +4.27:-1:/4.(?:3|29{5}\d+)
520 -4.27:-1:/-4.(?:3|29{5}\d+)
521 +4.25:-1:/4.2(?:0{5}\d+)?
522 -4.25:-1:/-4.(?:3|29{5}\d+)
523 +4.35:-1:/4.(?:3|29{5}\d+)
524 -4.35:-1:/-4.(?:4|39{5}\d+)
526 -0.0065:-2:/-0\.01|-1e-02
527 -0.0065:-3:/-0\.007|-7e-03
528 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
529 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
535 +5.23:-1:/5.2(?:0{5}\d+)?
536 -5.23:-1:/-5.2(?:0{5}\d+)?
537 +5.27:-1:/5.(?:3|29{5}\d+)
538 -5.27:-1:/-5.(?:3|29{5}\d+)
539 +5.25:-1:/5.(?:3|29{5}\d+)
540 -5.25:-1:/-5.(?:3|29{5}\d+)
541 +5.35:-1:/5.(?:3|29{5}\d+)
542 -5.35:-1:/-5.(?:3|29{5}\d+)
544 -0.0065:-2:/-0\.01|-1e-02
545 -0.0065:-3:/-0\.007|-7e-03
546 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
547 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
553 +6.23:-1:/6.2(?:0{5}\d+)?
554 -6.23:-1:/-6.2(?:0{5}\d+)?
555 +6.27:-1:/6.(?:3|29{5}\d+)
556 -6.27:-1:/-6.(?:3|29{5}\d+)
557 +6.25:-1:/6.(?:2(?:0{5}\d+)?|29{5}\d+)
558 -6.25:-1:/-6.(?:2(?:0{5}\d+)?|29{5}\d+)
559 +6.35:-1:/6.(?:4|39{5}\d+|29{8}\d+)
560 -6.35:-1:/-6.(?:4|39{5}\d+|29{8}\d+)
562 -0.0065:-2:/-0\.01|-1e-02
563 -0.0065:-3:/-0\.006|-7e-03
564 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
565 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
572 0.01234567:-5:0.01235
573 0.01234567:-6:0.012346
574 0.01234567:-7:0.0123457
575 0.01234567:-8:0.01234567
576 0.01234567:-9:0.012345670
577 0.01234567:-12:0.012345670000
779 +99999999:+1:100000000
780 +999999999:+1:1000000000
781 +9999999999:+1:10000000000
782 +99999999999:+1:100000000000
790 +100000000:-1:99999999
791 +1000000000:-1:999999999
792 +10000000000:-1:9999999999
793 +123456789:+987654321:1111111110
794 -123456789:+987654321:864197532
795 -123456789:-987654321:-1111111110
796 +123456789:-987654321:-864197532
797 0.001234:0.0001234:0.0013574
826 +99999999:+1:99999998
827 +999999999:+1:999999998
828 +9999999999:+1:9999999998
829 +99999999999:+1:99999999998
836 +10000000:-1:10000001
837 +100000000:-1:100000001
838 +1000000000:-1:1000000001
839 +10000000000:-1:10000000001
840 +123456789:+987654321:-864197532
841 -123456789:+987654321:-1111111110
842 -123456789:-987654321:864197532
843 +123456789:-987654321:1111111110
869 +123456789123456789:+0:0
870 +0:+123456789123456789:0
880 +10101:+10101:102030201
881 +1001001:+1001001:1002003002001
882 +100010001:+100010001:10002000300020001
883 +10000100001:+10000100001:100002000030000200001
884 +11111111111:+9:99999999999
885 +22222222222:+9:199999999998
886 +33333333333:+9:299999999997
887 +44444444444:+9:399999999996
888 +55555555555:+9:499999999995
889 +66666666666:+9:599999999994
890 +77777777777:+9:699999999993
891 +88888888888:+9:799999999992
892 +99999999999:+9:899999999991
901 $div_scale = 40; $round_mode = 'even'
927 +999999999999:+9:111111111111
928 +999999999999:+99:10101010101
929 +999999999999:+999:1001001001
930 +999999999999:+9999:100010001
931 +999999999999999:+99999:10000100001
932 +1000000000:+9:111111111.1111111111111111111111111111111
933 +2000000000:+9:222222222.2222222222222222222222222222222
934 +3000000000:+9:333333333.3333333333333333333333333333333
935 +4000000000:+9:444444444.4444444444444444444444444444444
936 +5000000000:+9:555555555.5555555555555555555555555555556
937 +6000000000:+9:666666666.6666666666666666666666666666667
938 +7000000000:+9:777777777.7777777777777777777777777777778
939 +8000000000:+9:888888888.8888888888888888888888888888889
940 +9000000000:+9:1000000000
941 +35500000:+113:314159.2920353982300884955752212389380531
942 +71000000:+226:314159.2920353982300884955752212389380531
943 +106500000:+339:314159.2920353982300884955752212389380531
944 +1000000000:+3:333333333.3333333333333333333333333333333
945 2:25.024996000799840031993601279744051189762:0.07992009269196593320152084692285869265447
948 +1000000000:+9:111111111.11111111111
949 +2000000000:+9:222222222.22222222222
950 +3000000000:+9:333333333.33333333333
951 +4000000000:+9:444444444.44444444444
952 +5000000000:+9:555555555.55555555556
953 +6000000000:+9:666666666.66666666667
954 +7000000000:+9:777777777.77777777778
955 +8000000000:+9:888888888.88888888889
956 +9000000000:+9:1000000000
961 1:504:0.001984126984126984127
962 2:1.987654321:1.0062111801179738436
963 123456789.123456789123456789123456789:1:123456789.12345678912
964 # the next two cases are the "old" behaviour, but are now (>v0.01) different
965 #+35500000:+113:314159.292035398230088
966 #+71000000:+226:314159.292035398230088
967 +35500000:+113:314159.29203539823009
968 +71000000:+226:314159.29203539823009
969 +106500000:+339:314159.29203539823009
970 +1000000000:+3:333333333.33333333333
972 # round to accuracy 1 after bdiv
974 123456789.1234:1:100000000
975 # reset scale for further tests
982 # inf handling, see table in doc
1001 # exceptions to reminder rule
1040 999999999999999:99999:0
1054 152403346:12345:4321
1056 # now some floating point tests
1084 2:1.41421356237309504880168872420969807857
1089 123.456:11.11107555549866648462149404118219234119
1090 15241.38393:123.4559999756998444766131352122991626468
1092 # sqrt(1.44) = 1.2, sqrt(e10) = e5 => 12e4
1094 2e10:141421.356237309504880168872420969807857
1096 # proved to be an endless loop under 7-9
1097 12:3.464101615137754587054892683011744733886
1114 # it must be exactly /^[+-]inf$/
1210 12345678901234567890:20