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 "facmp") {
80 $try .= '$x->facmp($y);';
81 } elsif ($f eq "fpow") {
83 } elsif ($f eq "fadd") {
85 } elsif ($f eq "fsub") {
87 } elsif ($f eq "fmul") {
89 } elsif ($f eq "fdiv") {
90 $try .= "$setup; \$x / \$y;";
91 } elsif ($f eq "frsft") {
93 } elsif ($f eq "flsft") {
95 } elsif ($f eq "fmod") {
97 } else { warn "Unknown op '$f'"; }
99 # print "# Trying: '$try'\n";
101 if ($ans =~ m|^/(.*)$|)
110 print "# '$try' expected: /$pat/ got: '$ans1'\n" if !ok(1,0);
121 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
122 if (ref($ans1) eq "$class")
124 # float numbers are normalized (for now), so mantissa shouldn't have
126 #print $ans1->_trailing_zeros(),"\n";
127 print "# Has trailing zeros after '$try'\n"
128 if !ok ($ans1->{_m}->_trailing_zeros(), 0);
131 } # end pattern or string
135 # check whether $class->new( Math::BigInt->new()) destroys it
136 # ($y == 12 in this case)
137 $x = Math::BigInt->new(1200); $y = $class->new($x);
138 ok ($y,1200); ok ($x,1200);
140 ###############################################################################
141 # fdiv() in list context
142 $x = $class->bzero(); ($x,$y) = $x->fdiv(0);
143 ok ($x,'NaN'); ok ($y,'NaN');
145 # fdiv() in list context
146 $x = $class->bzero(); ($x,$y) = $x->fdiv(1);
147 ok ($x,0); ok ($y,0);
149 $x = $class->new(2); $x->fzero(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
150 $x = $class->new(2); $x->finf(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
151 $x = $class->new(2); $x->fone(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
152 $x = $class->new(2); $x->fnan(); ok_undef ($x->{_a}); ok_undef ($x->{_p});
156 ###############################################################################
157 # Perl 5.005 does not like ok ($x,undef)
163 ok (1,1) and return if !defined $x;
241 1234.567:9::1234.56700
242 1234.567::-6:1234.567000
244 0.001234:6::0.00123400
245 0.001234::-8:0.00123400
264 000000_0000000_00000:0
275 -123456789:-123456789
283 -.0000000004:-0.0000000004
298 -3e111:-3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
299 -4e-1111:-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004
306 123.456:2:15241.383936
309 128:-2:0.00006103515625
323 +123456789:-123456789
325 +123.456789:-123.456789
326 -123456.789:123456.789
336 +123.456789:123.456789
337 -123456.789:123456.789
339 $round_mode = "trunc"
344 +10123456789:5:10123000000
345 -10123456789:5:-10123000000
346 +10123456789.123:5:10123000000
347 -10123456789.123:5:-10123000000
348 +10123456789:9:10123456700
349 -10123456789:9:-10123456700
350 +101234500:6:101234000
351 -101234500:6:-101234000
353 +20123456789:5:20123000000
354 -20123456789:5:-20123000000
355 +20123456789.123:5:20123000000
356 -20123456789.123:5:-20123000000
357 +20123456789:9:20123456800
358 -20123456789:9:-20123456800
359 +201234500:6:201234000
360 -201234500:6:-201234000
362 +30123456789:5:30123000000
363 -30123456789:5:-30123000000
364 +30123456789.123:5:30123000000
365 -30123456789.123:5:-30123000000
366 +30123456789:9:30123456800
367 -30123456789:9:-30123456800
368 +301234500:6:301235000
369 -301234500:6:-301234000
371 +40123456789:5:40123000000
372 -40123456789:5:-40123000000
373 +40123456789.123:5:40123000000
374 -40123456789.123:5:-40123000000
375 +40123456789:9:40123456800
376 -40123456789:9:-40123456800
377 +401234500:6:401234000
378 -401234500:6:-401235000
380 +50123456789:5:50123000000
381 -50123456789:5:-50123000000
382 +50123456789.123:5:50123000000
383 -50123456789.123:5:-50123000000
384 +50123456789:9:50123456800
385 -50123456789:9:-50123456800
386 +501234500:6:501235000
387 -501234500:6:-501235000
389 +60123456789:5:60123000000
390 -60123456789:5:-60123000000
391 +60123456789:9:60123456800
392 -60123456789:9:-60123456800
393 +601234500:6:601234000
394 -601234500:6:-601234000
395 +60123456789.0123:5:60123000000
396 -60123456789.0123:5:-60123000000
398 $round_mode = "trunc"
419 -0.0061234567890:-1:0.0
427 -0.0065:-3:/-0\.006|-6e-03
428 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
429 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
435 +2.23:-1:/2.2(?:0{5}\d+)?
436 -2.23:-1:/-2.2(?:0{5}\d+)?
437 +2.27:-1:/2.(?:3|29{5}\d+)
438 -2.27:-1:/-2.(?:3|29{5}\d+)
439 +2.25:-1:/2.2(?:0{5}\d+)?
440 -2.25:-1:/-2.2(?:0{5}\d+)?
441 +2.35:-1:/2.(?:3|29{5}\d+)
442 -2.35:-1:/-2.(?:3|29{5}\d+)
444 -0.0065:-2:/-0\.01|-1e-02
445 -0.0065:-3:/-0\.006|-6e-03
446 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
447 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
453 +3.23:-1:/3.2(?:0{5}\d+)?
454 -3.23:-1:/-3.2(?:0{5}\d+)?
455 +3.27:-1:/3.(?:3|29{5}\d+)
456 -3.27:-1:/-3.(?:3|29{5}\d+)
457 +3.25:-1:/3.(?:3|29{5}\d+)
458 -3.25:-1:/-3.2(?:0{5}\d+)?
459 +3.35:-1:/3.(?:4|39{5}\d+)
460 -3.35:-1:/-3.(?:3|29{5}\d+)
462 -0.0065:-2:/-0\.01|-1e-02
463 -0.0065:-3:/-0\.006|-6e-03
464 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
465 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
471 +4.23:-1:/4.2(?:0{5}\d+)?
472 -4.23:-1:/-4.2(?:0{5}\d+)?
473 +4.27:-1:/4.(?:3|29{5}\d+)
474 -4.27:-1:/-4.(?:3|29{5}\d+)
475 +4.25:-1:/4.2(?:0{5}\d+)?
476 -4.25:-1:/-4.(?:3|29{5}\d+)
477 +4.35:-1:/4.(?:3|29{5}\d+)
478 -4.35:-1:/-4.(?:4|39{5}\d+)
480 -0.0065:-2:/-0\.01|-1e-02
481 -0.0065:-3:/-0\.007|-7e-03
482 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
483 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
489 +5.23:-1:/5.2(?:0{5}\d+)?
490 -5.23:-1:/-5.2(?:0{5}\d+)?
491 +5.27:-1:/5.(?:3|29{5}\d+)
492 -5.27:-1:/-5.(?:3|29{5}\d+)
493 +5.25:-1:/5.(?:3|29{5}\d+)
494 -5.25:-1:/-5.(?:3|29{5}\d+)
495 +5.35:-1:/5.(?:3|29{5}\d+)
496 -5.35:-1:/-5.(?:3|29{5}\d+)
498 -0.0065:-2:/-0\.01|-1e-02
499 -0.0065:-3:/-0\.007|-7e-03
500 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
501 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
507 +6.23:-1:/6.2(?:0{5}\d+)?
508 -6.23:-1:/-6.2(?:0{5}\d+)?
509 +6.27:-1:/6.(?:3|29{5}\d+)
510 -6.27:-1:/-6.(?:3|29{5}\d+)
511 +6.25:-1:/6.(?:2(?:0{5}\d+)?|29{5}\d+)
512 -6.25:-1:/-6.(?:2(?:0{5}\d+)?|29{5}\d+)
513 +6.35:-1:/6.(?:4|39{5}\d+|29{8}\d+)
514 -6.35:-1:/-6.(?:4|39{5}\d+|29{8}\d+)
516 -0.0065:-2:/-0\.01|-1e-02
517 -0.0065:-3:/-0\.006|-7e-03
518 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
519 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
526 0.01234567:-5:0.01235
527 0.01234567:-6:0.012346
528 0.01234567:-7:0.0123457
529 0.01234567:-8:0.01234567
530 0.01234567:-9:0.012345670
531 0.01234567:-12:0.012345670000
733 +99999999:+1:100000000
734 +999999999:+1:1000000000
735 +9999999999:+1:10000000000
736 +99999999999:+1:100000000000
744 +100000000:-1:99999999
745 +1000000000:-1:999999999
746 +10000000000:-1:9999999999
747 +123456789:+987654321:1111111110
748 -123456789:+987654321:864197532
749 -123456789:-987654321:-1111111110
750 +123456789:-987654321:-864197532
751 0.001234:0.0001234:0.0013574
780 +99999999:+1:99999998
781 +999999999:+1:999999998
782 +9999999999:+1:9999999998
783 +99999999999:+1:99999999998
790 +10000000:-1:10000001
791 +100000000:-1:100000001
792 +1000000000:-1:1000000001
793 +10000000000:-1:10000000001
794 +123456789:+987654321:-864197532
795 -123456789:+987654321:-1111111110
796 -123456789:-987654321:864197532
797 +123456789:-987654321:1111111110
823 +123456789123456789:+0:0
824 +0:+123456789123456789:0
834 +10101:+10101:102030201
835 +1001001:+1001001:1002003002001
836 +100010001:+100010001:10002000300020001
837 +10000100001:+10000100001:100002000030000200001
838 +11111111111:+9:99999999999
839 +22222222222:+9:199999999998
840 +33333333333:+9:299999999997
841 +44444444444:+9:399999999996
842 +55555555555:+9:499999999995
843 +66666666666:+9:599999999994
844 +77777777777:+9:699999999993
845 +88888888888:+9:799999999992
846 +99999999999:+9:899999999991
850 $div_scale = 40; $round_mode = 'even'
876 +999999999999:+9:111111111111
877 +999999999999:+99:10101010101
878 +999999999999:+999:1001001001
879 +999999999999:+9999:100010001
880 +999999999999999:+99999:10000100001
881 +1000000000:+9:111111111.1111111111111111111111111111111
882 +2000000000:+9:222222222.2222222222222222222222222222222
883 +3000000000:+9:333333333.3333333333333333333333333333333
884 +4000000000:+9:444444444.4444444444444444444444444444444
885 +5000000000:+9:555555555.5555555555555555555555555555556
886 +6000000000:+9:666666666.6666666666666666666666666666667
887 +7000000000:+9:777777777.7777777777777777777777777777778
888 +8000000000:+9:888888888.8888888888888888888888888888889
889 +9000000000:+9:1000000000
890 +35500000:+113:314159.2920353982300884955752212389380531
891 +71000000:+226:314159.2920353982300884955752212389380531
892 +106500000:+339:314159.2920353982300884955752212389380531
893 +1000000000:+3:333333333.3333333333333333333333333333333
894 2:25.024996000799840031993601279744051189762:0.07992009269196593320152084692285869265447
897 +1000000000:+9:111111111.11111111111
898 +2000000000:+9:222222222.22222222222
899 +3000000000:+9:333333333.33333333333
900 +4000000000:+9:444444444.44444444444
901 +5000000000:+9:555555555.55555555556
902 +6000000000:+9:666666666.66666666667
903 +7000000000:+9:777777777.77777777778
904 +8000000000:+9:888888888.88888888889
905 +9000000000:+9:1000000000
910 1:504:0.001984126984126984127
911 2:1.987654321:1.0062111801179738436
912 123456789.123456789123456789123456789:1:123456789.12345678912
913 # the next two cases are the "old" behaviour, but are now (>v0.01) different
914 #+35500000:+113:314159.292035398230088
915 #+71000000:+226:314159.292035398230088
916 +35500000:+113:314159.29203539823009
917 +71000000:+226:314159.29203539823009
918 +106500000:+339:314159.29203539823009
919 +1000000000:+3:333333333.33333333333
921 # round to accuracy 1 after bdiv
923 123456789.1234:1:100000000
924 # reset scale for further tests
945 2:1.41421356237309504880168872420969807857
950 123.456:11.11107555549866648462149404118219234119
951 15241.38393:123.4559999756998444766131352122991626468
953 # sqrt(1.44) = 1.2, sqrt(e10) = e5 => 12e4
955 2e10:141421.356237309504880168872420969807857
972 # it must be exactly /^[+-]inf$/
1051 12345678901234567890:20