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->b$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 "fmod") {
93 } else { warn "Unknown op '$f'"; }
95 # print "# Trying: '$try'\n";
97 if ($ans =~ m|^/(.*)$|)
106 print "# '$try' expected: /$pat/ got: '$ans1'\n" if !ok(1,0);
117 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
118 if (ref($ans1) eq "$class")
120 # float numbers are normalized (for now), so mantissa shouldn't have
122 #print $ans1->_trailing_zeros(),"\n";
123 print "# Has trailing zeros after '$try'\n"
124 if !ok ($ans1->{_m}->_trailing_zeros(), 0);
127 } # end pattern or string
131 # check whether new() for BigInts destroys them ($y == 12 in this case)
132 $x = Math::BigInt->new(1200); $y = $class->new($x);
133 ok ($y,1200); ok ($x,1200);
135 ###############################################################################
136 # fdiv() in list context
137 $x = $class->bzero(); ($x,$y) = $x->fdiv(0);
138 ok ($x,'NaN'); ok ($y,'NaN');
140 # fdiv() in list context
141 $x = $class->bzero(); ($x,$y) = $x->fdiv(1);
142 ok ($x,0); ok ($y,0);
146 ###############################################################################
147 # Perl 5.005 does not like ok ($x,undef)
153 ok (1,1) and return if !defined $x;
216 1234.567:9::1234.56700
217 1234.567::-6:1234.567000
219 0.001234:6::0.00123400
220 0.001234::-8:0.00123400
239 000000_0000000_00000:0
250 -123456789:-123456789
258 -.0000000004:-0.0000000004
273 -3e111:-3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
274 -4e-1111:-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004
281 123.456:2:15241.383936
284 128:-2:0.00006103515625
298 +123456789:-123456789
300 +123.456789:-123.456789
301 -123456.789:123456.789
311 +123.456789:123.456789
312 -123456.789:123456.789
314 $round_mode = "trunc"
319 +10123456789:5:10123000000
320 -10123456789:5:-10123000000
321 +10123456789.123:5:10123000000
322 -10123456789.123:5:-10123000000
323 +10123456789:9:10123456700
324 -10123456789:9:-10123456700
325 +101234500:6:101234000
326 -101234500:6:-101234000
328 +20123456789:5:20123000000
329 -20123456789:5:-20123000000
330 +20123456789.123:5:20123000000
331 -20123456789.123:5:-20123000000
332 +20123456789:9:20123456800
333 -20123456789:9:-20123456800
334 +201234500:6:201234000
335 -201234500:6:-201234000
337 +30123456789:5:30123000000
338 -30123456789:5:-30123000000
339 +30123456789.123:5:30123000000
340 -30123456789.123:5:-30123000000
341 +30123456789:9:30123456800
342 -30123456789:9:-30123456800
343 +301234500:6:301235000
344 -301234500:6:-301234000
346 +40123456789:5:40123000000
347 -40123456789:5:-40123000000
348 +40123456789.123:5:40123000000
349 -40123456789.123:5:-40123000000
350 +40123456789:9:40123456800
351 -40123456789:9:-40123456800
352 +401234500:6:401234000
353 -401234500:6:-401235000
355 +50123456789:5:50123000000
356 -50123456789:5:-50123000000
357 +50123456789.123:5:50123000000
358 -50123456789.123:5:-50123000000
359 +50123456789:9:50123456800
360 -50123456789:9:-50123456800
361 +501234500:6:501235000
362 -501234500:6:-501235000
364 +60123456789:5:60123000000
365 -60123456789:5:-60123000000
366 +60123456789:9:60123456800
367 -60123456789:9:-60123456800
368 +601234500:6:601234000
369 -601234500:6:-601234000
370 +60123456789.0123:5:60123000000
371 -60123456789.0123:5:-60123000000
373 $round_mode = "trunc"
394 -0.0061234567890:-1:0.0
402 -0.0065:-3:/-0\.006|-6e-03
403 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
404 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
410 +2.23:-1:/2.2(?:0{5}\d+)?
411 -2.23:-1:/-2.2(?:0{5}\d+)?
412 +2.27:-1:/2.(?:3|29{5}\d+)
413 -2.27:-1:/-2.(?:3|29{5}\d+)
414 +2.25:-1:/2.2(?:0{5}\d+)?
415 -2.25:-1:/-2.2(?:0{5}\d+)?
416 +2.35:-1:/2.(?:3|29{5}\d+)
417 -2.35:-1:/-2.(?:3|29{5}\d+)
419 -0.0065:-2:/-0\.01|-1e-02
420 -0.0065:-3:/-0\.006|-6e-03
421 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
422 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
428 +3.23:-1:/3.2(?:0{5}\d+)?
429 -3.23:-1:/-3.2(?:0{5}\d+)?
430 +3.27:-1:/3.(?:3|29{5}\d+)
431 -3.27:-1:/-3.(?:3|29{5}\d+)
432 +3.25:-1:/3.(?:3|29{5}\d+)
433 -3.25:-1:/-3.2(?:0{5}\d+)?
434 +3.35:-1:/3.(?:4|39{5}\d+)
435 -3.35:-1:/-3.(?:3|29{5}\d+)
437 -0.0065:-2:/-0\.01|-1e-02
438 -0.0065:-3:/-0\.006|-6e-03
439 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
440 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
446 +4.23:-1:/4.2(?:0{5}\d+)?
447 -4.23:-1:/-4.2(?:0{5}\d+)?
448 +4.27:-1:/4.(?:3|29{5}\d+)
449 -4.27:-1:/-4.(?:3|29{5}\d+)
450 +4.25:-1:/4.2(?:0{5}\d+)?
451 -4.25:-1:/-4.(?:3|29{5}\d+)
452 +4.35:-1:/4.(?:3|29{5}\d+)
453 -4.35:-1:/-4.(?:4|39{5}\d+)
455 -0.0065:-2:/-0\.01|-1e-02
456 -0.0065:-3:/-0\.007|-7e-03
457 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
458 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
464 +5.23:-1:/5.2(?:0{5}\d+)?
465 -5.23:-1:/-5.2(?:0{5}\d+)?
466 +5.27:-1:/5.(?:3|29{5}\d+)
467 -5.27:-1:/-5.(?:3|29{5}\d+)
468 +5.25:-1:/5.(?:3|29{5}\d+)
469 -5.25:-1:/-5.(?:3|29{5}\d+)
470 +5.35:-1:/5.(?:3|29{5}\d+)
471 -5.35:-1:/-5.(?:3|29{5}\d+)
473 -0.0065:-2:/-0\.01|-1e-02
474 -0.0065:-3:/-0\.007|-7e-03
475 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
476 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
482 +6.23:-1:/6.2(?:0{5}\d+)?
483 -6.23:-1:/-6.2(?:0{5}\d+)?
484 +6.27:-1:/6.(?:3|29{5}\d+)
485 -6.27:-1:/-6.(?:3|29{5}\d+)
486 +6.25:-1:/6.(?:2(?:0{5}\d+)?|29{5}\d+)
487 -6.25:-1:/-6.(?:2(?:0{5}\d+)?|29{5}\d+)
488 +6.35:-1:/6.(?:4|39{5}\d+|29{8}\d+)
489 -6.35:-1:/-6.(?:4|39{5}\d+|29{8}\d+)
491 -0.0065:-2:/-0\.01|-1e-02
492 -0.0065:-3:/-0\.006|-7e-03
493 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
494 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
501 0.01234567:-5:0.01235
502 0.01234567:-6:0.012346
503 0.01234567:-7:0.0123457
504 0.01234567:-8:0.01234567
505 0.01234567:-9:0.012345670
506 0.01234567:-12:0.012345670000
708 +99999999:+1:100000000
709 +999999999:+1:1000000000
710 +9999999999:+1:10000000000
711 +99999999999:+1:100000000000
719 +100000000:-1:99999999
720 +1000000000:-1:999999999
721 +10000000000:-1:9999999999
722 +123456789:+987654321:1111111110
723 -123456789:+987654321:864197532
724 -123456789:-987654321:-1111111110
725 +123456789:-987654321:-864197532
726 0.001234:0.0001234:0.0013574
755 +99999999:+1:99999998
756 +999999999:+1:999999998
757 +9999999999:+1:9999999998
758 +99999999999:+1:99999999998
765 +10000000:-1:10000001
766 +100000000:-1:100000001
767 +1000000000:-1:1000000001
768 +10000000000:-1:10000000001
769 +123456789:+987654321:-864197532
770 -123456789:+987654321:-1111111110
771 -123456789:-987654321:864197532
772 +123456789:-987654321:1111111110
798 +123456789123456789:+0:0
799 +0:+123456789123456789:0
809 +10101:+10101:102030201
810 +1001001:+1001001:1002003002001
811 +100010001:+100010001:10002000300020001
812 +10000100001:+10000100001:100002000030000200001
813 +11111111111:+9:99999999999
814 +22222222222:+9:199999999998
815 +33333333333:+9:299999999997
816 +44444444444:+9:399999999996
817 +55555555555:+9:499999999995
818 +66666666666:+9:599999999994
819 +77777777777:+9:699999999993
820 +88888888888:+9:799999999992
821 +99999999999:+9:899999999991
825 $div_scale = 40; $round_mode = 'even'
851 +999999999999:+9:111111111111
852 +999999999999:+99:10101010101
853 +999999999999:+999:1001001001
854 +999999999999:+9999:100010001
855 +999999999999999:+99999:10000100001
856 +1000000000:+9:111111111.1111111111111111111111111111111
857 +2000000000:+9:222222222.2222222222222222222222222222222
858 +3000000000:+9:333333333.3333333333333333333333333333333
859 +4000000000:+9:444444444.4444444444444444444444444444444
860 +5000000000:+9:555555555.5555555555555555555555555555556
861 +6000000000:+9:666666666.6666666666666666666666666666667
862 +7000000000:+9:777777777.7777777777777777777777777777778
863 +8000000000:+9:888888888.8888888888888888888888888888889
864 +9000000000:+9:1000000000
865 +35500000:+113:314159.2920353982300884955752212389380531
866 +71000000:+226:314159.2920353982300884955752212389380531
867 +106500000:+339:314159.2920353982300884955752212389380531
868 +1000000000:+3:333333333.3333333333333333333333333333333
869 2:25.024996000799840031993601279744051189762:0.07992009269196593320152084692285869265447
871 +1000000000:+9:111111111.11111111111
872 +2000000000:+9:222222222.22222222222
873 +3000000000:+9:333333333.33333333333
874 +4000000000:+9:444444444.44444444444
875 +5000000000:+9:555555555.55555555556
876 +6000000000:+9:666666666.66666666667
877 +7000000000:+9:777777777.77777777778
878 +8000000000:+9:888888888.88888888889
879 +9000000000:+9:1000000000
884 1:504:0.001984126984126984127
885 2:1.987654321:1.0062111801179738436
886 # the next two cases are the "old" behaviour, but are now (>v0.01) different
887 #+35500000:+113:314159.292035398230088
888 #+71000000:+226:314159.292035398230088
889 +35500000:+113:314159.29203539823009
890 +71000000:+226:314159.29203539823009
891 +106500000:+339:314159.29203539823009
892 +1000000000:+3:333333333.33333333333
894 # round to accuracy 1 after bdiv
896 # reset scale for further tests
917 +2:1.41421356237309504880168872420969807857
921 +123.456:11.11107555549866648462149404118219234119
922 +15241.38393:123.4559999756998444766131352122991626468
940 # it must be exactly /^[+-]inf$/
1019 12345678901234567890:20