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->finf('$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->fstr();';
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->f$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->fround($args[1]);";
72 } elsif ($f eq "ffround") {
73 $try .= "$setup; \$x->ffround($args[1]);";
74 } elsif ($f eq "fsqrt") {
75 $try .= "$setup; \$x->fsqrt();";
76 } elsif ($f eq "flog") {
77 $try .= "$setup; \$x->flog();";
78 } elsif ($f eq "ffac") {
79 $try .= "$setup; \$x->ffac();";
83 $try .= "\$y = new $class \"$args[1]\";";
86 } elsif ($f eq "facmp") {
87 $try .= '$x->facmp($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->fdiv(\$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
177 ###############################################################################
178 # can we call objectify (broken until v1.52)
180 $try = '@args' . " = $class" . "::objectify(2,$class,4,5);".'join(" ",@args);';
182 ok ($ans,"$class 4 5");
186 ###############################################################################
187 # Perl 5.005 does not like ok ($x,undef)
193 ok (1,1) and return if !defined $x;
204 # this is too slow for the testsuite
205 #2.718281828:0.9999999998311266953289851340574956564911
207 #2.718281828:0.99999999983112669533
209 # too slow, too (or hangs?)
213 #1000:0:6.90775527898214
214 #100:0:4.60517018598809
215 #2:0:0.693147180559945
216 #3.1415:0:1.14470039286086
217 #12345:0:9.42100640177928
218 #0.001:0:-6.90775527898214
219 # reset for further tests
294 1234.567:9::1234.56700
295 1234.567::-6:1234.567000
297 0.001234:6::0.00123400
298 0.001234::-8:0.00123400
317 000000_0000000_00000:0
328 -123456789:-123456789
336 -.0000000004:-0.0000000004
351 -3e111:-3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
352 -4e-1111:-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004
359 123.456:2:15241.383936
362 128:-2:0.00006103515625
376 +123456789:-123456789
378 +123.456789:-123.456789
379 -123456.789:123456.789
389 +123.456789:123.456789
390 -123456.789:123456.789
392 $round_mode = "trunc"
397 +10123456789:5:10123000000
398 -10123456789:5:-10123000000
399 +10123456789.123:5:10123000000
400 -10123456789.123:5:-10123000000
401 +10123456789:9:10123456700
402 -10123456789:9:-10123456700
403 +101234500:6:101234000
404 -101234500:6:-101234000
406 +20123456789:5:20123000000
407 -20123456789:5:-20123000000
408 +20123456789.123:5:20123000000
409 -20123456789.123:5:-20123000000
410 +20123456789:9:20123456800
411 -20123456789:9:-20123456800
412 +201234500:6:201234000
413 -201234500:6:-201234000
415 +30123456789:5:30123000000
416 -30123456789:5:-30123000000
417 +30123456789.123:5:30123000000
418 -30123456789.123:5:-30123000000
419 +30123456789:9:30123456800
420 -30123456789:9:-30123456800
421 +301234500:6:301235000
422 -301234500:6:-301234000
424 +40123456789:5:40123000000
425 -40123456789:5:-40123000000
426 +40123456789.123:5:40123000000
427 -40123456789.123:5:-40123000000
428 +40123456789:9:40123456800
429 -40123456789:9:-40123456800
430 +401234500:6:401234000
431 -401234500:6:-401235000
433 +50123456789:5:50123000000
434 -50123456789:5:-50123000000
435 +50123456789.123:5:50123000000
436 -50123456789.123:5:-50123000000
437 +50123456789:9:50123456800
438 -50123456789:9:-50123456800
439 +501234500:6:501235000
440 -501234500:6:-501235000
442 +60123456789:5:60123000000
443 -60123456789:5:-60123000000
444 +60123456789:9:60123456800
445 -60123456789:9:-60123456800
446 +601234500:6:601234000
447 -601234500:6:-601234000
448 +60123456789.0123:5:60123000000
449 -60123456789.0123:5:-60123000000
451 $round_mode = "trunc"
472 -0.0061234567890:-1:0.0
480 -0.0065:-3:/-0\.006|-6e-03
481 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
482 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
488 +2.23:-1:/2.2(?:0{5}\d+)?
489 -2.23:-1:/-2.2(?:0{5}\d+)?
490 +2.27:-1:/2.(?:3|29{5}\d+)
491 -2.27:-1:/-2.(?:3|29{5}\d+)
492 +2.25:-1:/2.2(?:0{5}\d+)?
493 -2.25:-1:/-2.2(?:0{5}\d+)?
494 +2.35:-1:/2.(?:3|29{5}\d+)
495 -2.35:-1:/-2.(?:3|29{5}\d+)
497 -0.0065:-2:/-0\.01|-1e-02
498 -0.0065:-3:/-0\.006|-6e-03
499 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
500 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
506 +3.23:-1:/3.2(?:0{5}\d+)?
507 -3.23:-1:/-3.2(?:0{5}\d+)?
508 +3.27:-1:/3.(?:3|29{5}\d+)
509 -3.27:-1:/-3.(?:3|29{5}\d+)
510 +3.25:-1:/3.(?:3|29{5}\d+)
511 -3.25:-1:/-3.2(?:0{5}\d+)?
512 +3.35:-1:/3.(?:4|39{5}\d+)
513 -3.35:-1:/-3.(?:3|29{5}\d+)
515 -0.0065:-2:/-0\.01|-1e-02
516 -0.0065:-3:/-0\.006|-6e-03
517 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
518 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
524 +4.23:-1:/4.2(?:0{5}\d+)?
525 -4.23:-1:/-4.2(?:0{5}\d+)?
526 +4.27:-1:/4.(?:3|29{5}\d+)
527 -4.27:-1:/-4.(?:3|29{5}\d+)
528 +4.25:-1:/4.2(?:0{5}\d+)?
529 -4.25:-1:/-4.(?:3|29{5}\d+)
530 +4.35:-1:/4.(?:3|29{5}\d+)
531 -4.35:-1:/-4.(?:4|39{5}\d+)
533 -0.0065:-2:/-0\.01|-1e-02
534 -0.0065:-3:/-0\.007|-7e-03
535 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
536 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
542 +5.23:-1:/5.2(?:0{5}\d+)?
543 -5.23:-1:/-5.2(?:0{5}\d+)?
544 +5.27:-1:/5.(?:3|29{5}\d+)
545 -5.27:-1:/-5.(?:3|29{5}\d+)
546 +5.25:-1:/5.(?:3|29{5}\d+)
547 -5.25:-1:/-5.(?:3|29{5}\d+)
548 +5.35:-1:/5.(?:3|29{5}\d+)
549 -5.35:-1:/-5.(?:3|29{5}\d+)
551 -0.0065:-2:/-0\.01|-1e-02
552 -0.0065:-3:/-0\.007|-7e-03
553 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
554 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
560 +6.23:-1:/6.2(?:0{5}\d+)?
561 -6.23:-1:/-6.2(?:0{5}\d+)?
562 +6.27:-1:/6.(?:3|29{5}\d+)
563 -6.27:-1:/-6.(?:3|29{5}\d+)
564 +6.25:-1:/6.(?:2(?:0{5}\d+)?|29{5}\d+)
565 -6.25:-1:/-6.(?:2(?:0{5}\d+)?|29{5}\d+)
566 +6.35:-1:/6.(?:4|39{5}\d+|29{8}\d+)
567 -6.35:-1:/-6.(?:4|39{5}\d+|29{8}\d+)
569 -0.0065:-2:/-0\.01|-1e-02
570 -0.0065:-3:/-0\.006|-7e-03
571 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
572 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
579 0.01234567:-5:0.01235
580 0.01234567:-6:0.012346
581 0.01234567:-7:0.0123457
582 0.01234567:-8:0.01234567
583 0.01234567:-9:0.012345670
584 0.01234567:-12:0.012345670000
786 +99999999:+1:100000000
787 +999999999:+1:1000000000
788 +9999999999:+1:10000000000
789 +99999999999:+1:100000000000
797 +100000000:-1:99999999
798 +1000000000:-1:999999999
799 +10000000000:-1:9999999999
800 +123456789:+987654321:1111111110
801 -123456789:+987654321:864197532
802 -123456789:-987654321:-1111111110
803 +123456789:-987654321:-864197532
804 0.001234:0.0001234:0.0013574
833 +99999999:+1:99999998
834 +999999999:+1:999999998
835 +9999999999:+1:9999999998
836 +99999999999:+1:99999999998
843 +10000000:-1:10000001
844 +100000000:-1:100000001
845 +1000000000:-1:1000000001
846 +10000000000:-1:10000000001
847 +123456789:+987654321:-864197532
848 -123456789:+987654321:-1111111110
849 -123456789:-987654321:864197532
850 +123456789:-987654321:1111111110
876 +123456789123456789:+0:0
877 +0:+123456789123456789:0
887 +10101:+10101:102030201
888 +1001001:+1001001:1002003002001
889 +100010001:+100010001:10002000300020001
890 +10000100001:+10000100001:100002000030000200001
891 +11111111111:+9:99999999999
892 +22222222222:+9:199999999998
893 +33333333333:+9:299999999997
894 +44444444444:+9:399999999996
895 +55555555555:+9:499999999995
896 +66666666666:+9:599999999994
897 +77777777777:+9:699999999993
898 +88888888888:+9:799999999992
899 +99999999999:+9:899999999991
908 $div_scale = 40; $round_mode = 'even'
934 +999999999999:+9:111111111111
935 +999999999999:+99:10101010101
936 +999999999999:+999:1001001001
937 +999999999999:+9999:100010001
938 +999999999999999:+99999:10000100001
939 +1000000000:+9:111111111.1111111111111111111111111111111
940 +2000000000:+9:222222222.2222222222222222222222222222222
941 +3000000000:+9:333333333.3333333333333333333333333333333
942 +4000000000:+9:444444444.4444444444444444444444444444444
943 +5000000000:+9:555555555.5555555555555555555555555555556
944 +6000000000:+9:666666666.6666666666666666666666666666667
945 +7000000000:+9:777777777.7777777777777777777777777777778
946 +8000000000:+9:888888888.8888888888888888888888888888889
947 +9000000000:+9:1000000000
948 +35500000:+113:314159.2920353982300884955752212389380531
949 +71000000:+226:314159.2920353982300884955752212389380531
950 +106500000:+339:314159.2920353982300884955752212389380531
951 +1000000000:+3:333333333.3333333333333333333333333333333
952 2:25.024996000799840031993601279744051189762:0.07992009269196593320152084692285869265447
955 +1000000000:+9:111111111.11111111111
956 +2000000000:+9:222222222.22222222222
957 +3000000000:+9:333333333.33333333333
958 +4000000000:+9:444444444.44444444444
959 +5000000000:+9:555555555.55555555556
960 +6000000000:+9:666666666.66666666667
961 +7000000000:+9:777777777.77777777778
962 +8000000000:+9:888888888.88888888889
963 +9000000000:+9:1000000000
968 1:504:0.001984126984126984127
969 2:1.987654321:1.0062111801179738436
970 123456789.123456789123456789123456789:1:123456789.12345678912
971 # the next two cases are the "old" behaviour, but are now (>v0.01) different
972 #+35500000:+113:314159.292035398230088
973 #+71000000:+226:314159.292035398230088
974 +35500000:+113:314159.29203539823009
975 +71000000:+226:314159.29203539823009
976 +106500000:+339:314159.29203539823009
977 +1000000000:+3:333333333.33333333333
979 # round to accuracy 1 after bdiv
981 123456789.1234:1:100000000
982 # reset scale for further tests
989 # inf handling, see table in doc
1008 # exceptions to reminder rule
1047 999999999999999:99999:0
1061 152403346:12345:4321
1063 # now some floating point tests
1091 2:1.41421356237309504880168872420969807857
1096 123.456:11.11107555549866648462149404118219234119
1097 15241.38393:123.4559999756998444766131352122991626468
1099 # sqrt(1.44) = 1.2, sqrt(e10) = e5 => 12e4
1101 2e10:141421.356237309504880168872420969807857
1103 # proved to be an endless loop under 7-9
1104 12:3.464101615137754587054892683011744733886
1121 # it must be exactly /^[+-]inf$/
1217 12345678901234567890:20