diff options
Diffstat (limited to 'cpan/Math-BigInt/t/bigfltpm.inc')
-rw-r--r-- | cpan/Math-BigInt/t/bigfltpm.inc | 842 |
1 files changed, 529 insertions, 313 deletions
diff --git a/cpan/Math-BigInt/t/bigfltpm.inc b/cpan/Math-BigInt/t/bigfltpm.inc index 158b3aa811..10d05137df 100644 --- a/cpan/Math-BigInt/t/bigfltpm.inc +++ b/cpan/Math-BigInt/t/bigfltpm.inc @@ -1,209 +1,193 @@ #include this file into another test for subclass testing... -is ($class->config()->{lib},$CL); - use strict; +use warnings; + +our ($CLASS, $CALC); + +is($CLASS->config()->{lib}, $CALC, "$CLASS->config()->{lib}"); + +my ($x, $y, $z, @args, $try, $want, $got); +my ($f, $setup); + +while (<DATA>) { + s/#.*$//; # remove comments + s/\s+$//; # remove trailing whitespace + next unless length; # skip empty lines -my $z; - -while (<DATA>) - { - $_ =~ s/[\n\r]//g; # remove newlines - $_ =~ s/#.*$//; # remove comments - $_ =~ s/\s+$//; # trailing spaces - next if /^$/; # skip empty lines & comments - if (s/^&//) - { - $f = $_; + + if (s/^&//) { + $f = $_; + next; + } + + if (/^\$/) { + $setup = $_; + $setup =~ s/\$/\$${CLASS}::/g; # round_mode, div_scale + #print "\$setup== $setup\n"; + next; } - elsif (/^\$/) - { - $setup = $_; $setup =~ s/\$/\$${class}::/g; # round_mode, div_scale - #print "\$setup== $setup\n"; + + if (m|^(.*?):(/.+)$|) { + $want = $2; + @args = split(/:/, $1, 99); + } else { + @args = split(/:/, $_, 99); + $want = pop(@args); } - else - { - if (m|^(.*?):(/.+)$|) - { - $ans = $2; - @args = split(/:/,$1,99); - } - else - { - @args = split(/:/,$_,99); $ans = pop(@args); - } - $try = "\$x = $class->new(\"$args[0]\");"; - if ($f eq "bnorm") - { - $try .= "\$x;"; - } elsif ($f eq "binf") { - $try .= "\$x->binf('$args[1]');"; - } elsif ($f eq "is_inf") { - $try .= "\$x->is_inf('$args[1]');"; - } elsif ($f eq "bone") { - $try .= "\$x->bone('$args[1]');"; - } elsif ($f eq "bstr") { - $try .= "\$x->accuracy($args[1]); \$x->precision($args[2]);"; - $try .= '$x->bstr();'; - } elsif ($f eq "parts") { + + $try = qq|\$x = $CLASS->new("$args[0]");|; + if ($f eq "bnorm") { + $try .= qq| \$x;|; + } elsif ($f =~ /^is_(zero|one|negative|positive|odd|even|nan|int)$/) { + $try .= qq| \$x->$f();|; + } elsif ($f eq "is_inf") { + $try .= qq| \$x->is_inf("$args[1]");|; + } elsif ($f eq "binf") { + $try .= qq| \$x->binf("$args[1]");|; + } elsif ($f eq "bone") { + $try .= qq| \$x->bone("$args[1]");|; + } elsif ($f eq "bstr") { + $try .= qq| \$x->accuracy($args[1]); \$x->precision($args[2]);|; + $try .= ' $x->bstr();'; + # some unary ops + } elsif ($f =~ /^b(nan|sstr|neg|floor|ceil|int|abs)$/) { + $try .= qq| \$x->$f();|; + # overloaded functions + } elsif ($f =~ /^(log|exp|sin|cos|atan2|int|neg|abs|sqrt)$/) { + $try .= qq| \$x = $f(\$x);|; + } elsif ($f eq "parts") { # ->bstr() to see if an object is returned - $try .= '($a,$b) = $x->parts(); $a = $a->bstr(); $b = $b->bstr();'; - $try .= '"$a $b";'; - } elsif ($f eq "exponent") { + $try .= ' ($a, $b) = $x->parts(); $a = $a->bstr(); $b = $b->bstr();'; + $try .= ' "$a $b";'; + } elsif ($f eq "exponent") { # ->bstr() to see if an object is returned - $try .= '$x->exponent()->bstr();'; - } elsif ($f eq "mantissa") { + $try .= ' $x->exponent()->bstr();'; + } elsif ($f eq "mantissa") { # ->bstr() to see if an object is returned - $try .= '$x->mantissa()->bstr();'; - } elsif ($f =~ /^(numify|length|as_number|as_hex|as_bin)$/) { - $try .= "\$x->$f();"; - # some unary ops - } elsif ($f =~ /^b(nan|sstr|neg|floor|ceil|int|abs)$/) { - $try .= "\$x->$f();"; - # overloaded functions - } elsif ($f =~ /^(log|exp|sin|cos|atan2|int|neg|abs|sqrt)$/) { - $try .= "\$x = $f(\$x);"; - # some is_xxx test function - } elsif ($f =~ /^is_(zero|one|negative|positive|odd|even|nan|int)$/) { - $try .= "\$x->$f();"; - } elsif ($f eq "bpi") { - $try .= '$class->bpi($x);'; - } elsif ($f eq "binc") { - $try .= '++$x;'; - } elsif ($f eq "bdec") { - $try .= '--$x;'; - }elsif ($f eq "bround") { - $try .= "$setup; \$x->bround($args[1]);"; - } elsif ($f eq "bfround") { - $try .= "$setup; \$x->bfround($args[1]);"; - } elsif ($f eq "bsqrt") { - $try .= "$setup; \$x->bsqrt();"; - } elsif ($f eq "bfac") { - $try .= "$setup; \$x->bfac();"; - } elsif ($f eq "blog") { - if (defined $args[1] && $args[1] ne '') - { - $try .= "\$y = $class->new($args[1]);"; - $try .= "$setup; \$x->blog(\$y);"; - } - else - { - $try .= "$setup; \$x->blog();"; - } - } - else - { - $try .= "\$y = $class->new(\"$args[1]\");"; - - if ($f eq "bgcd") - { - if (defined $args[2]) - { - $try .= " \$z = $class->new(\"$args[2]\"); "; - } - $try .= "$class\::bgcd(\$x, \$y"; - $try .= ", \$z" if (defined $args[2]); - $try .= " );"; + $try .= ' $x->mantissa()->bstr();'; + } elsif ($f =~ /^(numify|length|as_number|as_hex|as_bin)$/) { + $try .= qq| \$x->$f();|; + } elsif ($f eq "bpi") { + $try .= qq| $CLASS->bpi(\$x);|; + } elsif ($f eq "binc") { + $try .= ' ++$x;'; + } elsif ($f eq "bdec") { + $try .= ' --$x;'; + } elsif ($f eq "bround") { + $try .= qq| $setup; \$x->bround($args[1]);|; + } elsif ($f eq "bfround") { + $try .= qq| $setup; \$x->bfround($args[1]);|; + } elsif ($f eq "bsqrt") { + $try .= qq| $setup; \$x->bsqrt();|; + } elsif ($f eq "bfac") { + $try .= qq| $setup; \$x->bfac();|; + } elsif ($f eq "blog") { + if (defined $args[1] && $args[1] ne '') { + $try .= qq| \$y = $CLASS->new($args[1]);|; + $try .= qq| $setup; \$x->blog(\$y);|; + } else { + $try .= qq| $setup; \$x->blog();|; + } + } else { + # binary operators + $try .= qq| \$y = $CLASS->new("$args[1]");|; + + if ($f eq "bgcd") { + if (defined $args[2]) { + $try .= qq| \$z = $CLASS->new("$args[2]");|; + } + $try .= qq| $CLASS\::bgcd(\$x, \$y|; + $try .= qq|, \$z| if defined $args[2]; + $try .= qq|);|; + } elsif ($f eq "blcm") { + if (defined $args[2]) { + $try .= qq| \$z = $CLASS->new("$args[2]");|; + } + $try .= qq| $CLASS\::blcm(\$x, \$y|; + $try .= qq|, \$z| if defined $args[2]; + $try .= qq|);|; + } elsif ($f eq "bcmp") { + $try .= ' $x->bcmp($y);'; + } elsif ($f eq "bacmp") { + $try .= ' $x->bacmp($y);'; + } elsif ($f eq "bpow") { + $try .= ' $x ** $y;'; + } elsif ($f eq "bnok") { + $try .= ' $x->bnok($y);'; + } elsif ($f eq "bcos") { + $try .= ' $x->bcos($y);'; + } elsif ($f eq "bsin") { + $try .= ' $x->bsin($y);'; + } elsif ($f eq "batan") { + $try .= ' $x->batan($y);'; + } elsif ($f eq "broot") { + $try .= qq| $setup; \$x->broot(\$y);|; + } elsif ($f eq "badd") { + $try .= ' $x + $y;'; + } elsif ($f eq "bsub") { + $try .= ' $x - $y;'; + } elsif ($f eq "bmul") { + $try .= ' $x * $y;'; + } elsif ($f eq "bdiv") { + $try .= qq| $setup; \$x / \$y;|; + } elsif ($f eq "bdiv-list") { + $try .= qq| $setup; join(",", \$x->bdiv(\$y));|; + } elsif ($f eq "brsft") { + $try .= ' $x >> $y;'; + } elsif ($f eq "blsft") { + $try .= ' $x << $y;'; + } elsif ($f eq "bmod") { + $try .= ' $x % $y;'; + } else { + # Functions with three arguments + $try .= qq| \$z = $CLASS->new("$args[2]");|; + + if ($f eq "bmodpow") { + $try .= ' $x->bmodpow($y, $z);'; + } elsif ($f eq "bmuladd") { + $try .= ' $x->bmuladd($y, $z);'; + } elsif ($f eq "batan2") { + $try .= ' $x->batan2($y, $z);'; + } else { + warn qq|Unknown op "$f"|; + } } - elsif ($f eq "blcm") - { - if (defined $args[2]) - { - $try .= " \$z = $class->new(\"$args[2]\"); "; - } - $try .= "$class\::blcm(\$x, \$y"; - $try .= ", \$z" if (defined $args[2]); - $try .= " );"; - } elsif ($f eq "bcmp") { - $try .= '$x->bcmp($y);'; - } elsif ($f eq "bacmp") { - $try .= '$x->bacmp($y);'; - } elsif ($f eq "bpow") { - $try .= '$x ** $y;'; - } elsif ($f eq "bnok") { - $try .= '$x->bnok($y);'; - } elsif ($f eq "bcos") { - $try .= '$x->bcos($y);'; - } elsif ($f eq "bsin") { - $try .= '$x->bsin($y);'; - } elsif ($f eq "batan") { - $try .= '$x->batan($y);'; - } elsif ($f eq "broot") { - $try .= "$setup; \$x->broot(\$y);"; - } elsif ($f eq "badd") { - $try .= '$x + $y;'; - } elsif ($f eq "bsub") { - $try .= '$x - $y;'; - } elsif ($f eq "bmul") { - $try .= '$x * $y;'; - } elsif ($f eq "bdiv") { - $try .= "$setup; \$x / \$y;"; - } elsif ($f eq "bdiv-list") { - $try .= "$setup; join(',',\$x->bdiv(\$y));"; - } elsif ($f eq "brsft") { - $try .= '$x >> $y;'; - } elsif ($f eq "blsft") { - $try .= '$x << $y;'; - } elsif ($f eq "bmod") { - $try .= '$x % $y;'; - } else { - # Functions with three arguments - $try .= "\$z = $class->new(\"$args[2]\");"; - - if( $f eq "bmodpow") { - $try .= '$x->bmodpow($y,$z);'; - } elsif ($f eq "bmuladd"){ - $try .= '$x->bmuladd($y,$z);'; - } elsif ($f eq "batan2"){ - $try .= '$x->batan2($y,$z);'; - } else { warn "Unknown op '$f'"; } - } } - # print "# Trying: '$try'\n"; - $ans1 = eval $try; + + $got = eval $try; print "# Error: $@\n" if $@; - if ($ans =~ m|^/(.*)$|) - { - my $pat = $1; - if ($ans1 =~ /$pat/) - { - is (1,1); - } - else - { - print "# '$try' expected: /$pat/ got: '$ans1'\n" if !is (1,0); - } - } - else - { - if ($ans eq "") - { - is ($ans1, undef); - } - else - { - print "# Tried: '$try'\n" if !is ($ans1, $ans); - if (ref($ans1) eq "$class") - { - # float numbers are normalized (for now), so mantissa shouldn't have - # trailing zeros - #print $ans1->_trailing_zeros(),"\n"; - print "# Has trailing zeros after '$try'\n" - if !is ($CL->_zeros( $ans1->{_m}), 0); - } + + if ($want =~ m|^/(.*)$|) { + my $pat = $1; + like($got, qr/$pat/, $try); + } else { + if ($want eq "") { + is($got, undef, $try); + } else { + is($got, $want, $try); + if (ref($got) eq $CLASS) { + # float numbers are normalized (for now), so mantissa shouldn't + # have trailing zeros print $got->_trailing_zeros(), "\n"; + is($CALC->_zeros($got->{_m}), 0, $try); + } } - } # end pattern or string - } - } # end while + } # end pattern or string -# check whether $class->new( Math::BigInt->new()) destroys it +} # end while + +# check whether $CLASS->new(Math::BigInt->new()) destroys it # ($y == 12 in this case) -$x = Math::BigInt->new(1200); $y = $class->new($x); -is ($y,1200); is ($x,1200); +$x = Math::BigInt->new(1200); +$y = $CLASS->new($x); +is($y, 1200, + q|$x = Math::BigInt->new(1200); $y = $CLASS->new($x); # check $y|); +is($x, 1200, + q|$x = Math::BigInt->new(1200); $y = $CLASS->new($x); # check $x|); ############################################################################### -# Really huge, big, ultra-mega-biggy-monster exponents -# Technically, the exponents should not be limited (they are BigInts), but +# Really huge, big, ultra-mega-biggy-monster exponents. Technically, the +# exponents should not be limited (they are Math::BigInt objects), but # practically there are a few places were they are limited to a Perl scalar. # This is sometimes for speed, sometimes because otherwise the number wouldn't # fit into your memory (just think of 1e123456789012345678901234567890 + 1!) @@ -213,60 +197,91 @@ is ($y,1200); is ($x,1200); my $monster = '1e1234567890123456789012345678901234567890'; # new and exponent -is ($class->new($monster)->bsstr(), - '1e+1234567890123456789012345678901234567890'); -is ($class->new($monster)->exponent(), - '1234567890123456789012345678901234567890'); +is($CLASS->new($monster)->bsstr(), + '1e+1234567890123456789012345678901234567890', + qq|$CLASS->new("$monster")->bsstr()|); +is($CLASS->new($monster)->exponent(), + '1234567890123456789012345678901234567890', + qq|$CLASS->new("$monster")->exponent()|); + # cmp -is ($class->new($monster) > 0,1); +is($CLASS->new($monster) > 0, 1, qq|$CLASS->new("$monster") > 0|); -# sub/mul -is ($class->new($monster)->bsub( $monster),0); -is ($class->new($monster)->bmul(2)->bsstr(), - '2e+1234567890123456789012345678901234567890'); +# sub/mul +is($CLASS->new($monster)->bsub($monster), 0, + qq|$CLASS->new("$monster")->bsub("$monster")|); +is($CLASS->new($monster)->bmul(2)->bsstr(), + '2e+1234567890123456789012345678901234567890', + qq|$CLASS->new("$monster")->bmul(2)->bsstr()|); # mantissa $monster = '1234567890123456789012345678901234567890e2'; -is ($class->new($monster)->mantissa(), - '123456789012345678901234567890123456789'); +is($CLASS->new($monster)->mantissa(), + '123456789012345678901234567890123456789', + qq|$CLASS->new("$monster")->mantissa()|); ############################################################################### -# zero,inf,one,nan +# zero, inf, one, nan -$x = $class->new(2); $x->bzero(); is ($x->{_a}, undef); is ($x->{_p}, undef); -$x = $class->new(2); $x->binf(); is ($x->{_a}, undef); is ($x->{_p}, undef); -$x = $class->new(2); $x->bone(); is ($x->{_a}, undef); is ($x->{_p}, undef); -$x = $class->new(2); $x->bnan(); is ($x->{_a}, undef); is ($x->{_p}, undef); +$x = $CLASS->new(2); +$x->bzero(); +is($x->{_a}, undef, qq|\$x = $CLASS->new(2); \$x->bzero(); \$x->{_a}|); +is($x->{_p}, undef, qq|\$x = $CLASS->new(2); \$x->bzero(); \$x->{_p}|); + +$x = $CLASS->new(2); +$x->binf(); +is($x->{_a}, undef, qq|\$x = $CLASS->new(2); \$x->binf(); \$x->{_a}|); +is($x->{_p}, undef, qq|\$x = $CLASS->new(2); \$x->binf(); \$x->{_p}|); + +$x = $CLASS->new(2); +$x->bone(); +is($x->{_a}, undef, qq|\$x = $CLASS->new(2); \$x->bone(); \$x->{_a}|); +is($x->{_p}, undef, qq|\$x = $CLASS->new(2); \$x->bone(); \$x->{_p}|); + +$x = $CLASS->new(2); +$x->bnan(); +is($x->{_a}, undef, qq|\$x = $CLASS->new(2); \$x->bnan(); \$x->{_a}|); +is($x->{_p}, undef, qq|\$x = $CLASS->new(2); \$x->bnan(); \$x->{_p}|); ############################################################################### # bone/binf etc as plain calls (Lite failed them) -is ($class->bzero(),0); -is ($class->bone(),1); -is ($class->bone('+'),1); -is ($class->bone('-'),-1); -is ($class->bnan(),'NaN'); -is ($class->binf(),'inf'); -is ($class->binf('+'),'inf'); -is ($class->binf('-'),'-inf'); -is ($class->binf('-inf'),'-inf'); - -$class->accuracy(undef); $class->precision(undef); # reset +is($CLASS->bzero(), 0, qq|$CLASS->bzero()|); +is($CLASS->bone(), 1, qq|$CLASS->bone()|); +is($CLASS->bone("+"), 1, qq|$CLASS->bone("+")|); +is($CLASS->bone("-"), -1, qq|$CLASS->bone("-")|); +is($CLASS->bnan(), "NaN", qq|$CLASS->bnan()|); +is($CLASS->binf(), "inf", qq|$CLASS->binf()|); +is($CLASS->binf("+"), "inf", qq|$CLASS->binf("+")|); +is($CLASS->binf("-"), "-inf", qq|$CLASS->binf("-")|); +is($CLASS->binf("-inf"), "-inf", qq|$CLASS->binf("-inf")|); + +$CLASS->accuracy(undef); # reset +$CLASS->precision(undef); # reset ############################################################################### # bug in bsstr()/numify() showed up in after-rounding in bdiv() -$x = $class->new('0.008'); $y = $class->new(2); -$x->bdiv(3,$y); -is ($x,'0.0027'); +$x = $CLASS->new("0.008"); +$y = $CLASS->new(2); +$x->bdiv(3, $y); +is($x, "0.0027", + qq|\$x = $CLASS->new("0.008"); \$y = $CLASS->new(2); \$x->bdiv(3, \$y);|); ############################################################################### # Verify that numify() returns a normalized value, and underflows and # overflows when given "extreme" values. -like($class->new("12345e67")->numify(), qr/^1\.2345e\+?0*71$/); -like($class->new("1e-9999")->numify(), qr/^\+?0$/); # underflow -unlike($class->new("1e9999")->numify(), qr/^1(\.0*)?e\+?9+$/); # overflow +like($CLASS->new("12345e67")->numify(), qr/^1\.2345e\+?0*71$/, + qq|$CLASS->new("12345e67")->numify()|); + +# underflow +like($CLASS->new("1e-9999")->numify(), qr/^\+?0$/, + qq|$CLASS->new("1e-9999")->numify()|); + +# overflow +unlike($CLASS->new("1e9999")->numify(), qr/^1(\.0*)?e\+?9+$/, + qq|$CLASS->new("1e9999")->numify()|); ############################################################################### # Check numify on non-finite objects. @@ -275,82 +290,161 @@ unlike($class->new("1e9999")->numify(), qr/^1(\.0*)?e\+?9+$/); # overflow require Math::Complex; my $inf = Math::Complex::Inf(); my $nan = $inf - $inf; - is($class -> binf("+") -> numify(), $inf, "numify of +Inf"); - is($class -> binf("-") -> numify(), -$inf, "numify of -Inf"); - is($class -> bnan() -> numify(), $nan, "numify of NaN"); + is($CLASS -> binf("+") -> numify(), $inf, "numify of +Inf"); + is($CLASS -> binf("-") -> numify(), -$inf, "numify of -Inf"); + is($CLASS -> bnan() -> numify(), $nan, "numify of NaN"); } ############################################################################### # bsqrt() with set global A/P or A/P enabled on $x, also a test whether bsqrt() # correctly modifies $x +$x = $CLASS->new(12); +$CLASS->precision(-2); +$x->bsqrt(); +is($x, '3.46', + qq|\$x = $CLASS->new(12); $CLASS->precision(-2); \$x->bsqrt();|); -$x = $class->new(12); $class->precision(-2); $x->bsqrt(); is ($x,'3.46'); +$CLASS->precision(undef); +$x = $CLASS->new(12); +$CLASS->precision(0); +$x->bsqrt(); +is($x, '3', + qq|$CLASS->precision(undef); \$x = $CLASS->new(12);| . + qq| $CLASS->precision(0); \$x->bsqrt();|); -$class->precision(undef); -$x = $class->new(12); $class->precision(0); $x->bsqrt(); is ($x,'3'); - -$class->precision(-3); $x = $class->new(12); $x->bsqrt(); is ($x,'3.464'); +$CLASS->precision(-3); +$x = $CLASS->new(12); +$x->bsqrt(); +is($x, '3.464', + qq|$CLASS->precision(-3); \$x = $CLASS->new(12); \$x->bsqrt();|); { - no strict 'refs'; - # A and P set => NaN - ${${class}.'::accuracy'} = 4; $x = $class->new(12); - $x->bsqrt(3); is ($x,'NaN'); - # supplied arg overrides set global - $class->precision(undef); $x = $class->new(12); $x->bsqrt(3); is ($x,'3.46'); - $class->accuracy(undef); $class->precision(undef); # reset for further tests + no strict 'refs'; + # A and P set => NaN + ${${CLASS}.'::accuracy'} = 4; + $x = $CLASS->new(12); + $x->bsqrt(3); + is($x, 'NaN', "A and P set => NaN"); + + # supplied arg overrides set global + $CLASS->precision(undef); + $x = $CLASS->new(12); + $x->bsqrt(3); + is($x, '3.46', "supplied arg overrides set global"); + + # reset for further tests + $CLASS->accuracy(undef); + $CLASS->precision(undef); } ############################################################################# # can we call objectify (broken until v1.52) { - no strict; - $try = - '@args' . " = $class" . "::objectify(2,$class,4,5);".'join(" ",@args);'; - $ans = eval $try; - is ($ans,"$class 4 5"); + no strict; + $try = '@args' + . " = $CLASS" + . "::objectify(2, $CLASS, 4, 5);" + . ' join(" ", @args);'; + $want = eval $try; + is($want, "$CLASS 4 5", $try); } ############################################################################# # is_one('-') (broken until v1.64) -is ($class->new(-1)->is_one(),0); -is ($class->new(-1)->is_one('-'),1); +is($CLASS->new(-1)->is_one(), 0, qq|$CLASS->new(-1)->is_one()|); +is($CLASS->new(-1)->is_one("-"), 1, qq|$CLASS->new(-1)->is_one("-")|); ############################################################################# # bug 1/0.5 leaving 2e-0 instead of 2e0 -is ($class->new(1)->bdiv('0.5')->bsstr(),'2e+0'); +is($CLASS->new(1)->bdiv("0.5")->bsstr(), "2e+0", + qq|$CLASS->new(1)->bdiv("0.5")->bsstr()|); ############################################################################### # [perl #30609] bug with $x -= $x not being 0, but 2*$x -$x = $class->new(3); $x -= $x; is ($x, 0); -$x = $class->new(-3); $x -= $x; is ($x, 0); -$x = $class->new(3); $x += $x; is ($x, 6); -$x = $class->new(-3); $x += $x; is ($x, -6); +$x = $CLASS->new(3); +$x -= $x; +is($x, 0, qq|\$x = $CLASS->new(3); \$x -= \$x;|); + +$x = $CLASS->new(-3); +$x -= $x; +is($x, 0, qq|\$x = $CLASS->new(-3); \$x -= \$x;|); + +$x = $CLASS->new(3); +$x += $x; +is($x, 6, qq|\$x = $CLASS->new(3); \$x += \$x;|); + +$x = $CLASS->new(-3); +$x += $x; +is($x, -6, qq|\$x = $CLASS->new(-3); \$x += \$x;|); -$x = $class->new('NaN'); $x -= $x; is ($x->is_nan(), 1); -$x = $class->new('inf'); $x -= $x; is ($x->is_nan(), 1); -$x = $class->new('-inf'); $x -= $x; is ($x->is_nan(), 1); +$x = $CLASS->new("NaN"); +$x -= $x; +is($x->is_nan(), 1, qq|\$x = $CLASS->new("NaN"); \$x -= \$x;|); -$x = $class->new('NaN'); $x += $x; is ($x->is_nan(), 1); -$x = $class->new('inf'); $x += $x; is ($x->is_inf(), 1); -$x = $class->new('-inf'); $x += $x; is ($x->is_inf('-'), 1); +$x = $CLASS->new("inf"); +$x -= $x; +is($x->is_nan(), 1, qq|\$x = $CLASS->new("inf"); \$x -= \$x;|); -$x = $class->new('3.14'); $x -= $x; is ($x, 0); -$x = $class->new('-3.14'); $x -= $x; is ($x, 0); -$x = $class->new('3.14'); $x += $x; is ($x, '6.28'); -$x = $class->new('-3.14'); $x += $x; is ($x, '-6.28'); +$x = $CLASS->new("-inf"); +$x -= $x; +is($x->is_nan(), 1, qq|\$x = $CLASS->new("-inf"); \$x -= \$x;|); -$x = $class->new('3.14'); $x *= $x; is ($x, '9.8596'); -$x = $class->new('-3.14'); $x *= $x; is ($x, '9.8596'); -$x = $class->new('3.14'); $x /= $x; is ($x, '1'); -$x = $class->new('-3.14'); $x /= $x; is ($x, '1'); -$x = $class->new('3.14'); $x %= $x; is ($x, '0'); -$x = $class->new('-3.14'); $x %= $x; is ($x, '0'); +$x = $CLASS->new("NaN"); +$x += $x; +is($x->is_nan(), 1, qq|\$x = $CLASS->new("NaN"); \$x += \$x;|); + +$x = $CLASS->new("inf"); +$x += $x; +is($x->is_inf(), 1, qq|\$x = $CLASS->new("inf"); \$x += \$x;|); + +$x = $CLASS->new("-inf"); +$x += $x; +is($x->is_inf("-"), 1, qq|\$x = $CLASS->new("-inf"); \$x += \$x;|); + +$x = $CLASS->new("3.14"); +$x -= $x; +is($x, 0, qq|\$x = $CLASS->new("3.14"); \$x -= \$x;|); + +$x = $CLASS->new("-3.14"); +$x -= $x; +is($x, 0, qq|\$x = $CLASS->new("-3.14"); \$x -= \$x;|); + +$x = $CLASS->new("3.14"); +$x += $x; +is($x, "6.28", qq|$x = $CLASS->new("3.14"); $x += $x;|); + +$x = $CLASS->new("-3.14"); +$x += $x; +is($x, "-6.28", qq|$x = $CLASS->new("-3.14"); $x += $x;|); + +$x = $CLASS->new("3.14"); +$x *= $x; +is($x, "9.8596", qq|$x = $CLASS->new("3.14"); $x *= $x;|); + +$x = $CLASS->new("-3.14"); +$x *= $x; +is($x, "9.8596", qq|$x = $CLASS->new("-3.14"); $x *= $x;|); + +$x = $CLASS->new("3.14"); +$x /= $x; +is($x, "1", qq|$x = $CLASS->new("3.14"); $x /= $x;|); + +$x = $CLASS->new("-3.14"); +$x /= $x; +is($x, "1", qq|$x = $CLASS->new("-3.14"); $x /= $x;|); + +$x = $CLASS->new("3.14"); +$x %= $x; +is($x, "0", qq|$x = $CLASS->new("3.14"); $x %= $x;|); + +$x = $CLASS->new("-3.14"); +$x %= $x; +is($x, "0", qq|$x = $CLASS->new("-3.14"); $x %= $x;|); ############################################################################### # the following two were reported by "kenny" via hotmail.com: @@ -358,41 +452,67 @@ $x = $class->new('-3.14'); $x %= $x; is ($x, '0'); #perl -MMath::BigFloat -wle 'print Math::BigFloat->new(0)->bpow(".1")' #Use of uninitialized value in numeric le (<=) at BigFloat.pm line 1851. -$x = $class->new(0); $y = $class->new('0.1'); -is ($x ** $y, 0, 'no warnings and zero result'); +$x = $CLASS->new(0); +$y = $CLASS->new("0.1"); +is($x ** $y, 0, + qq|\$x = $CLASS->new(0); \$y = $CLASS->new("0.1"); \$x ** \$y|); #perl -MMath::BigFloat -lwe 'print Math::BigFloat->new(".222222222222222222222222222222222222222222")->bceil()' #Use of uninitialized value in numeric le (<=) at BigFloat.pm line 1851. -$x = $class->new(".222222222222222222222222222222222222222222"); -is ($x->bceil(), 1, 'no warnings and one as result'); +$x = $CLASS->new(".222222222222222222222222222222222222222222"); +is($x->bceil(), 1, + qq|$x = $CLASS->new(".222222222222222222222222222222222222222222");| . + qq| $x->bceil();|); ############################################################################### # test **=, <<=, >>= -# ((2^148)-1)/17 -$x = $class->new(2); $x **= 148; $x++; $x->bdiv(17, 60)->bfloor(); $x->accuracy(undef); -is ($x,"20988936657440586486151264256610222593863921"); -is ($x->length(),length "20988936657440586486151264256610222593863921"); +# ((2**148)+1)/17 +$x = $CLASS->new(2); +$x **= 148; +$x++; +$x->bdiv(17, 60)->bfloor(); +$x->accuracy(undef); +is($x, "20988936657440586486151264256610222593863921", + "value of ((2**148)+1)/17"); +is($x->length(), length("20988936657440586486151264256610222593863921"), + "number of digits in ((2**148)+1)/17"); -$x = $class->new('2'); -my $y = $class->new('18'); -is ($x <<= $y, 2 << 18); -is ($x, 2 << 18); -is ($x >>= $y, 2); -is ($x, 2); +$x = $CLASS->new("2"); +$y = $CLASS->new("18"); +is($x <<= $y, 2 << 18, + qq|\$x = $CLASS->new("2"); \$y = $CLASS->new("18");| + . q| $x <<= $y|); +is($x, 2 << 18, + qq|\$x = $CLASS->new("2"); \$y = $CLASS->new("18");| + . q| $x <<= $y; $x|); +is($x >>= $y, 2, + qq|\$x = $CLASS->new("2"); \$y = $CLASS->new("18");| + . q| $x <<= $y; $x >>= $y|); +is($x, 2, + qq|\$x = $CLASS->new("2"); \$y = $CLASS->new("18");| + . q| $x <<= $y; $x >>= $y; $x|); -$x = $class->new('2'); -$y = $class->new('18.2'); -$x <<= $y; # 2 * (2 ** 18.2); +$x = $CLASS->new("2"); +$y = $CLASS->new("18.2"); -is ($x->copy()->bfround(-9), '602248.763144685'); -is ($x >>= $y, 2); # 2 * (2 ** 18.2) / (2 ** 18.2) => 2 -is ($x, 2); +# 2 * (2 ** 18.2); +$x <<= $y; +is($x->copy()->bfround(-9), "602248.763144685", + qq|\$x = $CLASS->new("2"); \$y = $CLASS->new("18.2");| . + q| $x <<= $y; $x->copy()->bfround(-9);|); -1; # all done +# 2 * (2 ** 18.2) / (2 ** 18.2) => 2 +is($x >>= $y, 2, + qq|\$x = $CLASS->new("2"); \$y = $CLASS->new("18.2");| . + q| $x <<= $y; $x->copy()->bfround(-9); $x >>= $y|); +is($x, 2, + qq|\$x = $CLASS->new("2"); \$y = $CLASS->new("18.2");| . + q| $x <<= $y; $x->copy()->bfround(-9); $x >>= $y; $x|); __DATA__ + &bgcd inf:12:NaN -inf:12:NaN @@ -420,6 +540,7 @@ abc:+0:NaN 1034:804:2 27:90:56:1 27:90:54:9 + &blcm abc:abc:NaN abc:+0:NaN @@ -429,7 +550,8 @@ abc:+0:NaN +0:+1:0 +27:+90:270 +1034:+804:415668 -$div_scale = 40; +$div_scale = 40 + &bcos 1.2:10:0.3623577545 2.4:12:-0.737393715541 @@ -437,6 +559,7 @@ $div_scale = 40; 0:20:1 1:10:0.5403023059 1:12:0.540302305868 + &bsin 1:10:0.8414709848 0:10:0 @@ -445,37 +568,67 @@ $div_scale = 40; 1.2:13:0.9320390859672 0.2:13:0.1986693307951 3.2:12:-0.0583741434276 + &batan NaN:10:NaN inf:14:1.5707963267949 -inf:14:-1.5707963267949 +0:14:0 +0:10:0 +0.1:14:0.099668652491162 0.2:13:0.1973955598499 0.2:14:0.19739555984988 -0:10:0 +0.5:14:0.46364760900081 1:14:0.78539816339744 -1:14:-0.78539816339744 -# test an argument X > 1 -2:14:1.1071487177941 +1.5:14:0.98279372324732 +2.0:14:1.1071487177941 +2.5:14:1.1902899496825 +3.0:14:1.2490457723982 +6.0:14:1.4056476493803 +12:14:1.4876550949064 +24:14:1.5291537476963 +48:14:1.5499660067587 + &batan2 + NaN:1:10:NaN NaN:NaN:10:NaN 1:NaN:10:NaN -inf:1:14:1.5707963267949 --inf:1:14:-1.5707963267949 -0:-inf:14:3.1415926535898 --1:-inf:14:-3.1415926535898 -1:-inf:14:3.1415926535898 -0:inf:14:0 -inf:-inf:14:2.3561944901923 + -inf:-inf:14:-2.3561944901923 -inf:+inf:14:0.7853981633974 --inf:+inf:14:-0.7853981633974 +-inf:-1:14:-1.5707963267949 +-inf:0:14:-1.5707963267949 +-inf:+1:14:-1.5707963267949 +-inf:+inf:14:-0.78539816339745 + +-1:-inf:14:-3.1415926535898 +-1:-1:14:-2.3561944901923 +-1:0:14:-1.5707963267949 +-1:+1:14:-0.78539816339745 +-1:+inf:14:0 + +0:-inf:14:3.1415926535898 +0:-1:14:3.1415926535898 +0:0:14:0 +0:+1:14:0 +0:+inf:14:0 + ++1:-inf:14:3.1415926535898 ++1:-1:14:2.3561944901923 ++1:0:14:1.5707963267949 ++1:+1:14:0.78539816339745 ++1:+inf:14:0 + ++inf:-inf:14:2.3561944901923 ++inf:-1:14:1.5707963267949 ++inf:0:14:1.5707963267949 ++inf:+1:14:1.5707963267949 ++inf:+inf:14:0.78539816339745 + 1:5:13:0.1973955598499 1:5:14:0.19739555984988 -0:0:10:0 -0:1:14:0 0:2:14:0 -1:0:14:1.5707963267949 5:0:14:1.5707963267949 -1:0:11:-1.5707963268 -2:0:77:-1.5707963267948966192313216916397514420985846996875529104874722961539082031431 @@ -484,16 +637,17 @@ inf:+inf:14:0.7853981633974 1:5:14:0.19739555984988 -1:8:14:-0.12435499454676 1:8:14:0.12435499454676 --1:1:14:-0.78539816339744 # test an argument X > 1 and one X < 1 1:2:24:0.463647609000806116214256 2:1:14:1.1071487177941 -2:1:14:-1.1071487177941 + &bpi 150:3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940813 77:3.1415926535897932384626433832795028841971693993751058209749445923078164062862 +0:3.141592653589793238462643383279502884197 11:3.1415926536 + &bnok +inf:10:inf NaN:NaN:NaN @@ -513,6 +667,7 @@ NaN:1:NaN 2:0:1 7:0:1 2:1:2 + &blog 0::-inf -1::NaN @@ -527,9 +682,9 @@ NaN:1:NaN 1:2:0 2::0.6931471805599453094172321214581765680755 2.718281828::0.9999999998311266953289851340574956564911 -$div_scale = 20; +$div_scale = 20 2.718281828::0.99999999983112669533 -$div_scale = 15; +$div_scale = 15 123::4.81218435537242 10::2.30258509299405 1000::6.90775527898214 @@ -542,8 +697,9 @@ $div_scale = 15; 10:10:1 100:100:1 # reset for further tests -$div_scale = 40; +$div_scale = 40 1::0 + &brsft NaNbrsft:2:NaN 0:2:0 @@ -552,6 +708,7 @@ NaNbrsft:2:NaN 4:1:2 123:1:61.5 32:3:4 + &blsft NaNblsft:0:NaN 2:1:4 @@ -559,6 +716,7 @@ NaNblsft:0:NaN 5:3:40 1:2:4 0:5:0 + &bnorm 1:1 -0:0 @@ -602,6 +760,7 @@ bnormNaN:NaN -00e+3:0 -00e-03:0 -00e+03:0 + &as_number 0:0 1:1 @@ -640,10 +799,12 @@ NaN:NaN 0.1234567:0 0.12345678:0 0.123456789:0 + &binf 1:+:inf 2:-:-inf 3:abc:inf + &as_hex +inf:inf -inf:-inf @@ -651,6 +812,7 @@ hexNaN:NaN 0:0x0 5:0x5 -5:-0x5 + &as_bin +inf:inf -inf:-inf @@ -658,6 +820,7 @@ hexNaN:NaN 0:0b0 5:0b101 -5:-0b101 + &numify # uses bsstr() so 5 => 5e+0 to be compatible w/ Perls output 0:0 @@ -666,11 +829,13 @@ hexNaN:NaN -5:-5 100:100 -100:-100 + &bnan abc:NaN 2:NaN -2:NaN 0:NaN + &bone 2:+:1 -2:-:-1 @@ -680,6 +845,7 @@ abc:NaN -2::1 abc::1 2:abc:1 + &bsstr +inf:inf -inf:-inf @@ -689,6 +855,7 @@ abcfsstr:NaN 123:123e+0 -5:-5e+0 -100:-1e+2 + &bstr +inf:::inf -inf:::-inf @@ -700,11 +867,12 @@ abcfstr:::NaN 0.001234::-8:0.00123400 0:4::0 0::-4:0.0000 + &bnorm inf:inf +inf:inf -inf:-inf -+infinity:NaN ++infinity:inf +-inf:NaN abc:NaN 1 a:NaN @@ -756,6 +924,7 @@ abc:NaN 1.1e1:11 -3e111:-3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -4e-1111:-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004 + &bpow NaN:1:NaN 1:NaN:NaN @@ -797,9 +966,10 @@ abc:123.456:NaN 2:0.5:1.41421356237309504880168872420969807857 #2:0.2:1.148698354997035006798626946777927589444 #6:1.5:14.6969384566990685891837044482353483518 -$div_scale = 20; +$div_scale = 20 #62.5:12.5:26447206647554886213592.3959144 -$div_scale = 40; +$div_scale = 40 + &bneg bnegNaN:NaN +inf:-inf @@ -811,6 +981,7 @@ bnegNaN:NaN -123456789:123456789 +123.456789:-123.456789 -123456.789:123456.789 + &babs babsNaN:NaN +inf:inf @@ -822,6 +993,7 @@ babsNaN:NaN -123456789:123456789 +123.456789:123.456789 -123456.789:123456.789 + &bround $round_mode = "trunc" +inf:5:inf @@ -897,6 +1069,7 @@ $round_mode = "common" +601234300:6:601234000 +60123456789.0123:5:60123000000 -60123456789.0123:5:-60123000000 + &bfround $round_mode = "trunc" +inf:5:inf @@ -1032,6 +1205,7 @@ $round_mode = "even" 0.01234567:-8:0.01234567 0.01234567:-9:0.012345670 0.01234567:-12:0.012345670000 + &bcmp bcmpNaN:bcmpNaN: bcmpNaN:+0: @@ -1104,6 +1278,7 @@ bcmpNaN:+0: NaN:inf: -inf:NaN: NaN:-inf: + &bacmp bcmpNaN:bcmpNaN: bcmpNaN:+0: @@ -1178,6 +1353,7 @@ bcmpNaN:+0: bacmpNaN:inf: -inf:bacmpNaN: bacmpNaN:-inf: + &bdec bdecNaN:NaN +inf:inf @@ -1193,6 +1369,7 @@ bdecNaN:NaN -99:-100 -98:-99 99:98 + &binc bincNaN:NaN +inf:inf @@ -1207,6 +1384,7 @@ bincNaN:NaN -99:-98 -101:-100 99:100 + &badd abc:abc:NaN abc:+0:NaN @@ -1254,6 +1432,7 @@ baddNaN:+inf:NaN -123456789:-987654321:-1111111110 +123456789:-987654321:-864197532 0.001234:0.0001234:0.0013574 + &bsub abc:abc:NaN abc:+0:NaN @@ -1300,6 +1479,7 @@ baddNaN:+inf:NaN -123456789:+987654321:-1111111110 -123456789:-987654321:864197532 +123456789:-987654321:1111111110 + &bmuladd abc:abc:0:NaN abc:+0:0:NaN @@ -1361,12 +1541,14 @@ NaNmul:-inf:0:NaN 9999999999999999999:10000000000000000000:1234567890:99999999999999999990000000001234567890 3.2:5.7:8.9:27.14 -3.2:5.197:6.05:-10.5804 + &bmodpow 3:4:8:1 3:4:7:4 3:4:7:4 77777:777:123456789:99995084 3.2:6.2:5.2:2.970579856718063040273642739529400818 + &bmul abc:abc:NaN abc:+0:NaN @@ -1418,6 +1600,7 @@ NaNmul:-inf:NaN +99999999999:+9:899999999991 6:120:720 10:10000:100000 + &bdiv-list 0:0:NaN,0 0:1:0,0 @@ -1428,8 +1611,9 @@ NaNmul:-inf:NaN 2.1:1:2.1,0 -2.1:-1:2.1,0 -2.1:1:-2.1,0 + &bdiv -$div_scale = 40; $round_mode = 'even' +$div_scale = 40; $round_mode = "even" abc:abc:NaN abc:+1:abc:NaN +1:abc:NaN @@ -1505,6 +1689,7 @@ $div_scale = 1 123456789.1234:1:100000000 # reset scale for further tests $div_scale = 40 + &bmod +9:4:1 +9:5:4 @@ -1595,6 +1780,7 @@ abc:1:abc:NaN 3:1:0 -3:-1:0 3:-1:0 + &bfac Nanfac:NaN -1:NaN @@ -1610,6 +1796,7 @@ Nanfac:NaN 10:3628800 11:39916800 12:479001600 + &broot # sqrt() +0:2:0 @@ -1660,6 +1847,7 @@ NaN:inf:NaN 16:4:2 81:4:3 # see t/bigroot() for more tests + &bsqrt +0:0 -1:NaN @@ -1686,11 +1874,13 @@ nanbsqrt:NaN 12:3.464101615137754587054892683011744733886 0.49:0.7 0.0049:0.07 + &is_nan 123:0 abc:1 NaN:1 -123:0 + &is_inf +inf::1 -inf::1 @@ -1702,9 +1892,13 @@ NaN::0 +inf:+:1 -inf:-:1 -inf:+:0 -# it must be exactly /^[+-]inf$/ -+infinity::0 --infinity::0 +-inf:-inf:1 +-inf:+inf:0 ++inf:-inf:0 ++inf:+inf:1 ++iNfInItY::1 +-InFiNiTy::1 + &is_odd abc:0 0:0 @@ -1719,6 +1913,7 @@ abc:0 123.45:0 -123.45:0 2:0 + &is_int NaNis_int:0 0:1 @@ -1731,6 +1926,7 @@ NaNis_int:0 123.4567:0 -0.1:0 -0.002:0 + &is_even abc:0 0:1 @@ -1750,6 +1946,7 @@ abc:0 120:1 1200:1 -1200:1 + &is_positive 0:0 1:1 @@ -1758,6 +1955,7 @@ abc:0 NaN:0 -inf:0 +inf:1 + &is_negative 0:0 1:0 @@ -1766,6 +1964,7 @@ NaN:0 NaN:0 -inf:1 +inf:0 + &parts 0:0 0 1:1 0 @@ -1775,6 +1974,7 @@ NaN:0 NaNparts:NaN NaN +inf:inf inf -inf:-inf inf + &exponent 0:0 1:0 @@ -1784,6 +1984,7 @@ NaNparts:NaN NaN +inf:inf -inf:inf NaNexponent:NaN + &mantissa 0:0 1:1 @@ -1793,12 +1994,14 @@ NaNexponent:NaN +inf:inf -inf:-inf NaNmantissa:NaN + &length 123:3 -123:3 0:1 1:1 12345678901234567890:20 + &is_zero NaNzero:0 +inf:0 @@ -1806,6 +2009,7 @@ NaNzero:0 0:1 -1:0 1:0 + &is_one NaNone:0 +inf:0 @@ -1815,6 +2019,7 @@ NaNone:0 1:1 -1:0 -2:0 + &bfloor 0:0 abc:NaN @@ -1829,6 +2034,7 @@ abc:NaN 0.1234567:0 0.12345678:0 0.123456789:0 + &bceil 0:0 abc:NaN @@ -1839,6 +2045,7 @@ abc:NaN -51.2:-51 12.2:13 -0.4:0 + &bint 0:0 NaN:NaN @@ -1850,6 +2057,7 @@ NaN:NaN 12.2:12 -0.4:0 # overloaded functions + &log -1:NaN 0:-inf @@ -1861,11 +2069,19 @@ NaN:NaN -inf:inf inf:inf NaN:NaN + &exp + &sin + &cos + &atan2 + &int + &neg + &abs + &sqrt |