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 "fnan") {
35 $try .= "\$x->fnan();";
36 } elsif ($f eq "numify") {
37 $try .= "\$x->numify();";
38 } elsif ($f eq "fone") {
39 $try .= "\$x->bone('$args[1]');";
40 } elsif ($f eq "fstr") {
41 $try .= "\$x->accuracy($args[1]); \$x->precision($args[2]);";
42 $try .= '$x->fstr();';
43 } elsif ($f eq "fsstr") {
44 $try .= '$x->fsstr();';
45 } elsif ($f eq "parts") {
46 # ->bstr() to see if an object is returned
47 $try .= '($a,$b) = $x->parts(); $a = $a->bstr(); $b = $b->bstr();';
49 } elsif ($f eq "length") {
50 $try .= '$x->length();';
51 } elsif ($f eq "exponent") {
52 # ->bstr() to see if an object is returned
53 $try .= '$x->exponent()->bstr();';
54 } elsif ($f eq "mantissa") {
55 # ->bstr() to see if an object is returned
56 $try .= '$x->mantissa()->bstr();';
57 } elsif ($f eq "fneg") {
58 $try .= '$x->bneg();';
59 } elsif ($f eq "fnorm") {
60 $try .= '$x->fnorm();';
61 } elsif ($f eq "bfloor") {
62 $try .= '$x->ffloor();';
63 } elsif ($f eq "bceil") {
64 $try .= '$x->fceil();';
65 } elsif ($f eq "is_zero") {
66 $try .= '$x->is_zero();';
67 } elsif ($f eq "is_one") {
68 $try .= '$x->is_one();';
69 } elsif ($f eq "is_positive") {
70 $try .= '$x->is_positive();';
71 } elsif ($f eq "is_negative") {
72 $try .= '$x->is_negative();';
73 } elsif ($f eq "is_odd") {
74 $try .= '$x->is_odd();';
75 } elsif ($f eq "is_even") {
76 $try .= '$x->is_even();';
77 } elsif ($f eq "as_number") {
78 $try .= '$x->as_number();';
79 } elsif ($f eq "fabs") {
80 $try .= '$x->fabs();';
81 } elsif ($f eq "finc") {
83 } elsif ($f eq "fdec") {
85 }elsif ($f eq "fround") {
86 $try .= "$setup; \$x->fround($args[1]);";
87 } elsif ($f eq "ffround") {
88 $try .= "$setup; \$x->ffround($args[1]);";
89 } elsif ($f eq "fsqrt") {
90 $try .= "$setup; \$x->fsqrt();";
94 $try .= "\$y = new $class \"$args[1]\";";
97 } elsif ($f eq "facmp") {
98 $try .= '$x->facmp($y);';
99 } elsif ($f eq "fpow") {
101 } elsif ($f eq "fadd") {
103 } elsif ($f eq "fsub") {
105 } elsif ($f eq "fmul") {
107 } elsif ($f eq "fdiv") {
108 $try .= "$setup; \$x / \$y;";
109 } elsif ($f eq "fmod") {
111 } else { warn "Unknown op '$f'"; }
113 # print "# Trying: '$try'\n";
115 if ($ans =~ m|^/(.*)$|)
124 print "# '$try' expected: /$pat/ got: '$ans1'\n" if !ok(1,0);
135 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
136 if (ref($ans1) eq "$class")
138 #print $ans1->_trailing_zeros(),"\n";
139 print "# Has trailing zeros after '$try'\n"
140 if !ok ($ans1->{_m}->_trailing_zeros(), 0);
143 } # end pattern or string
147 # check whether new() for BigInts destroys them ($y == 12 in this case)
148 $x = Math::BigInt->new(1200); $y = $class->new($x);
149 ok ($y,1200); ok ($x,1200);
151 ###############################################################################
152 # fdiv() in list context
153 $x = $class->bzero(); ($x,$y) = $x->fdiv(0);
154 ok ($x,'NaN'); ok ($y,'NaN');
156 # fdiv() in list context
157 $x = $class->bzero(); ($x,$y) = $x->fdiv(1);
158 ok ($x,0); ok ($y,0);
162 ###############################################################################
163 # Perl 5.005 does not like ok ($x,undef)
169 ok (1,1) and return if !defined $x;
224 1234.567:9::1234.56700
225 1234.567::-6:1234.567000
227 0.001234:6::0.00123400
228 0.001234::-8:0.00123400
247 000000_0000000_00000:0
258 -123456789:-123456789
266 -.0000000004:-0.0000000004
281 -3e111:-3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
282 -4e-1111:-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004
289 123.456:2:15241.383936
292 128:-2:0.00006103515625
306 +123456789:-123456789
308 +123.456789:-123.456789
309 -123456.789:123456.789
319 +123.456789:123.456789
320 -123456.789:123456.789
322 $round_mode = "trunc"
327 +10123456789:5:10123000000
328 -10123456789:5:-10123000000
329 +10123456789.123:5:10123000000
330 -10123456789.123:5:-10123000000
331 +10123456789:9:10123456700
332 -10123456789:9:-10123456700
333 +101234500:6:101234000
334 -101234500:6:-101234000
336 +20123456789:5:20123000000
337 -20123456789:5:-20123000000
338 +20123456789.123:5:20123000000
339 -20123456789.123:5:-20123000000
340 +20123456789:9:20123456800
341 -20123456789:9:-20123456800
342 +201234500:6:201234000
343 -201234500:6:-201234000
345 +30123456789:5:30123000000
346 -30123456789:5:-30123000000
347 +30123456789.123:5:30123000000
348 -30123456789.123:5:-30123000000
349 +30123456789:9:30123456800
350 -30123456789:9:-30123456800
351 +301234500:6:301235000
352 -301234500:6:-301234000
354 +40123456789:5:40123000000
355 -40123456789:5:-40123000000
356 +40123456789.123:5:40123000000
357 -40123456789.123:5:-40123000000
358 +40123456789:9:40123456800
359 -40123456789:9:-40123456800
360 +401234500:6:401234000
361 -401234500:6:-401235000
363 +50123456789:5:50123000000
364 -50123456789:5:-50123000000
365 +50123456789.123:5:50123000000
366 -50123456789.123:5:-50123000000
367 +50123456789:9:50123456800
368 -50123456789:9:-50123456800
369 +501234500:6:501235000
370 -501234500:6:-501235000
372 +60123456789:5:60123000000
373 -60123456789:5:-60123000000
374 +60123456789:9:60123456800
375 -60123456789:9:-60123456800
376 +601234500:6:601234000
377 -601234500:6:-601234000
378 +60123456789.0123:5:60123000000
379 -60123456789.0123:5:-60123000000
381 $round_mode = "trunc"
402 -0.0061234567890:-1:0.0
410 -0.0065:-3:/-0\.006|-6e-03
411 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
412 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
418 +2.23:-1:/2.2(?:0{5}\d+)?
419 -2.23:-1:/-2.2(?:0{5}\d+)?
420 +2.27:-1:/2.(?:3|29{5}\d+)
421 -2.27:-1:/-2.(?:3|29{5}\d+)
422 +2.25:-1:/2.2(?:0{5}\d+)?
423 -2.25:-1:/-2.2(?:0{5}\d+)?
424 +2.35:-1:/2.(?:3|29{5}\d+)
425 -2.35:-1:/-2.(?:3|29{5}\d+)
427 -0.0065:-2:/-0\.01|-1e-02
428 -0.0065:-3:/-0\.006|-6e-03
429 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
430 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
436 +3.23:-1:/3.2(?:0{5}\d+)?
437 -3.23:-1:/-3.2(?:0{5}\d+)?
438 +3.27:-1:/3.(?:3|29{5}\d+)
439 -3.27:-1:/-3.(?:3|29{5}\d+)
440 +3.25:-1:/3.(?:3|29{5}\d+)
441 -3.25:-1:/-3.2(?:0{5}\d+)?
442 +3.35:-1:/3.(?:4|39{5}\d+)
443 -3.35:-1:/-3.(?:3|29{5}\d+)
445 -0.0065:-2:/-0\.01|-1e-02
446 -0.0065:-3:/-0\.006|-6e-03
447 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
448 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
454 +4.23:-1:/4.2(?:0{5}\d+)?
455 -4.23:-1:/-4.2(?:0{5}\d+)?
456 +4.27:-1:/4.(?:3|29{5}\d+)
457 -4.27:-1:/-4.(?:3|29{5}\d+)
458 +4.25:-1:/4.2(?:0{5}\d+)?
459 -4.25:-1:/-4.(?:3|29{5}\d+)
460 +4.35:-1:/4.(?:3|29{5}\d+)
461 -4.35:-1:/-4.(?:4|39{5}\d+)
463 -0.0065:-2:/-0\.01|-1e-02
464 -0.0065:-3:/-0\.007|-7e-03
465 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
466 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
472 +5.23:-1:/5.2(?:0{5}\d+)?
473 -5.23:-1:/-5.2(?:0{5}\d+)?
474 +5.27:-1:/5.(?:3|29{5}\d+)
475 -5.27:-1:/-5.(?:3|29{5}\d+)
476 +5.25:-1:/5.(?:3|29{5}\d+)
477 -5.25:-1:/-5.(?:3|29{5}\d+)
478 +5.35:-1:/5.(?:3|29{5}\d+)
479 -5.35:-1:/-5.(?:3|29{5}\d+)
481 -0.0065:-2:/-0\.01|-1e-02
482 -0.0065:-3:/-0\.007|-7e-03
483 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
484 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
490 +6.23:-1:/6.2(?:0{5}\d+)?
491 -6.23:-1:/-6.2(?:0{5}\d+)?
492 +6.27:-1:/6.(?:3|29{5}\d+)
493 -6.27:-1:/-6.(?:3|29{5}\d+)
494 +6.25:-1:/6.(?:2(?:0{5}\d+)?|29{5}\d+)
495 -6.25:-1:/-6.(?:2(?:0{5}\d+)?|29{5}\d+)
496 +6.35:-1:/6.(?:4|39{5}\d+|29{8}\d+)
497 -6.35:-1:/-6.(?:4|39{5}\d+|29{8}\d+)
499 -0.0065:-2:/-0\.01|-1e-02
500 -0.0065:-3:/-0\.006|-7e-03
501 -0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
502 -0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03
509 0.01234567:-5:0.01235
510 0.01234567:-6:0.012346
511 0.01234567:-7:0.0123457
512 0.01234567:-8:0.01234567
513 0.01234567:-9:0.012345670
514 0.01234567:-12:0.012345670000
716 +99999999:+1:100000000
717 +999999999:+1:1000000000
718 +9999999999:+1:10000000000
719 +99999999999:+1:100000000000
727 +100000000:-1:99999999
728 +1000000000:-1:999999999
729 +10000000000:-1:9999999999
730 +123456789:+987654321:1111111110
731 -123456789:+987654321:864197532
732 -123456789:-987654321:-1111111110
733 +123456789:-987654321:-864197532
734 0.001234:0.0001234:0.0013574
763 +99999999:+1:99999998
764 +999999999:+1:999999998
765 +9999999999:+1:9999999998
766 +99999999999:+1:99999999998
773 +10000000:-1:10000001
774 +100000000:-1:100000001
775 +1000000000:-1:1000000001
776 +10000000000:-1:10000000001
777 +123456789:+987654321:-864197532
778 -123456789:+987654321:-1111111110
779 -123456789:-987654321:864197532
780 +123456789:-987654321:1111111110
806 +123456789123456789:+0:0
807 +0:+123456789123456789:0
817 +10101:+10101:102030201
818 +1001001:+1001001:1002003002001
819 +100010001:+100010001:10002000300020001
820 +10000100001:+10000100001:100002000030000200001
821 +11111111111:+9:99999999999
822 +22222222222:+9:199999999998
823 +33333333333:+9:299999999997
824 +44444444444:+9:399999999996
825 +55555555555:+9:499999999995
826 +66666666666:+9:599999999994
827 +77777777777:+9:699999999993
828 +88888888888:+9:799999999992
829 +99999999999:+9:899999999991
833 $div_scale = 40; $round_mode = 'even'
859 +999999999999:+9:111111111111
860 +999999999999:+99:10101010101
861 +999999999999:+999:1001001001
862 +999999999999:+9999:100010001
863 +999999999999999:+99999:10000100001
864 +1000000000:+9:111111111.1111111111111111111111111111111
865 +2000000000:+9:222222222.2222222222222222222222222222222
866 +3000000000:+9:333333333.3333333333333333333333333333333
867 +4000000000:+9:444444444.4444444444444444444444444444444
868 +5000000000:+9:555555555.5555555555555555555555555555556
869 +6000000000:+9:666666666.6666666666666666666666666666667
870 +7000000000:+9:777777777.7777777777777777777777777777778
871 +8000000000:+9:888888888.8888888888888888888888888888889
872 +9000000000:+9:1000000000
873 +35500000:+113:314159.2920353982300884955752212389380531
874 +71000000:+226:314159.2920353982300884955752212389380531
875 +106500000:+339:314159.2920353982300884955752212389380531
876 +1000000000:+3:333333333.3333333333333333333333333333333
877 2:25.024996000799840031993601279744051189762:0.07992009269196593320152084692285869265447
879 +1000000000:+9:111111111.11111111111
880 +2000000000:+9:222222222.22222222222
881 +3000000000:+9:333333333.33333333333
882 +4000000000:+9:444444444.44444444444
883 +5000000000:+9:555555555.55555555556
884 +6000000000:+9:666666666.66666666667
885 +7000000000:+9:777777777.77777777778
886 +8000000000:+9:888888888.88888888889
887 +9000000000:+9:1000000000
892 1:504:0.001984126984126984127
893 2:1.987654321:1.0062111801179738436
894 # the next two cases are the "old" behaviour, but are now (>v0.01) different
895 #+35500000:+113:314159.292035398230088
896 #+71000000:+226:314159.292035398230088
897 +35500000:+113:314159.29203539823009
898 +71000000:+226:314159.29203539823009
899 +106500000:+339:314159.29203539823009
900 +1000000000:+3:333333333.33333333333
902 # round to accuracy 1 after bdiv
904 # reset scale for further tests
925 +2:1.41421356237309504880168872420969807857
929 +123.456:11.11107555549866648462149404118219234119
930 +15241.38393:123.4559999756998444766131352122991626468
1008 12345678901234567890:20