1 #include this file into another test for subclass testing...
5 $_ =~ s/#.*$//; # remove comments
6 $_ =~ s/\s+$//; # trailing spaces
7 next if /^$/; # skip empty lines & comments
14 $setup = $_; $setup =~ s/\$/\$${class}::/g; # round_mode, div_scale
15 #print "\$setup== $setup\n";
22 @args = split(/:/,$1,99);
26 @args = split(/:/,$_,99); $ans = pop(@args);
28 $try = "\$x = new $class \"$args[0]\";";
32 } elsif ($f eq "finf") {
33 $try .= "\$x->finf('$args[1]');";
34 } elsif ($f eq "is_inf") {
35 $try .= "\$x->is_inf('$args[1]');";
36 } elsif ($f eq "fone") {
37 $try .= "\$x->bone('$args[1]');";
38 } elsif ($f eq "fstr") {
39 $try .= "\$x->accuracy($args[1]); \$x->precision($args[2]);";
40 $try .= '$x->fstr();';
41 } elsif ($f eq "parts") {
42 # ->bstr() to see if an object is returned
43 $try .= '($a,$b) = $x->parts(); $a = $a->bstr(); $b = $b->bstr();';
45 } elsif ($f eq "exponent") {
46 # ->bstr() to see if an object is returned
47 $try .= '$x->exponent()->bstr();';
48 } elsif ($f eq "mantissa") {
49 # ->bstr() to see if an object is returned
50 $try .= '$x->mantissa()->bstr();';
51 } elsif ($f eq "numify") {
52 $try .= "\$x->numify();";
53 } elsif ($f eq "length") {
54 $try .= "\$x->length();";
55 # some unary ops (test the bxxx form, since that is done by AUTOLOAD)
56 } elsif ($f =~ /^f(nan|sstr|neg|floor|ceil|abs)$/) {
57 $try .= "\$x->f$1();";
58 # some is_xxx test function
59 } elsif ($f =~ /^is_(zero|one|negative|positive|odd|even|nan)$/) {
61 } elsif ($f eq "as_number") {
62 $try .= '$x->as_number();';
63 } elsif ($f eq "finc") {
65 } elsif ($f eq "fdec") {
67 }elsif ($f eq "fround") {
68 $try .= "$setup; \$x->fround($args[1]);";
69 } elsif ($f eq "ffround") {
70 $try .= "$setup; \$x->ffround($args[1]);";
71 } elsif ($f eq "fsqrt") {
72 $try .= "$setup; \$x->fsqrt();";
76 $try .= "\$y = new $class \"$args[1]\";";
79 } elsif ($f eq "flog") {
80 $try .= '$x->flog($y);';
81 } elsif ($f eq "facmp") {
82 $try .= '$x->facmp($y);';
83 } elsif ($f eq "fpow") {
85 } elsif ($f eq "fadd") {
87 } elsif ($f eq "fsub") {
89 } elsif ($f eq "fmul") {
91 } elsif ($f eq "fdiv") {
92 $try .= "$setup; \$x / \$y;";
93 } elsif ($f eq "frsft") {
95 } elsif ($f eq "flsft") {
97 } elsif ($f eq "fmod") {
99 } else { warn "Unknown op '$f'"; }
101 # print "# Trying: '$try'\n";
103 if ($ans =~ m|^/(.*)$|)
112 print "# '$try' expected: /$pat/ got: '$ans1'\n" if !ok(1,0);
123 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
124 if (ref($ans1) eq "$class")
126 # float numbers are normalized (for now), so mantissa shouldn't have
128 #print $ans1->_trailing_zeros(),"\n";
129 print "# Has trailing zeros after '$try'\n"
130 if !ok ($ans1->{_m}->_trailing_zeros(), 0);
133 } # end pattern or string
137 # check whether $class->new( Math::BigInt->new()) destroys it
138 # ($y == 12 in this case)
139 $x = Math::BigInt->new(1200); $y = $class->new($x);
140 ok ($y,1200); ok ($x,1200);
142 ###############################################################################
143 # fdiv() in list context
145 $x = $class->bzero(); ($x,$y) = $x->fdiv(0);
146 ok ($x,'NaN'); ok ($y,'NaN');
148 # fdiv() in list context
149 $x = $class->bzero(); ($x,$y) = $x->fdiv(1);
150 ok ($x,0); ok ($y,0);
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;
193 #10:0:2.30258509299405
194 #1000:0:6.90775527898214
195 #100:0:4.60517018598809
196 #2:0:0.693147180559945
197 #3.1415:0:1.14470039286086
198 #12345:0:9.42100640177928
199 #0.001:0:-6.90775527898214
200 ## reset for further tests
275 1234.567:9::1234.56700
276 1234.567::-6:1234.567000
278 0.001234:6::0.00123400
279 0.001234::-8:0.00123400
298 000000_0000000_00000:0
309 -123456789:-123456789
317 -.0000000004:-0.0000000004
332 -3e111:-3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
333 -4e-1111:-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004
340 123.456:2:15241.383936
343 128:-2:0.00006103515625
357 +123456789:-123456789
359 +123.456789:-123.456789
360 -123456.789:123456.789
370 +123.456789:123.456789
371 -123456.789:123456.789
373 $round_mode = "trunc"
378 +10123456789:5:10123000000
379 -10123456789:5:-10123000000
380 +10123456789.123:5:10123000000
381 -10123456789.123:5:-10123000000
382 +10123456789:9:10123456700
383 -10123456789:9:-10123456700
384 +101234500:6:101234000
385 -101234500:6:-101234000
387 +20123456789:5:20123000000
388 -20123456789:5:-20123000000
389 +20123456789.123:5:20123000000
390 -20123456789.123:5:-20123000000
391 +20123456789:9:20123456800
392 -20123456789:9:-20123456800
393 +201234500:6:201234000
394 -201234500:6:-201234000
396 +30123456789:5:30123000000
397 -30123456789:5:-30123000000
398 +30123456789.123:5:30123000000
399 -30123456789.123:5:-30123000000
400 +30123456789:9:30123456800
401 -30123456789:9:-30123456800
402 +301234500:6:301235000
403 -301234500:6:-301234000
405 +40123456789:5:40123000000
406 -40123456789:5:-40123000000
407 +40123456789.123:5:40123000000
408 -40123456789.123:5:-40123000000
409 +40123456789:9:40123456800
410 -40123456789:9:-40123456800
411 +401234500:6:401234000
412 -401234500:6:-401235000
414 +50123456789:5:50123000000
415 -50123456789:5:-50123000000
416 +50123456789.123:5:50123000000
417 -50123456789.123:5:-50123000000
418 +50123456789:9:50123456800
419 -50123456789:9:-50123456800
420 +501234500:6:501235000
421 -501234500:6:-501235000
423 +60123456789:5:60123000000
424 -60123456789:5:-60123000000
425 +60123456789:9:60123456800
426 -60123456789:9:-60123456800
427 +601234500:6:601234000
428 -601234500:6:-601234000
429 +60123456789.0123:5:60123000000
430 -60123456789.0123:5:-60123000000
432 $round_mode = "trunc"
453 -0.0061234567890:-1:0.0
461 -0.0065:-3:/-0\.006|-6e-03
462 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
463 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
469 +2.23:-1:/2.2(?:0{5}\d+)?
470 -2.23:-1:/-2.2(?:0{5}\d+)?
471 +2.27:-1:/2.(?:3|29{5}\d+)
472 -2.27:-1:/-2.(?:3|29{5}\d+)
473 +2.25:-1:/2.2(?:0{5}\d+)?
474 -2.25:-1:/-2.2(?:0{5}\d+)?
475 +2.35:-1:/2.(?:3|29{5}\d+)
476 -2.35:-1:/-2.(?:3|29{5}\d+)
478 -0.0065:-2:/-0\.01|-1e-02
479 -0.0065:-3:/-0\.006|-6e-03
480 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
481 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
487 +3.23:-1:/3.2(?:0{5}\d+)?
488 -3.23:-1:/-3.2(?:0{5}\d+)?
489 +3.27:-1:/3.(?:3|29{5}\d+)
490 -3.27:-1:/-3.(?:3|29{5}\d+)
491 +3.25:-1:/3.(?:3|29{5}\d+)
492 -3.25:-1:/-3.2(?:0{5}\d+)?
493 +3.35:-1:/3.(?:4|39{5}\d+)
494 -3.35:-1:/-3.(?:3|29{5}\d+)
496 -0.0065:-2:/-0\.01|-1e-02
497 -0.0065:-3:/-0\.006|-6e-03
498 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
499 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
505 +4.23:-1:/4.2(?:0{5}\d+)?
506 -4.23:-1:/-4.2(?:0{5}\d+)?
507 +4.27:-1:/4.(?:3|29{5}\d+)
508 -4.27:-1:/-4.(?:3|29{5}\d+)
509 +4.25:-1:/4.2(?:0{5}\d+)?
510 -4.25:-1:/-4.(?:3|29{5}\d+)
511 +4.35:-1:/4.(?:3|29{5}\d+)
512 -4.35:-1:/-4.(?:4|39{5}\d+)
514 -0.0065:-2:/-0\.01|-1e-02
515 -0.0065:-3:/-0\.007|-7e-03
516 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
517 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
523 +5.23:-1:/5.2(?:0{5}\d+)?
524 -5.23:-1:/-5.2(?:0{5}\d+)?
525 +5.27:-1:/5.(?:3|29{5}\d+)
526 -5.27:-1:/-5.(?:3|29{5}\d+)
527 +5.25:-1:/5.(?:3|29{5}\d+)
528 -5.25:-1:/-5.(?:3|29{5}\d+)
529 +5.35:-1:/5.(?:3|29{5}\d+)
530 -5.35:-1:/-5.(?:3|29{5}\d+)
532 -0.0065:-2:/-0\.01|-1e-02
533 -0.0065:-3:/-0\.007|-7e-03
534 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
535 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
541 +6.23:-1:/6.2(?:0{5}\d+)?
542 -6.23:-1:/-6.2(?:0{5}\d+)?
543 +6.27:-1:/6.(?:3|29{5}\d+)
544 -6.27:-1:/-6.(?:3|29{5}\d+)
545 +6.25:-1:/6.(?:2(?:0{5}\d+)?|29{5}\d+)
546 -6.25:-1:/-6.(?:2(?:0{5}\d+)?|29{5}\d+)
547 +6.35:-1:/6.(?:4|39{5}\d+|29{8}\d+)
548 -6.35:-1:/-6.(?:4|39{5}\d+|29{8}\d+)
550 -0.0065:-2:/-0\.01|-1e-02
551 -0.0065:-3:/-0\.006|-7e-03
552 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
553 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
560 0.01234567:-5:0.01235
561 0.01234567:-6:0.012346
562 0.01234567:-7:0.0123457
563 0.01234567:-8:0.01234567
564 0.01234567:-9:0.012345670
565 0.01234567:-12:0.012345670000
767 +99999999:+1:100000000
768 +999999999:+1:1000000000
769 +9999999999:+1:10000000000
770 +99999999999:+1:100000000000
778 +100000000:-1:99999999
779 +1000000000:-1:999999999
780 +10000000000:-1:9999999999
781 +123456789:+987654321:1111111110
782 -123456789:+987654321:864197532
783 -123456789:-987654321:-1111111110
784 +123456789:-987654321:-864197532
785 0.001234:0.0001234:0.0013574
814 +99999999:+1:99999998
815 +999999999:+1:999999998
816 +9999999999:+1:9999999998
817 +99999999999:+1:99999999998
824 +10000000:-1:10000001
825 +100000000:-1:100000001
826 +1000000000:-1:1000000001
827 +10000000000:-1:10000000001
828 +123456789:+987654321:-864197532
829 -123456789:+987654321:-1111111110
830 -123456789:-987654321:864197532
831 +123456789:-987654321:1111111110
857 +123456789123456789:+0:0
858 +0:+123456789123456789:0
868 +10101:+10101:102030201
869 +1001001:+1001001:1002003002001
870 +100010001:+100010001:10002000300020001
871 +10000100001:+10000100001:100002000030000200001
872 +11111111111:+9:99999999999
873 +22222222222:+9:199999999998
874 +33333333333:+9:299999999997
875 +44444444444:+9:399999999996
876 +55555555555:+9:499999999995
877 +66666666666:+9:599999999994
878 +77777777777:+9:699999999993
879 +88888888888:+9:799999999992
880 +99999999999:+9:899999999991
884 $div_scale = 40; $round_mode = 'even'
910 +999999999999:+9:111111111111
911 +999999999999:+99:10101010101
912 +999999999999:+999:1001001001
913 +999999999999:+9999:100010001
914 +999999999999999:+99999:10000100001
915 +1000000000:+9:111111111.1111111111111111111111111111111
916 +2000000000:+9:222222222.2222222222222222222222222222222
917 +3000000000:+9:333333333.3333333333333333333333333333333
918 +4000000000:+9:444444444.4444444444444444444444444444444
919 +5000000000:+9:555555555.5555555555555555555555555555556
920 +6000000000:+9:666666666.6666666666666666666666666666667
921 +7000000000:+9:777777777.7777777777777777777777777777778
922 +8000000000:+9:888888888.8888888888888888888888888888889
923 +9000000000:+9:1000000000
924 +35500000:+113:314159.2920353982300884955752212389380531
925 +71000000:+226:314159.2920353982300884955752212389380531
926 +106500000:+339:314159.2920353982300884955752212389380531
927 +1000000000:+3:333333333.3333333333333333333333333333333
928 2:25.024996000799840031993601279744051189762:0.07992009269196593320152084692285869265447
931 +1000000000:+9:111111111.11111111111
932 +2000000000:+9:222222222.22222222222
933 +3000000000:+9:333333333.33333333333
934 +4000000000:+9:444444444.44444444444
935 +5000000000:+9:555555555.55555555556
936 +6000000000:+9:666666666.66666666667
937 +7000000000:+9:777777777.77777777778
938 +8000000000:+9:888888888.88888888889
939 +9000000000:+9:1000000000
944 1:504:0.001984126984126984127
945 2:1.987654321:1.0062111801179738436
946 123456789.123456789123456789123456789:1:123456789.12345678912
947 # the next two cases are the "old" behaviour, but are now (>v0.01) different
948 #+35500000:+113:314159.292035398230088
949 #+71000000:+226:314159.292035398230088
950 +35500000:+113:314159.29203539823009
951 +71000000:+226:314159.29203539823009
952 +106500000:+339:314159.29203539823009
953 +1000000000:+3:333333333.33333333333
955 # round to accuracy 1 after bdiv
957 123456789.1234:1:100000000
958 # reset scale for further tests
965 # inf handling, see table in doc
984 # exceptions to reminder rule
1023 999999999999999:99999:0
1037 152403346:12345:4321
1039 # now some floating point tests
1054 2:1.41421356237309504880168872420969807857
1059 123.456:11.11107555549866648462149404118219234119
1060 15241.38393:123.4559999756998444766131352122991626468
1062 # sqrt(1.44) = 1.2, sqrt(e10) = e5 => 12e4
1064 2e10:141421.356237309504880168872420969807857
1065 # proved to be an endless loop under 7-9
1066 12:3.464101615137754587054892683011744733886
1083 # it must be exactly /^[+-]inf$/
1162 12345678901234567890:20