diff options
author | Steve Hay <steve.m.hay@googlemail.com> | 2016-01-04 13:55:50 +0000 |
---|---|---|
committer | Steve Hay <steve.m.hay@googlemail.com> | 2016-01-05 13:08:02 +0000 |
commit | 11c955beb7860e5e5bfd8eeb502344fecceea403 (patch) | |
tree | bc780c3d0c3e80fb9a3e5e76fd03bd7334177bdb /cpan | |
parent | 1d5bcce3b0d190a88de46d72740373f3c00ab576 (diff) | |
download | perl-11c955beb7860e5e5bfd8eeb502344fecceea403.tar.gz |
Upgrade Math-BigRat from version 0.260801 to 0.260802
(This maintains the one minor divergence between blead and cpan. The blead
version first appeared in 50a54b125c. I haven't examined whether this
difference needs to remain, or whether we can switch to the cpan version.)
Diffstat (limited to 'cpan')
-rw-r--r-- | cpan/Math-BigRat/lib/Math/BigRat.pm | 655 | ||||
-rw-r--r-- | cpan/Math-BigRat/t/Math/BigRat/Test.pm | 166 | ||||
-rw-r--r-- | cpan/Math-BigRat/t/big_ap.t | 92 | ||||
-rw-r--r-- | cpan/Math-BigRat/t/bigfltpm.inc | 5 | ||||
-rw-r--r-- | cpan/Math-BigRat/t/bigfltrt.t | 16 | ||||
-rw-r--r-- | cpan/Math-BigRat/t/biglog.t | 4 | ||||
-rw-r--r-- | cpan/Math-BigRat/t/bigrat.t | 561 | ||||
-rw-r--r-- | cpan/Math-BigRat/t/bigratpm.inc | 331 | ||||
-rw-r--r-- | cpan/Math-BigRat/t/bigratpm.t | 12 | ||||
-rw-r--r-- | cpan/Math-BigRat/t/bigratup.t | 28 | ||||
-rw-r--r-- | cpan/Math-BigRat/t/bigroot.t | 4 | ||||
-rw-r--r-- | cpan/Math-BigRat/t/bitwise.t | 14 | ||||
-rw-r--r-- | cpan/Math-BigRat/t/hang.t | 8 | ||||
-rw-r--r-- | cpan/Math-BigRat/t/requirer.t | 10 | ||||
-rw-r--r-- | cpan/Math-BigRat/t/trap.t | 4 |
15 files changed, 1085 insertions, 825 deletions
diff --git a/cpan/Math-BigRat/lib/Math/BigRat.pm b/cpan/Math-BigRat/lib/Math/BigRat.pm index e0c12b31f3..95c2927a86 100644 --- a/cpan/Math-BigRat/lib/Math/BigRat.pm +++ b/cpan/Math-BigRat/lib/Math/BigRat.pm @@ -1,4 +1,3 @@ - # # "Tax the rat farms." - Lord Vetinari # @@ -16,41 +15,43 @@ package Math::BigRat; # anything older is untested, and unlikely to work use 5.006; use strict; +use warnings; + use Carp (); use Math::BigFloat; -use vars qw($VERSION @ISA $upgrade $downgrade - $accuracy $precision $round_mode $div_scale $_trap_nan $_trap_inf); + +our ($VERSION, @ISA, $upgrade, $downgrade, + $accuracy, $precision, $round_mode, $div_scale, $_trap_nan, $_trap_inf); @ISA = qw(Math::BigFloat); -$VERSION = '0.260801'; +$VERSION = '0.260802'; $VERSION = eval $VERSION; -# inherit overload from Math::BigFloat, but disable the bitwise ops that don't -# make much sense for rationals unless they're truncated or something first +# Inherit overload from Math::BigFloat, but disable the bitwise ops that don't +# make much sense for rationals unless they're truncated or something first. use overload - map { - my $op = $_; - ($op => sub { - Carp::croak("bitwise operation $op not supported in Math::BigRat"); - }); - } qw(& | ^ ~ << >> &= |= ^= <<= >>=); - -BEGIN - { - *objectify = \&Math::BigInt::objectify; # inherit this from BigInt - *AUTOLOAD = \&Math::BigFloat::AUTOLOAD; # can't inherit AUTOLOAD - # we inherit these from BigFloat because currently it is not possible - # that MBF has a different $MBI variable than we, because MBF also uses - # Math::BigInt::config->('lib'); (there is always only one library loaded) - *_e_add = \&Math::BigFloat::_e_add; - *_e_sub = \&Math::BigFloat::_e_sub; - *as_int = \&as_number; - *is_pos = \&is_positive; - *is_neg = \&is_negative; - } + map { + my $op = $_; + ($op => sub { + Carp::croak("bitwise operation $op not supported in Math::BigRat"); + }); + } qw(& | ^ ~ << >> &= |= ^= <<= >>=); + +BEGIN { + *objectify = \&Math::BigInt::objectify; # inherit this from BigInt + *AUTOLOAD = \&Math::BigFloat::AUTOLOAD; # can't inherit AUTOLOAD + # We inherit these from BigFloat because currently it is not possible + # that MBF has a different $MBI variable than we, because MBF also uses + # Math::BigInt::config->('lib'); (there is always only one library loaded) + *_e_add = \&Math::BigFloat::_e_add; + *_e_sub = \&Math::BigFloat::_e_sub; + *as_int = \&as_number; + *is_pos = \&is_positive; + *is_neg = \&is_negative; +} ############################################################################## # Global constants and flags. Access these only via the accessor methods! @@ -70,17 +71,22 @@ $_trap_inf = 0; # are infs ok? set w/ config() # Math::BigInt->config()->{lib} my $MBI = 'Math::BigInt::Calc'; -my $nan = 'NaN'; +my $nan = 'NaN'; my $class = 'Math::BigRat'; -sub isa - { - return 0 if $_[1] =~ /^Math::Big(Int|Float)/; # we aren't - UNIVERSAL::isa(@_); - } +sub isa { + return 0 if $_[1] =~ /^Math::Big(Int|Float)/; # we aren't + UNIVERSAL::isa(@_); +} ############################################################################## +# If $x is a Math::BigRat object and $f is a Math::BigFloat object, then +# +# $x -> _new_from_float($f) +# +# converts $x into a Math::BigRat with the value of $f. + sub _new_from_float { # turn a single float input into a rational number (like '0.1') @@ -89,258 +95,262 @@ sub _new_from_float return $self->bnan() if $f->is_nan(); return $self->binf($f->{sign}) if $f->{sign} =~ /^[+-]inf$/; - $self->{_n} = $MBI->_copy( $f->{_m} ); # mantissa + $self->{_n} = $MBI->_copy($f->{_m}); # mantissa $self->{_d} = $MBI->_one(); $self->{sign} = $f->{sign} || '+'; if ($f->{_es} eq '-') { # something like Math::BigRat->new('0.1'); # 1 / 1 => 1/10 - $MBI->_lsft ( $self->{_d}, $f->{_e} ,10); + $MBI->_lsft($self->{_d}, $f->{_e} ,10); } else { # something like Math::BigRat->new('10'); # 1 / 1 => 10/1 - $MBI->_lsft ( $self->{_n}, $f->{_e} ,10) unless + $MBI->_lsft($self->{_n}, $f->{_e} ,10) unless $MBI->_is_zero($f->{_e}); } - $self; + return $self -> bnorm(); } -sub new - { - # create a Math::BigRat - my $class = shift; +# If $x is a Math::BigRat object and $i is a Math::BigInt object, then +# +# $x -> _new_from_int($i) +# +# converts $x into a Math::BigRat with the value of $i. - my ($n,$d) = @_; +sub _new_from_int { + my ($self, $i) = @_; - my $self = { }; bless $self,$class; + return $self -> bnan() if $i -> is_nan(); + return $self -> binf($i -> sign()) if $i -> is_inf(); - # input like (BigInt) or (BigFloat): - if ((!defined $d) && (ref $n) && (!$n->isa('Math::BigRat'))) - { - if ($n->isa('Math::BigFloat')) - { - $self->_new_from_float($n); - } - if ($n->isa('Math::BigInt')) - { - # TODO: trap NaN, inf - $self->{_n} = $MBI->_copy($n->{value}); # "mantissa" = N - $self->{_d} = $MBI->_one(); # d => 1 - $self->{sign} = $n->{sign}; - } - if ($n->isa('Math::BigInt::Lite')) - { - # TODO: trap NaN, inf - $self->{sign} = '+'; $self->{sign} = '-' if $$n < 0; - $self->{_n} = $MBI->_new(abs($$n)); # "mantissa" = N - $self->{_d} = $MBI->_one(); # d => 1 - } - return $self->bnorm(); # normalize (120/1 => 12/10) - } + $self -> {_n} = $MBI -> _copy($i -> {value}); + $self -> {_d} = $MBI -> _one(); + $self -> {sign} = $i -> {sign}; + return $self; +} - # input like (BigInt,BigInt) or (BigLite,BigLite): - if (ref($d) && ref($n)) - { - # do N first (for $self->{sign}): - if ($n->isa('Math::BigInt')) - { - # TODO: trap NaN, inf - $self->{_n} = $MBI->_copy($n->{value}); # "mantissa" = N - $self->{sign} = $n->{sign}; - } - elsif ($n->isa('Math::BigInt::Lite')) - { - # TODO: trap NaN, inf - $self->{sign} = '+'; $self->{sign} = '-' if $$n < 0; - $self->{_n} = $MBI->_new(abs($$n)); # "mantissa" = $n - } - else - { - require Carp; - Carp::croak(ref($n) . " is not a recognized object format for Math::BigRat->new"); - } - # now D: - if ($d->isa('Math::BigInt')) - { - # TODO: trap NaN, inf - $self->{_d} = $MBI->_copy($d->{value}); # "mantissa" = D - # +/+ or -/- => +, +/- or -/+ => - - $self->{sign} = $d->{sign} ne $self->{sign} ? '-' : '+'; - } - elsif ($d->isa('Math::BigInt::Lite')) - { - # TODO: trap NaN, inf - $self->{_d} = $MBI->_new(abs($$d)); # "mantissa" = D - my $ds = '+'; $ds = '-' if $$d < 0; - # +/+ or -/- => +, +/- or -/+ => - - $self->{sign} = $ds ne $self->{sign} ? '-' : '+'; - } - else - { - require Carp; - Carp::croak(ref($d) . " is not a recognized object format for Math::BigRat->new"); - } - return $self->bnorm(); # normalize (120/1 => 12/10) - } - return $n->copy() if ref $n; # already a BigRat +sub new { + my $self = shift; + my $selfref = ref $self; + my $class = $selfref || $self; - if (!defined $n) - { - $self->{_n} = $MBI->_zero(); # undef => 0 - $self->{_d} = $MBI->_one(); - $self->{sign} = '+'; - return $self; + # Get numerator and denominator. + + my ($n, $d) = @_; + + # If called as a class method, initialize a new object. + + $self = bless {}, $class unless $selfref; + + # Input like $class->new($n), where there is no denominator, and where $n + # is a Math::BigInt or Math::BigFloat. + + if ((!defined $d) && (ref $n) && (!$n->isa('Math::BigRat'))) { + if ($n->isa('Math::BigFloat')) { + $self->_new_from_float($n); + } + elsif ($n->isa('Math::BigInt')) { + # TODO: trap NaN, inf + $self->{_n} = $MBI->_copy($n->{value}); # "mantissa" = N + $self->{_d} = $MBI->_one(); # d => 1 + $self->{sign} = $n->{sign}; + } + elsif ($n->isa('Math::BigInt::Lite')) { + # TODO: trap NaN, inf + $self->{sign} = '+'; + $self->{sign} = '-' if $$n < 0; + $self->{_n} = $MBI->_new(abs($$n)); # "mantissa" = N + $self->{_d} = $MBI->_one(); # d => 1 + } + return $self->bnorm(); # normalize (120/100 => 6/5) } - # string input with / delimiter - if ($n =~ /\s*\/\s*/) - { - return $class->bnan() if $n =~ /\/.*\//; # 1/2/3 isn't valid - return $class->bnan() if $n =~ /\/\s*$/; # 1/ isn't valid - ($n,$d) = split (/\//,$n); - # try as BigFloats first - if (($n =~ /[\.eE]/) || ($d =~ /[\.eE]/)) - { - local $Math::BigFloat::accuracy = undef; - local $Math::BigFloat::precision = undef; - - # one of them looks like a float - my $nf = Math::BigFloat->new($n,undef,undef); - $self->{sign} = '+'; - return $self->bnan() if $nf->is_nan(); - - $self->{_n} = $MBI->_copy( $nf->{_m} ); # get mantissa - - # now correct $self->{_n} due to $n - my $f = Math::BigFloat->new($d,undef,undef); - return $self->bnan() if $f->is_nan(); - $self->{_d} = $MBI->_copy( $f->{_m} ); - - # calculate the difference between nE and dE - my $diff_e = $nf->exponent()->bsub( $f->exponent); - if ($diff_e->is_negative()) - { - # < 0: mul d with it - $MBI->_lsft( $self->{_d}, $MBI->_new( $diff_e->babs()), 10); - } - elsif (!$diff_e->is_zero()) - { - # > 0: mul n with it - $MBI->_lsft( $self->{_n}, $MBI->_new( $diff_e), 10); + # Input like $class->new($n, $d) where $n and $d both are Math::BigInt + # objects or Math::BigInt::Lite objects. + if (ref($d) && ref($n)) { + + # do N first (for $self->{sign}): + if ($n->isa('Math::BigInt')) { + # TODO: trap NaN, inf + $self->{_n} = $MBI->_copy($n->{value}); # "mantissa" = N + $self->{sign} = $n->{sign}; } - } - else - { - # both d and n look like (big)ints - - $self->{sign} = '+'; # no sign => '+' - $self->{_n} = undef; - $self->{_d} = undef; - if ($n =~ /^([+-]?)0*([0-9]+)\z/) # first part ok? - { - $self->{sign} = $1 || '+'; # no sign => '+' - $self->{_n} = $MBI->_new($2 || 0); + elsif ($n->isa('Math::BigInt::Lite')) { + # TODO: trap NaN, inf + $self->{sign} = '+'; + $self->{sign} = '-' if $$n < 0; + $self->{_n} = $MBI->_new(abs($$n)); # "mantissa" = $n + } + else { + Carp::croak(ref($n) . " is not a recognized object format for" + . " Math::BigRat->new"); } - if ($d =~ /^([+-]?)0*([0-9]+)\z/) # second part ok? - { - $self->{sign} =~ tr/+-/-+/ if ($1 || '') eq '-'; # negate if second part neg. - $self->{_d} = $MBI->_new($2 || 0); + # now D: + if ($d->isa('Math::BigInt')) { + # TODO: trap NaN, inf + $self->{_d} = $MBI->_copy($d->{value}); # "mantissa" = D + # +/+ or -/- => +, +/- or -/+ => - + $self->{sign} = $d->{sign} ne $self->{sign} ? '-' : '+'; + } elsif ($d->isa('Math::BigInt::Lite')) { + # TODO: trap NaN, inf + $self->{_d} = $MBI->_new(abs($$d)); # "mantissa" = D + my $ds = '+'; + $ds = '-' if $$d < 0; + # +/+ or -/- => +, +/- or -/+ => - + $self->{sign} = $ds ne $self->{sign} ? '-' : '+'; + } else { + Carp::croak(ref($d) . " is not a recognized object format for" + . " Math::BigRat->new"); } - if (!defined $self->{_n} || !defined $self->{_d}) - { - $d = Math::BigInt->new($d,undef,undef) unless ref $d; - $n = Math::BigInt->new($n,undef,undef) unless ref $n; - - if ($n->{sign} =~ /^[+-]$/ && $d->{sign} =~ /^[+-]$/) - { - # both parts are ok as integers (weird things like ' 1e0' - $self->{_n} = $MBI->_copy($n->{value}); - $self->{_d} = $MBI->_copy($d->{value}); - $self->{sign} = $n->{sign}; - $self->{sign} =~ tr/+-/-+/ if $d->{sign} eq '-'; # -1/-2 => 1/2 - return $self->bnorm(); - } - - $self->{sign} = '+'; # a default sign - return $self->bnan() if $n->is_nan() || $d->is_nan(); - - # handle inf cases: - if ($n->is_inf() || $d->is_inf()) - { - if ($n->is_inf()) - { - return $self->bnan() if $d->is_inf(); # both are inf => NaN - my $s = '+'; # '+inf/+123' or '-inf/-123' - $s = '-' if substr($n->{sign},0,1) ne $d->{sign}; - # +-inf/123 => +-inf - return $self->binf($s); - } - # 123/inf => 0 - return $self->bzero(); - } - } - } + return $self->bnorm(); # normalize (120/100 => 6/5) + } + + return $n->copy() if ref $n; # already a BigRat + + if (!defined $n) { + $self->{_n} = $MBI->_zero(); # undef => 0 + $self->{_d} = $MBI->_one(); + $self->{sign} = '+'; + return $self; + } + + # string input with / delimiter + if ($n =~ m|\s*/\s*|) { + return $class->bnan() if $n =~ m|/.*/|; # 1/2/3 isn't valid + return $class->bnan() if $n =~ m|/\s*$|; # 1/ isn't valid + ($n, $d) = split (/\//, $n); + # try as BigFloats first + if (($n =~ /[\.eE]/) || ($d =~ /[\.eE]/)) { + local $Math::BigFloat::accuracy = undef; + local $Math::BigFloat::precision = undef; + + # one of them looks like a float + my $nf = Math::BigFloat->new($n, undef, undef); + $self->{sign} = '+'; + return $self->bnan() if $nf->is_nan(); + + $self->{_n} = $MBI->_copy($nf->{_m}); # get mantissa + + # now correct $self->{_n} due to $n + my $f = Math::BigFloat->new($d, undef, undef); + return $self->bnan() if $f->is_nan(); + $self->{_d} = $MBI->_copy($f->{_m}); + + # calculate the difference between nE and dE + my $diff_e = $nf->exponent()->bsub($f->exponent); + if ($diff_e->is_negative()) { + # < 0: mul d with it + $MBI->_lsft($self->{_d}, $MBI->_new($diff_e->babs()), 10); + } elsif (!$diff_e->is_zero()) { + # > 0: mul n with it + $MBI->_lsft($self->{_n}, $MBI->_new($diff_e), 10); + } + } else { + # both d and n look like (big)ints + + $self->{sign} = '+'; # no sign => '+' + $self->{_n} = undef; + $self->{_d} = undef; + if ($n =~ /^([+-]?)0*([0-9]+)\z/) { # first part ok? + $self->{sign} = $1 || '+'; # no sign => '+' + $self->{_n} = $MBI->_new($2 || 0); + } + + if ($d =~ /^([+-]?)0*([0-9]+)\z/) { # second part ok? + $self->{sign} =~ tr/+-/-+/ if ($1 || '') eq '-'; # negate if second part neg. + $self->{_d} = $MBI->_new($2 || 0); + } + + if (!defined $self->{_n} || !defined $self->{_d}) { + $d = Math::BigInt->new($d, undef, undef) unless ref $d; + $n = Math::BigInt->new($n, undef, undef) unless ref $n; + + if ($n->{sign} =~ /^[+-]$/ && $d->{sign} =~ /^[+-]$/) { + # both parts are ok as integers (weird things like ' 1e0' + $self->{_n} = $MBI->_copy($n->{value}); + $self->{_d} = $MBI->_copy($d->{value}); + $self->{sign} = $n->{sign}; + $self->{sign} =~ tr/+-/-+/ if $d->{sign} eq '-'; # -1/-2 => 1/2 + return $self->bnorm(); + } + + $self->{sign} = '+'; # a default sign + return $self->bnan() if $n->is_nan() || $d->is_nan(); + + # handle inf cases: + if ($n->is_inf() || $d->is_inf()) { + if ($n->is_inf()) { + return $self->bnan() if $d->is_inf(); # both are inf => NaN + my $s = '+'; # '+inf/+123' or '-inf/-123' + $s = '-' if substr($n->{sign}, 0, 1) ne $d->{sign}; + # +-inf/123 => +-inf + return $self->binf($s); + } + # 123/inf => 0 + return $self->bzero(); + } + } + } - return $self->bnorm(); - } + return $self->bnorm(); + } + + # simple string input + if (($n =~ /[\.eE]/) && $n !~ /^0x/) { + # looks like a float, quacks like a float, so probably is a float + $self->{sign} = 'NaN'; + local $Math::BigFloat::accuracy = undef; + local $Math::BigFloat::precision = undef; + $self->_new_from_float(Math::BigFloat->new($n, undef, undef)); + } else { + # for simple forms, use $MBI directly + if ($n =~ /^([+-]?)0*([0-9]+)\z/) { + $self->{sign} = $1 || '+'; + $self->{_n} = $MBI->_new($2 || 0); + $self->{_d} = $MBI->_one(); + } + elsif ($n =~ /^\s*([+-]?)inf(inity)?\s*\z/i) { + my $sgn = $1 || '+'; + $self->{sign} = $sgn . 'inf'; # set a default sign for bstr() + $self->binf($sgn); + } - # simple string input - if (($n =~ /[\.eE]/) && $n !~ /^0x/) - { - # looks like a float, quacks like a float, so probably is a float - $self->{sign} = 'NaN'; - local $Math::BigFloat::accuracy = undef; - local $Math::BigFloat::precision = undef; - $self->_new_from_float(Math::BigFloat->new($n,undef,undef)); - } - else - { - # for simple forms, use $MBI directly - if ($n =~ /^([+-]?)0*([0-9]+)\z/) - { - $self->{sign} = $1 || '+'; - $self->{_n} = $MBI->_new($2 || 0); - $self->{_d} = $MBI->_one(); - } - else - { - my $n = Math::BigInt->new($n,undef,undef); - $self->{_n} = $MBI->_copy($n->{value}); - $self->{_d} = $MBI->_one(); - $self->{sign} = $n->{sign}; - return $self->bnan() if $self->{sign} eq 'NaN'; - return $self->binf($self->{sign}) if $self->{sign} =~ /^[+-]inf$/; - } + else { + my $n = Math::BigInt->new($n, undef, undef); + $self->{_n} = $MBI->_copy($n->{value}); + $self->{_d} = $MBI->_one(); + $self->{sign} = $n->{sign}; + return $self->bnan() if $self->{sign} eq 'NaN'; + } } - $self->bnorm(); - } -sub copy - { - # if two arguments, the first one is the class to "swallow" subclasses - my ($c,$x) = @_; + $self->bnorm(); +} - if (scalar @_ == 1) - { - $x = $_[0]; - $c = ref($x); - } - return unless ref($x); # only for objects +sub copy { + my $self = shift; + my $selfref = ref $self; + my $class = $selfref || $self; - my $self = bless {}, $c; + # If called as a class method, the object to copy is the next argument. - $self->{sign} = $x->{sign}; - $self->{_d} = $MBI->_copy($x->{_d}); - $self->{_n} = $MBI->_copy($x->{_n}); - $self->{_a} = $x->{_a} if defined $x->{_a}; - $self->{_p} = $x->{_p} if defined $x->{_p}; - $self; - } + $self = shift() unless $selfref; + + my $copy = bless {}, $class; + + $copy->{sign} = $self->{sign}; + $copy->{_d} = $MBI->_copy($self->{_d}); + $copy->{_n} = $MBI->_copy($self->{_n}); + $copy->{_a} = $self->{_a} if defined $self->{_a}; + $copy->{_p} = $self->{_p} if defined $self->{_p}; + + $copy; +} ############################################################################## @@ -401,15 +411,13 @@ sub bnorm my ($self,$x) = ref($_[0]) ? (undef,$_[0]) : objectify(1,@_); # Both parts must be objects of whatever we are using today. - if ( my $c = $MBI->_check($x->{_n}) ) + if (my $c = $MBI->_check($x->{_n})) { - require Carp; Carp::croak( - "n did not pass the self-check ($c) in bnorm()"); + Carp::croak("n did not pass the self-check ($c) in bnorm()"); } - if ( my $c = $MBI->_check($x->{_d}) ) + if (my $c = $MBI->_check($x->{_d})) { - require Carp; Carp::croak( - "d did not pass the self-check ($c) in bnorm()"); + Carp::croak("d did not pass the self-check ($c) in bnorm()"); } # no normalize for NaN, inf etc. @@ -464,7 +472,6 @@ sub _bnan if ($_trap_nan) { - require Carp; my $class = ref($self); # "$self" below will stringify the object, this blows up if $self is a # partial object (happens under trap_nan), so fix it beforehand @@ -483,7 +490,6 @@ sub _binf if ($_trap_inf) { - require Carp; my $class = ref($self); # "$self" below will stringify the object, this blows up if $self is a # partial object (happens under trap_nan), so fix it beforehand @@ -545,16 +551,16 @@ sub badd # and bnorm() will then take care of the rest # 5 * 3 - $x->{_n} = $MBI->_mul( $x->{_n}, $y->{_d}); + $x->{_n} = $MBI->_mul($x->{_n}, $y->{_d}); # 7 * 4 - my $m = $MBI->_mul( $MBI->_copy( $y->{_n} ), $x->{_d} ); + my $m = $MBI->_mul($MBI->_copy($y->{_n}), $x->{_d}); # 5 * 3 + 7 * 4 - ($x->{_n}, $x->{sign}) = _e_add( $x->{_n}, $m, $x->{sign}, $y->{sign}); + ($x->{_n}, $x->{sign}) = _e_add($x->{_n}, $m, $x->{sign}, $y->{sign}); # 4 * 3 - $x->{_d} = $MBI->_mul( $x->{_d}, $y->{_d}); + $x->{_d} = $MBI->_mul($x->{_d}, $y->{_d}); # normalize result, and possible round $x->bnorm()->round(@r); @@ -618,8 +624,8 @@ sub bmul # - * - = ----- = - = - # 4 3 4 * 3 12 6 - $x->{_n} = $MBI->_mul( $x->{_n}, $y->{_n}); - $x->{_d} = $MBI->_mul( $x->{_d}, $y->{_d}); + $x->{_n} = $MBI->_mul($x->{_n}, $y->{_n}); + $x->{_d} = $MBI->_mul($x->{_d}, $y->{_d}); # compute new sign $x->{sign} = $x->{sign} eq $y->{sign} ? '+' : '-'; @@ -725,8 +731,8 @@ sub bdiv # - / - == - * - # 4 3 4 1 - $x->{_n} = $MBI->_mul( $x->{_n}, $y->{_d}); - $x->{_d} = $MBI->_mul( $x->{_d}, $y->{_n}); + $x->{_n} = $MBI->_mul($x->{_n}, $y->{_d}); + $x->{_d} = $MBI->_mul($x->{_d}, $y->{_n}); # compute new sign $x->{sign} = $x->{sign} eq $y->{sign} ? '+' : '-'; @@ -813,14 +819,14 @@ sub bdec if ($x->{sign} eq '-') { - $x->{_n} = $MBI->_add( $x->{_n}, $x->{_d}); # -5/2 => -7/2 + $x->{_n} = $MBI->_add($x->{_n}, $x->{_d}); # -5/2 => -7/2 } else { if ($MBI->_acmp($x->{_n},$x->{_d}) < 0) # n < d? { # 1/3 -- => -2/3 - $x->{_n} = $MBI->_sub( $MBI->_copy($x->{_d}), $x->{_n}); + $x->{_n} = $MBI->_sub($MBI->_copy($x->{_d}), $x->{_n}); $x->{sign} = '-'; } else @@ -843,7 +849,7 @@ sub binc if ($MBI->_acmp($x->{_n},$x->{_d}) < 0) { # -1/3 ++ => 2/3 (overflow at 0) - $x->{_n} = $MBI->_sub( $MBI->_copy($x->{_d}), $x->{_n}); + $x->{_n} = $MBI->_sub($MBI->_copy($x->{_d}), $x->{_n}); $x->{sign} = '+'; } else @@ -948,9 +954,9 @@ sub parts return ($c->binf(),$c->binf()) if $x->{sign} eq '+inf'; return ($c->binf('-'),$c->binf()) if $x->{sign} eq '-inf'; - my $n = $c->new( $MBI->_str($x->{_n})); + my $n = $c->new($MBI->_str($x->{_n})); $n->{sign} = $x->{sign}; - my $d = $c->new( $MBI->_str($x->{_d})); + my $d = $c->new($MBI->_str($x->{_d})); ($n,$d); } @@ -1097,36 +1103,71 @@ sub bpow # a/b = -\/ (a/b) ** d # (a/b) ** n == (a ** n) / (b ** n) - $MBI->_pow($x->{_n}, $y->{_n} ); - $MBI->_pow($x->{_d}, $y->{_n} ); + $MBI->_pow($x->{_n}, $y->{_n}); + $MBI->_pow($x->{_d}, $y->{_n}); return $x->broot($MBI->_str($y->{_d}),@r); # n/d => root(n) } sub blog { + # Return the logarithm of the operand. If a second operand is defined, that + # value is used as the base, otherwise the base is assumed to be Euler's + # constant. + + # Don't objectify the base, since an undefined base, as in $x->blog() or + # $x->blog(undef) signals that the base is Euler's number. + # set up parameters - my ($self,$x,$y,@r) = (ref($_[0]),@_); + my ($self,$x,$base,@r) = (ref($_[0]),@_); # objectify is costly, so avoid it if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { - ($self,$x,$y,@r) = objectify(2,$class,@_); + ($self,$x,$base,@r) = objectify(1,$class,@_); } - # blog(1,Y) => 0 - return $x->bzero() if $x->is_one() && $y->{sign} eq '+'; + return $x if $x->modify('blog'); - # $x <= 0 => NaN - return $x->bnan() if $x->is_zero() || $x->{sign} ne '+' || $y->{sign} ne '+'; + # Handle all exception cases and all trivial cases. I have used Wolfram Alpha + # (http://www.wolframalpha.com) as the reference for these cases. - if ($x->is_int() && $y->is_int()) - { - return $self->new($x->as_number()->blog($y->as_number(),@r)); - } + return $x -> bnan() if $x -> is_nan(); - # do it with floats - $x->_new_from_float( $x->_as_float()->blog(Math::BigFloat->new("$y"),@r) ); + if (defined $base) { + $base = $self -> new($base) unless ref $base; + if ($base -> is_nan() || $base -> is_one()) { + return $x -> bnan(); + } elsif ($base -> is_inf() || $base -> is_zero()) { + return $x -> bnan() if $x -> is_inf() || $x -> is_zero(); + return $x -> bzero(); + } elsif ($base -> is_negative()) { # -inf < base < 0 + return $x -> bzero() if $x -> is_one(); # x = 1 + return $x -> bone() if $x == $base; # x = base + return $x -> bnan(); # otherwise + } + return $x -> bone() if $x == $base; # 0 < base && 0 < x < inf + } + + # We now know that the base is either undefined or positive and finite. + + if ($x -> is_inf()) { # x = +/-inf + my $sign = defined $base && $base < 1 ? '-' : '+'; + return $x -> binf($sign); + } elsif ($x -> is_neg()) { # -inf < x < 0 + return $x -> bnan(); + } elsif ($x -> is_one()) { # x = 1 + return $x -> bzero(); + } elsif ($x -> is_zero()) { # x = 0 + my $sign = defined $base && $base < 1 ? '+' : '-'; + return $x -> binf($sign); + } + + # At this point we are done handling all exception cases and trivial cases. + + # Do it with Math::BigFloats and convert back to Math::BigRat. + $base = $base -> _as_float() if defined $base; + $x -> _new_from_float($x -> _as_float() -> blog($base, @r)); } sub bexp @@ -1252,7 +1293,7 @@ sub bnok } # do it with floats - $x->_new_from_float( $x->_as_float()->bnok(Math::BigFloat->new("$y"),@r) ); + $x->_new_from_float($x->_as_float()->bnok(Math::BigFloat->new("$y"),@r)); } sub _float_from_part @@ -1279,7 +1320,7 @@ sub _as_float if ($a != 0 || !$MBI->_is_one($x->{_d})) { # n/d - return scalar Math::BigFloat->new($x->{sign} . $MBI->_str($x->{_n}))->bdiv( $MBI->_str($x->{_d}), $x->accuracy()); + return scalar Math::BigFloat->new($x->{sign} . $MBI->_str($x->{_n}))->bdiv($MBI->_str($x->{_d}), $x->accuracy()); } # just n Math::BigFloat->new($x->{sign} . $MBI->_str($x->{_n})); @@ -1301,7 +1342,7 @@ sub broot } # do it with floats - $x->_new_from_float( $x->_as_float()->broot($y->_as_float(),@r) )->bnorm()->bround(@r); + $x->_new_from_float($x->_as_float()->broot($y->_as_float(),@r))->bnorm()->bround(@r); } sub bmodpow @@ -1367,8 +1408,8 @@ sub bsqrt local $Math::BigInt::precision = undef; local $Math::BigInt::accuracy = undef; - $x->{_n} = _float_from_part( $x->{_n} )->bsqrt(); - $x->{_d} = _float_from_part( $x->{_d} )->bsqrt(); + $x->{_n} = _float_from_part($x->{_n})->bsqrt(); + $x->{_d} = _float_from_part($x->{_d})->bsqrt(); # XXX TODO: we probably can optimize this: @@ -1376,19 +1417,19 @@ sub bsqrt if ($x->{_d}->{_es} ne '+') { $x->{_n}->blsft($x->{_d}->exponent()->babs(),10); # 7.1/4.51 => 7.1/45.1 - $x->{_d} = $MBI->_copy( $x->{_d}->{_m} ); # 7.1/45.1 => 71/45.1 + $x->{_d} = $MBI->_copy($x->{_d}->{_m}); # 7.1/45.1 => 71/45.1 } # if sqrt(N) was not integer if ($x->{_n}->{_es} ne '+') { $x->{_d}->blsft($x->{_n}->exponent()->babs(),10); # 71/45.1 => 710/45.1 - $x->{_n} = $MBI->_copy( $x->{_n}->{_m} ); # 710/45.1 => 710/451 + $x->{_n} = $MBI->_copy($x->{_n}->{_m}); # 710/45.1 => 710/451 } # convert parts to $MBI again - $x->{_n} = $MBI->_lsft( $MBI->_copy( $x->{_n}->{_m} ), $x->{_n}->{_e}, 10) + $x->{_n} = $MBI->_lsft($MBI->_copy($x->{_n}->{_m}), $x->{_n}->{_e}, 10) if ref($x->{_n}) ne $MBI && ref($x->{_n}) ne 'ARRAY'; - $x->{_d} = $MBI->_lsft( $MBI->_copy( $x->{_d}->{_m} ), $x->{_d}->{_e}, 10) + $x->{_d} = $MBI->_lsft($MBI->_copy($x->{_d}->{_m}), $x->{_d}->{_e}, 10) if ref($x->{_d}) ne $MBI && ref($x->{_d}) ne 'ARRAY'; $x->bnorm()->round(@r); @@ -1400,7 +1441,7 @@ sub blsft $b = 2 unless defined $b; $b = $self->new($b) unless ref ($b); - $x->bmul( $b->copy()->bpow($y), @r); + $x->bmul($b->copy()->bpow($y), @r); $x; } @@ -1410,7 +1451,7 @@ sub brsft $b = 2 unless defined $b; $b = $self->new($b) unless ref ($b); - $x->bdiv( $b->copy()->bpow($y), @r); + $x->bdiv($b->copy()->bpow($y), @r); $x; } @@ -1468,8 +1509,8 @@ sub bcmp return -1 if $xz && $y->{sign} eq '+'; # 0 <=> +y return 1 if $yz && $x->{sign} eq '+'; # +x <=> 0 - my $t = $MBI->_mul( $MBI->_copy($x->{_n}), $y->{_d}); - my $u = $MBI->_mul( $MBI->_copy($y->{_n}), $x->{_d}); + my $t = $MBI->_mul($MBI->_copy($x->{_n}), $y->{_d}); + my $u = $MBI->_mul($MBI->_copy($y->{_n}), $x->{_d}); my $cmp = $MBI->_acmp($t,$u); # signs are equal $cmp = -$cmp if $x->{sign} eq '-'; # both are '-' => reverse @@ -1497,8 +1538,8 @@ sub bacmp return -1; } - my $t = $MBI->_mul( $MBI->_copy($x->{_n}), $y->{_d}); - my $u = $MBI->_mul( $MBI->_copy($y->{_n}), $x->{_d}); + my $t = $MBI->_mul($MBI->_copy($x->{_n}), $y->{_d}); + my $u = $MBI->_mul($MBI->_copy($y->{_n}), $x->{_d}); $MBI->_acmp($t,$u); # ignore signs } @@ -1527,7 +1568,7 @@ sub as_number return Math::BigInt->new($x->{sign}) if $x->{sign} !~ /^[+-]$/; my $u = Math::BigInt->bzero(); - $u->{value} = $MBI->_div( $MBI->_copy($x->{_n}), $x->{_d}); # 22/7 => 3 + $u->{value} = $MBI->_div($MBI->_copy($x->{_n}), $x->{_d}); # 22/7 => 3 $u->bneg if $x->{sign} eq '-'; # no negative zero $u; } @@ -1549,7 +1590,7 @@ sub as_float # n $u->{_m} = $MBI->_copy($x->{_n}); $u->{_e} = $MBI->_zero(); - $u->bdiv( $MBI->_str($x->{_d}), @r); + $u->bdiv($MBI->_str($x->{_d}), @r); # return $u $u; } @@ -1609,7 +1650,7 @@ sub from_oct { push @parts, Math::BigInt->from_oct($c); } - $class->new ( @parts ); + $class->new (@parts); } ############################################################################## @@ -1622,9 +1663,9 @@ sub import my $lib = ''; my @a; my $try = 'try'; - for ( my $i = 0; $i < $l ; $i++) + for (my $i = 0; $i < $l ; $i++) { - if ( $_[$i] eq ':constant' ) + if ($_[$i] eq ':constant') { # this rest causes overlord er load to step in overload::constant float => sub { $self->new(shift); }; @@ -1674,12 +1715,12 @@ sub import push @import, $try => $lib if $lib ne ''; # MBI already loaded, so feed it our lib arguments - Math::BigInt->import( @import ); + Math::BigInt->import(@import); $MBI = Math::BigFloat->config()->{lib}; # register us with MBI to get notified of future lib changes - Math::BigInt::_register_callback( $self, sub { $MBI = $_[0]; } ); + Math::BigInt::_register_callback($self, sub { $MBI = $_[0]; }); # any non :constant stuff is handled by our parent, Exporter (loaded # by Math::BigFloat, even if @_ is empty, to give it a chance diff --git a/cpan/Math-BigRat/t/Math/BigRat/Test.pm b/cpan/Math-BigRat/t/Math/BigRat/Test.pm index 74f9f9d004..b7150c468e 100644 --- a/cpan/Math-BigRat/t/Math/BigRat/Test.pm +++ b/cpan/Math-BigRat/t/Math/BigRat/Test.pm @@ -1,13 +1,13 @@ package Math::BigRat::Test; -require 5.005_02; +require 5.006; use strict; +use warnings; use Exporter; use Math::BigRat; use Math::BigFloat; -use vars qw($VERSION @ISA - $accuracy $precision $round_mode $div_scale); +our ($VERSION, @ISA, $accuracy, $precision, $round_mode, $div_scale); @ISA = qw(Math::BigRat Exporter); $VERSION = 0.04; @@ -21,102 +21,96 @@ $div_scale = 40; my $class = 'Math::BigRat::Test'; -#ub new -#{ -# my $proto = shift; -# my $class = ref($proto) || $proto; +#sub new { +# my $proto = shift; +# my $class = ref($proto) || $proto; # -# my $value = shift; -# my $a = $accuracy; $a = $_[0] if defined $_[0]; -# my $p = $precision; $p = $_[1] if defined $_[1]; -# # Store the floating point value -# my $self = Math::BigFloat->new($value,$a,$p,$round_mode); -# bless $self, $class; -# $self->{'_custom'} = 1; # make sure this never goes away -# return $self; +# my $value = shift; +# my $a = $accuracy; $a = $_[0] if defined $_[0]; +# my $p = $precision; $p = $_[1] if defined $_[1]; +# # Store the floating point value +# my $self = Math::BigFloat->new($value, $a, $p, $round_mode); +# bless $self, $class; +# $self->{'_custom'} = 1; # make sure this never goes away +# return $self; #} -BEGIN - { - *fstr = \&bstr; - *fsstr = \&bsstr; - *objectify = \&Math::BigInt::objectify; - *AUTOLOAD = \&Math::BigRat::AUTOLOAD; - no strict 'refs'; - foreach my $method ( qw/ div acmp floor ceil root sqrt log fac modpow modinv/) - { - *{'b' . $method} = \&{'Math::BigRat::b' . $method}; +BEGIN { + *fstr = \&bstr; + *fsstr = \&bsstr; + *objectify = \&Math::BigInt::objectify; + *AUTOLOAD = \&Math::BigRat::AUTOLOAD; + no strict 'refs'; + foreach my $method (qw/div acmp floor ceil root sqrt log fac modpow modinv/) { + *{'b' . $method} = \&{'Math::BigRat::b' . $method}; } - } - -sub fround - { - my ($x,$a) = @_; - - #print "$a $accuracy $precision $round_mode\n"; - Math::BigFloat->round_mode($round_mode); - Math::BigFloat->accuracy($a || $accuracy); - Math::BigFloat->precision(undef); - my $y = Math::BigFloat->new($x->bsstr(),undef,undef); - $class->new($y->fround($a)); - } - -sub ffround - { - my ($x,$p) = @_; - - Math::BigFloat->round_mode($round_mode); - Math::BigFloat->accuracy(undef); - Math::BigFloat->precision($p || $precision); - my $y = Math::BigFloat->new($x->bsstr(),undef,undef); - $class->new($y->ffround($p)); - } - -sub bstr - { - # calculate a BigFloat compatible string output - my ($x) = @_; - - $x = $class->new($x) unless ref $x; - - if ($x->{sign} !~ /^[+-]$/) # inf, NaN etc - { - my $s = $x->{sign}; $s =~ s/^\+//; # +inf => inf - return $s; +} + +sub fround { + my ($x, $a) = @_; + + #print "$a $accuracy $precision $round_mode\n"; + Math::BigFloat->round_mode($round_mode); + Math::BigFloat->accuracy($a || $accuracy); + Math::BigFloat->precision(undef); + my $y = Math::BigFloat->new($x->bsstr(), undef, undef); + $class->new($y->fround($a)); +} + +sub ffround { + my ($x, $p) = @_; + + Math::BigFloat->round_mode($round_mode); + Math::BigFloat->accuracy(undef); + Math::BigFloat->precision($p || $precision); + my $y = Math::BigFloat->new($x->bsstr(), undef, undef); + $class->new($y->ffround($p)); +} + +sub bstr { + # calculate a BigFloat compatible string output + my ($x) = @_; + + $x = $class->new($x) unless ref $x; + + if ($x->{sign} !~ /^[+-]$/) { # inf, NaN etc + my $s = $x->{sign}; + $s =~ s/^\+//; # +inf => inf + return $s; } - my $s = ''; $s = $x->{sign} if $x->{sign} ne '+'; # +3 vs 3 + my $s = ''; + $s = $x->{sign} if $x->{sign} ne '+'; # +3 vs 3 -# print " bstr \$x ", $accuracy || $x->{_a} || 'notset', " ", $precision || $x->{_p} || 'notset', "\n"; - return $s.$x->{_n} if $x->{_d}->is_one(); - my $output = Math::BigFloat->new($x->{_n})->bdiv($x->{_d}); - local $Math::BigFloat::accuracy = $accuracy || $x->{_a}; - local $Math::BigFloat::precision = $precision || $x->{_p}; - $s.$output->bstr(); - } + # print " bstr \$x ", $accuracy || $x->{_a} || 'notset', " ", $precision || $x->{_p} || 'notset', "\n"; + return $s.$x->{_n} if $x->{_d}->is_one(); + my $output = Math::BigFloat->new($x->{_n})->bdiv($x->{_d}); + local $Math::BigFloat::accuracy = $accuracy || $x->{_a}; + local $Math::BigFloat::precision = $precision || $x->{_p}; + $s.$output->bstr(); +} -sub numify - { - $_[0]->bsstr(); - } +sub numify { + $_[0]->bsstr(); +} -sub bsstr - { - # calculate a BigFloat compatible string output - my ($x) = @_; +sub bsstr { + # calculate a BigFloat compatible string output + my ($x) = @_; - $x = $class->new($x) unless ref $x; + $x = $class->new($x) unless ref $x; - if ($x->{sign} !~ /^[+-]$/) # inf, NaN etc - { - my $s = $x->{sign}; $s =~ s/^\+//; # +inf => inf - return $s; + if ($x->{sign} !~ /^[+-]$/) { # inf, NaN etc + my $s = $x->{sign}; + $s =~ s/^\+//; # +inf => inf + return $s; } - my $s = ''; $s = $x->{sign} if $x->{sign} ne '+'; # +3 vs 3 + my $s = ''; + $s = $x->{sign} if $x->{sign} ne '+'; # +3 vs 3 - my $output = Math::BigFloat->new($x->{_n})->bdiv($x->{_d}); - return $s.$output->bsstr(); - } + my $output = Math::BigFloat->new($x->{_n})->bdiv($x->{_d}); + return $s.$output->bsstr(); +} 1; diff --git a/cpan/Math-BigRat/t/big_ap.t b/cpan/Math-BigRat/t/big_ap.t index 1b45eddfe7..3b45058120 100644 --- a/cpan/Math-BigRat/t/big_ap.t +++ b/cpan/Math-BigRat/t/big_ap.t @@ -1,94 +1,106 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl # Test that accuracy() and precision() in BigInt/BigFloat do not disturb # the rounding force in BigRat. use strict; +use warnings; + use Test::More tests => 17; use Math::BigInt; use Math::BigFloat; use Math::BigRat; -my $r = 'Math::BigRat'; -my $proper = $r->new('12345678901234567890/2'); -my $proper_inc = $r->new('12345678901234567890/2')->binc(); -my $proper_dec = $r->new('12345678901234567890/2')->bdec(); -my $proper_int = Math::BigInt->new('12345678901234567890'); +my $proper = Math::BigRat->new('12345678901234567890/2'); +my $proper_inc = Math::BigRat->new('12345678901234567890/2')->binc(); +my $proper_dec = Math::BigRat->new('12345678901234567890/2')->bdec(); +my $proper_int = Math::BigInt->new('12345678901234567890'); my $proper_float = Math::BigFloat->new('12345678901234567890'); -my $proper2 = $r->new('12345678901234567890'); +my $proper2 = Math::BigRat->new('12345678901234567890'); print "# Start\n"; Math::BigInt->accuracy(3); Math::BigFloat->accuracy(5); -my ($x,$y,$z); +my ($x, $y, $z); ############################################################################## # new() -$z = $r->new('12345678901234567890/2'); -is ($z,$proper); +$z = Math::BigRat->new('12345678901234567890/2'); +is($z, $proper); + +$z = Math::BigRat->new('1234567890123456789E1'); +is($z, $proper2); + +$z = Math::BigRat->new('12345678901234567890/1E0'); +is($z, $proper2); -$z = $r->new('1234567890123456789E1'); -is ($z,$proper2); +$z = Math::BigRat->new('1234567890123456789e1/1'); +is($z, $proper2); -$z = $r->new('12345678901234567890/1E0'); -is ($z,$proper2); -$z = $r->new('1234567890123456789e1/1'); -is ($z,$proper2); -$z = $r->new('1234567890123456789e1/1E0'); -is ($z,$proper2); +$z = Math::BigRat->new('1234567890123456789e1/1E0'); +is($z, $proper2); -$z = $r->new($proper_int); -is ($z,$proper2); +$z = Math::BigRat->new($proper_int); +is($z, $proper2); -$z = $r->new($proper_float); -is ($z,$proper2); +$z = Math::BigRat->new($proper_float); +is($z, $proper2); ############################################################################## # bdiv -$x = $r->new('12345678901234567890'); $y = Math::BigRat->new('2'); +$x = Math::BigRat->new('12345678901234567890'); +$y = Math::BigRat->new('2'); $z = $x->copy->bdiv($y); -is ($z,$proper); +is($z, $proper); ############################################################################## # bmul -$x = $r->new("$proper"); $y = Math::BigRat->new('1'); +$x = Math::BigRat->new("$proper"); +$y = Math::BigRat->new('1'); $z = $x->copy->bmul($y); -is ($z,$proper); -$z = $r->new('12345678901234567890/1E0'); -is ($z,$proper2); +is($z, $proper); -$z = $r->new($proper_int); -is ($z,$proper2); +$z = Math::BigRat->new('12345678901234567890/1E0'); +is($z, $proper2); -$z = $r->new($proper_float); -is ($z,$proper2); +$z = Math::BigRat->new($proper_int); +is($z, $proper2); + +$z = Math::BigRat->new($proper_float); +is($z, $proper2); ############################################################################## # bdiv -$x = $r->new('12345678901234567890'); $y = Math::BigRat->new('2'); +$x = Math::BigRat->new('12345678901234567890'); +$y = Math::BigRat->new('2'); $z = $x->copy->bdiv($y); -is ($z,$proper); +is($z, $proper); ############################################################################## # bmul -$x = $r->new("$proper"); $y = Math::BigRat->new('1'); +$x = Math::BigRat->new("$proper"); +$y = Math::BigRat->new('1'); $z = $x->copy->bmul($y); -is ($z,$proper); +is($z, $proper); -$x = $r->new("$proper"); $y = Math::BigRat->new('2'); +$x = Math::BigRat->new("$proper"); +$y = Math::BigRat->new('2'); $z = $x->copy->bmul($y); -is ($z,$proper2); +is($z, $proper2); ############################################################################## # binc/bdec -$x = $proper->copy()->binc(); is ($x,$proper_inc); -$x = $proper->copy()->bdec(); is ($x,$proper_dec); +$x = $proper->copy()->binc(); +is($x, $proper_inc); + +$x = $proper->copy()->bdec(); +is($x, $proper_dec); diff --git a/cpan/Math-BigRat/t/bigfltpm.inc b/cpan/Math-BigRat/t/bigfltpm.inc index 9c884b7d9e..90dea8efb4 100644 --- a/cpan/Math-BigRat/t/bigfltpm.inc +++ b/cpan/Math-BigRat/t/bigfltpm.inc @@ -1,8 +1,9 @@ #include this file into another test for subclass testing... -ok ($class->config()->{lib},$CL); - use strict; +use warnings; + +ok ($class->config()->{lib},$CL); my $z; diff --git a/cpan/Math-BigRat/t/bigfltrt.t b/cpan/Math-BigRat/t/bigfltrt.t index 325e6fa77e..3c46000b71 100644 --- a/cpan/Math-BigRat/t/bigfltrt.t +++ b/cpan/Math-BigRat/t/bigfltrt.t @@ -1,17 +1,17 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl use strict; -use Test::More tests => 1; +use warnings; + +use lib 't'; -BEGIN { - unshift @INC, 't'; -} +use Test::More tests => 1; use Math::BigRat::Test lib => 'Calc'; # test via this Subclass -use vars qw ($class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL); -$class = "Math::BigRat::Test"; -$CL = "Math::BigInt::Calc"; +our ($CLASS, $CALC); +$CLASS = "Math::BigRat::Test"; +$CALC = "Math::BigInt::Calc"; pass(); diff --git a/cpan/Math-BigRat/t/biglog.t b/cpan/Math-BigRat/t/biglog.t index 42e9ac8d64..9d729af776 100644 --- a/cpan/Math-BigRat/t/biglog.t +++ b/cpan/Math-BigRat/t/biglog.t @@ -1,8 +1,10 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl # Test blog function (and bpow, since it uses blog), as well as bexp(). use strict; +use warnings; + use Test::More tests => 17; use Math::BigRat; diff --git a/cpan/Math-BigRat/t/bigrat.t b/cpan/Math-BigRat/t/bigrat.t index a640e59244..7ca3be3672 100644 --- a/cpan/Math-BigRat/t/bigrat.t +++ b/cpan/Math-BigRat/t/bigrat.t @@ -1,6 +1,8 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl use strict; +use warnings; + use Test::More tests => 202; # basic testing of Math::BigRat @@ -10,321 +12,472 @@ use Math::BigInt; use Math::BigFloat; # shortcuts -my $cr = 'Math::BigRat'; +my $mbr = 'Math::BigRat'; my $mbi = 'Math::BigInt'; my $mbf = 'Math::BigFloat'; -my ($x,$y,$z); +my ($x, $y, $z); -$x = Math::BigRat->new(1234); is ($x,1234); -isa_ok ($x, 'Math::BigRat'); -is ($x->isa('Math::BigFloat'), 0); -is ($x->isa('Math::BigInt'), 0); +$x = Math::BigRat->new(1234); +is($x, 1234); +isa_ok($x, 'Math::BigRat'); +is($x->isa('Math::BigFloat'), 0); +is($x->isa('Math::BigInt'), 0); ############################################################################## # new and bnorm() -foreach my $func (qw/new bnorm/) - { - $x = $cr->$func(1234); is ($x,1234); +foreach my $func (qw/new bnorm/) { + $x = $mbr->$func(1234); + is($x, 1234, qq|\$x = $mbr->$func(1234)|); - $x = $cr->$func('1234/1'); is ($x,1234); - $x = $cr->$func('1234/2'); is ($x,617); + $x = $mbr->$func("1234/1"); + is($x, 1234, qq|\$x = $mbr->$func("1234/1")|); - $x = $cr->$func('100/1.0'); is ($x,100); - $x = $cr->$func('10.0/1.0'); is ($x,10); - $x = $cr->$func('0.1/10'); is ($x,'1/100'); - $x = $cr->$func('0.1/0.1'); is ($x,'1'); - $x = $cr->$func('1e2/10'); is ($x,10); - $x = $cr->$func('5/1e2'); is ($x,'1/20'); - $x = $cr->$func('1e2/1e1'); is ($x,10); - $x = $cr->$func('1 / 3'); is ($x,'1/3'); - $x = $cr->$func('-1 / 3'); is ($x,'-1/3'); - $x = $cr->$func('NaN'); is ($x,'NaN'); - $x = $cr->$func('inf'); is ($x,'inf'); - $x = $cr->$func('-inf'); is ($x,'-inf'); - $x = $cr->$func('1/'); is ($x,'NaN'); + $x = $mbr->$func("1234/2"); + is($x, 617, qq|\$x = $mbr->$func("1234/2")|); - $x = $cr->$func("0x7e"); is ($x,126); + $x = $mbr->$func("100/1.0"); + is($x, 100, qq|\$x = $mbr->$func("100/1.0")|); - # input ala '1+1/3' isn't parsed ok yet - $x = $cr->$func('1+1/3'); is ($x,'NaN'); + $x = $mbr->$func("10.0/1.0"); + is($x, 10, qq|\$x = $mbr->$func("10.0/1.0")|); - $x = $cr->$func('1/1.2'); is ($x,'5/6'); - $x = $cr->$func('1.3/1.2'); is ($x,'13/12'); - $x = $cr->$func('1.2/1'); is ($x,'6/5'); + $x = $mbr->$func("0.1/10"); + is($x, "1/100", qq|\$x = $mbr->$func("0.1/10")|); - ############################################################################ - # other classes as input + $x = $mbr->$func("0.1/0.1"); + is($x, "1", qq|\$x = $mbr->$func("0.1/0.1")|); - $x = $cr->$func($mbi->new(1231)); is ($x,'1231'); - $x = $cr->$func($mbf->new(1232)); is ($x,'1232'); - $x = $cr->$func($mbf->new(1232.3)); is ($x,'12323/10'); - } + $x = $mbr->$func("1e2/10"); + is($x, 10, qq|\$x = $mbr->$func("1e2/10")|); -my $n = 'numerator'; -my $d = 'denominator'; + $x = $mbr->$func("5/1e2"); + is($x, "1/20", qq|\$x = $mbr->$func("5/1e2")|); -$x = $cr->new('-0'); is ($x,'0'); is ($x->$n(), '0'); is ($x->$d(),'1'); -$x = $cr->new('NaN'); is ($x,'NaN'); is ($x->$n(), 'NaN'); is ($x->$d(),'NaN'); -$x = $cr->new('-NaN'); is ($x,'NaN'); is ($x->$n(), 'NaN'); is ($x->$d(),'NaN'); -$x = $cr->new('-1r4'); is ($x,'NaN'); is ($x->$n(), 'NaN'); is ($x->$d(),'NaN'); + $x = $mbr->$func("1e2/1e1"); + is($x, 10, qq|\$x = $mbr->$func("1e2/1e1")|); -$x = $cr->new('+inf'); is ($x,'inf'); is ($x->$n(), 'inf'); is ($x->$d(),'1'); -$x = $cr->new('-inf'); is ($x,'-inf'); is ($x->$n(), '-inf'); is ($x->$d(),'1'); -$x = $cr->new('123a4'); is ($x,'NaN'); is ($x->$n(), 'NaN'); is ($x->$d(),'NaN'); + $x = $mbr->$func("1 / 3"); + is($x, "1/3", qq|\$x = $mbr->$func("1 / 3")|); -# wrong inputs -$x = $cr->new('1e2e2'); is ($x,'NaN'); is ($x->$n(), 'NaN'); is ($x->$d(),'NaN'); -$x = $cr->new('1+2+2'); is ($x,'NaN'); is ($x->$n(), 'NaN'); is ($x->$d(),'NaN'); -# failed due to BigFloat bug -$x = $cr->new('1.2.2'); is ($x,'NaN'); is ($x->$n(), 'NaN'); is ($x->$d(),'NaN'); + $x = $mbr->$func("-1 / 3"); + is($x, "-1/3", qq|\$x = $mbr->$func("-1 / 3")|); -is ($cr->new('123a4'),'NaN'); -is ($cr->new('123e4'),'1230000'); -is ($cr->new('-NaN'),'NaN'); -is ($cr->new('NaN'),'NaN'); -is ($cr->new('+inf'),'inf'); -is ($cr->new('-inf'),'-inf'); + $x = $mbr->$func("NaN"); + is($x, "NaN", qq|\$x = $mbr->$func("NaN")|); -############################################################################## -# two Bigints + $x = $mbr->$func("inf"); + is($x, "inf", qq|\$x = $mbr->$func("inf")|); -is ($cr->new($mbi->new(3),$mbi->new(7))->badd(1),'10/7'); -is ($cr->new($mbi->new(-13),$mbi->new(7)),'-13/7'); -is ($cr->new($mbi->new(13),$mbi->new(-7)),'-13/7'); -is ($cr->new($mbi->new(-13),$mbi->new(-7)),'13/7'); + $x = $mbr->$func("-inf"); + is($x, "-inf", qq|\$x = $mbr->$func("-inf")|); -############################################################################## -# mixed arguments + $x = $mbr->$func("1/"); + is($x, "NaN", qq|\$x = $mbr->$func("1/")|); -is ($cr->new('3/7')->badd(1),'10/7'); -is ($cr->new('3/10')->badd(1.1),'7/5'); -is ($cr->new('3/7')->badd($mbi->new(1)),'10/7'); -is ($cr->new('3/10')->badd($mbf->new('1.1')),'7/5'); + $x = $mbr->$func("0x7e"); + is($x, 126, qq|\$x = $mbr->$func("0x7e")|); -is ($cr->new('3/7')->bsub(1),'-4/7'); -is ($cr->new('3/10')->bsub(1.1),'-4/5'); -is ($cr->new('3/7')->bsub($mbi->new(1)),'-4/7'); -is ($cr->new('3/10')->bsub($mbf->new('1.1')),'-4/5'); + # input ala "1+1/3" isn"t parsed ok yet + $x = $mbr->$func("1+1/3"); + is($x, "NaN", qq|\$x = $mbr->$func("1+1/3")|); -is ($cr->new('3/7')->bmul(1),'3/7'); -is ($cr->new('3/10')->bmul(1.1),'33/100'); -is ($cr->new('3/7')->bmul($mbi->new(1)),'3/7'); -is ($cr->new('3/10')->bmul($mbf->new('1.1')),'33/100'); + $x = $mbr->$func("1/1.2"); + is($x, "5/6", qq|\$x = $mbr->$func("1/1.2")|); -is ($cr->new('3/7')->bdiv(1),'3/7'); -is ($cr->new('3/10')->bdiv(1.1),'3/11'); -is ($cr->new('3/7')->bdiv($mbi->new(1)),'3/7'); -is ($cr->new('3/10')->bdiv($mbf->new('1.1')),'3/11'); + $x = $mbr->$func("1.3/1.2"); + is($x, "13/12", qq|\$x = $mbr->$func("1.3/1.2")|); -############################################################################## -$x = $cr->new('1/4'); $y = $cr->new('1/3'); + $x = $mbr->$func("1.2/1"); + is($x, "6/5", qq|\$x = $mbr->$func("1.2/1")|); -is ($x + $y, '7/12'); -is ($x * $y, '1/12'); -is ($x / $y, '3/4'); + ############################################################################ + # other classes as input -$x = $cr->new('7/5'); $x *= '3/2'; -is ($x,'21/10'); -$x -= '0.1'; -is ($x,'2'); # not 21/10 + $x = $mbr->$func($mbi->new(1231)); + is($x, "1231", qq|\$x = $mbr->$func($mbi->new(1231))|); + + $x = $mbr->$func($mbf->new(1232)); + is($x, "1232", qq|\$x = $mbr->$func($mbf->new(1232))|); -$x = $cr->new('2/3'); $y = $cr->new('3/2'); -is ($x > $y,''); -is ($x < $y,1); -is ($x == $y,''); + $x = $mbr->$func($mbf->new(1232.3)); + is($x, "12323/10", qq|\$x = $mbr->$func($mbf->new(1232.3))|); +} -$x = $cr->new('-2/3'); $y = $cr->new('3/2'); -is ($x > $y,''); -is ($x < $y,'1'); -is ($x == $y,''); +my $n = 'numerator'; +my $d = 'denominator'; + +$x = $mbr->new('-0'); +is($x, '0'); + is($x->$n(), '0'); +is($x->$d(), '1'); + +$x = $mbr->new('NaN'); +is($x, 'NaN'); is($x->$n(), 'NaN'); +is($x->$d(), 'NaN'); + +$x = $mbr->new('-NaN'); +is($x, 'NaN'); is($x->$n(), 'NaN'); +is($x->$d(), 'NaN'); + +$x = $mbr->new('-1r4'); +is($x, 'NaN'); is($x->$n(), 'NaN'); +is($x->$d(), 'NaN'); -$x = $cr->new('-2/3'); $y = $cr->new('-2/3'); -is ($x > $y,''); -is ($x < $y,''); -is ($x == $y,'1'); +$x = $mbr->new('+inf'); +is($x, 'inf'); is($x->$n(), 'inf'); +is($x->$d(), '1'); -$x = $cr->new('-2/3'); $y = $cr->new('-1/3'); -is ($x > $y,''); -is ($x < $y,'1'); -is ($x == $y,''); +$x = $mbr->new('-inf'); +is($x, '-inf'); +is($x->$n(), '-inf'); +is($x->$d(), '1'); + +$x = $mbr->new('123a4'); +is($x, 'NaN'); +is($x->$n(), 'NaN'); +is($x->$d(), 'NaN'); + +# wrong inputs +$x = $mbr->new('1e2e2'); +is($x, 'NaN'); +is($x->$n(), 'NaN'); +is($x->$d(), 'NaN'); + +$x = $mbr->new('1+2+2'); +is($x, 'NaN'); +is($x->$n(), 'NaN'); +is($x->$d(), 'NaN'); + +# failed due to BigFloat bug +$x = $mbr->new('1.2.2'); +is($x, 'NaN'); +is($x->$n(), 'NaN'); +is($x->$d(), 'NaN'); + +is($mbr->new('123a4'), 'NaN'); +is($mbr->new('123e4'), '1230000'); +is($mbr->new('-NaN'), 'NaN'); +is($mbr->new('NaN'), 'NaN'); +is($mbr->new('+inf'), 'inf'); +is($mbr->new('-inf'), '-inf'); -$x = $cr->new('-124'); $y = $cr->new('-122'); -is ($x->bacmp($y),1); +############################################################################## +# two Bigints -$x = $cr->new('-124'); $y = $cr->new('-122'); -is ($x->bcmp($y),-1); +is($mbr->new($mbi->new(3), $mbi->new(7))->badd(1), '10/7'); +is($mbr->new($mbi->new(-13), $mbi->new(7)), '-13/7'); +is($mbr->new($mbi->new(13), $mbi->new(-7)), '-13/7'); +is($mbr->new($mbi->new(-13), $mbi->new(-7)), '13/7'); -$x = $cr->new('3/7'); $y = $cr->new('5/7'); -is ($x+$y,'8/7'); +############################################################################## +# mixed arguments -$x = $cr->new('3/7'); $y = $cr->new('5/7'); -is ($x*$y,'15/49'); +is($mbr->new('3/7')->badd(1), '10/7'); +is($mbr->new('3/10')->badd(1.1), '7/5'); +is($mbr->new('3/7')->badd($mbi->new(1)), '10/7'); +is($mbr->new('3/10')->badd($mbf->new('1.1')), '7/5'); -$x = $cr->new('3/5'); $y = $cr->new('5/7'); -is ($x*$y,'3/7'); +is($mbr->new('3/7')->bsub(1), '-4/7'); +is($mbr->new('3/10')->bsub(1.1), '-4/5'); +is($mbr->new('3/7')->bsub($mbi->new(1)), '-4/7'); +is($mbr->new('3/10')->bsub($mbf->new('1.1')), '-4/5'); -$x = $cr->new('3/5'); $y = $cr->new('5/7'); -is ($x/$y,'21/25'); +is($mbr->new('3/7')->bmul(1), '3/7'); +is($mbr->new('3/10')->bmul(1.1), '33/100'); +is($mbr->new('3/7')->bmul($mbi->new(1)), '3/7'); +is($mbr->new('3/10')->bmul($mbf->new('1.1')), '33/100'); -$x = $cr->new('7/4'); $y = $cr->new('1'); -is ($x % $y,'3/4'); +is($mbr->new('3/7')->bdiv(1), '3/7'); +is($mbr->new('3/10')->bdiv(1.1), '3/11'); +is($mbr->new('3/7')->bdiv($mbi->new(1)), '3/7'); +is($mbr->new('3/10')->bdiv($mbf->new('1.1')), '3/11'); -$x = $cr->new('7/4'); $y = $cr->new('5/13'); -is ($x % $y,'11/52'); +############################################################################## +$x = $mbr->new('1/4'); +$y = $mbr->new('1/3'); -$x = $cr->new('7/4'); $y = $cr->new('5/9'); -is ($x % $y,'1/12'); +is($x + $y, '7/12'); +is($x * $y, '1/12'); +is($x / $y, '3/4'); -$x = $cr->new('-144/9')->bsqrt(); is ($x,'NaN'); -$x = $cr->new('144/9')->bsqrt(); is ($x,'4'); -$x = $cr->new('3/4')->bsqrt(); is ($x, - '1732050807568877293527446341505872366943/' - .'2000000000000000000000000000000000000000'); +$x = $mbr->new('7/5'); +$x *= '3/2'; +is($x, '21/10'); +$x -= '0.1'; +is($x, '2'); # not 21/10 + +$x = $mbr->new('2/3'); +$y = $mbr->new('3/2'); +is($x > $y, ''); +is($x < $y, 1); +is($x == $y, ''); + +$x = $mbr->new('-2/3'); +$y = $mbr->new('3/2'); +is($x > $y, ''); +is($x < $y, '1'); +is($x == $y, ''); + +$x = $mbr->new('-2/3'); +$y = $mbr->new('-2/3'); +is($x > $y, ''); +is($x < $y, ''); +is($x == $y, '1'); + +$x = $mbr->new('-2/3'); +$y = $mbr->new('-1/3'); +is($x > $y, ''); +is($x < $y, '1'); +is($x == $y, ''); + +$x = $mbr->new('-124'); +$y = $mbr->new('-122'); +is($x->bacmp($y), 1); + +$x = $mbr->new('-124'); +$y = $mbr->new('-122'); +is($x->bcmp($y), -1); + +$x = $mbr->new('3/7'); +$y = $mbr->new('5/7'); +is($x+$y, '8/7'); + +$x = $mbr->new('3/7'); +$y = $mbr->new('5/7'); +is($x*$y, '15/49'); + +$x = $mbr->new('3/5'); +$y = $mbr->new('5/7'); +is($x*$y, '3/7'); + +$x = $mbr->new('3/5'); +$y = $mbr->new('5/7'); +is($x/$y, '21/25'); + +$x = $mbr->new('7/4'); +$y = $mbr->new('1'); +is($x % $y, '3/4'); + +$x = $mbr->new('7/4'); +$y = $mbr->new('5/13'); +is($x % $y, '11/52'); + +$x = $mbr->new('7/4'); +$y = $mbr->new('5/9'); +is($x % $y, '1/12'); + +$x = $mbr->new('-144/9')->bsqrt(); +is($x, 'NaN'); + +$x = $mbr->new('144/9')->bsqrt(); +is($x, '4'); + +$x = $mbr->new('3/4')->bsqrt(); +is($x, + '1732050807568877293527446341505872366943/' + .'2000000000000000000000000000000000000000'); ############################################################################## # bpow -$x = $cr->new('2/1'); $z = $x->bpow('3/1'); is ($x,'8'); -$x = $cr->new('1/2'); $z = $x->bpow('3/1'); is ($x,'1/8'); -$x = $cr->new('1/3'); $z = $x->bpow('4/1'); is ($x,'1/81'); -$x = $cr->new('2/3'); $z = $x->bpow('4/1'); is ($x,'16/81'); +$x = $mbr->new('2/1'); +$z = $x->bpow('3/1'); +is($x, '8'); -$x = $cr->new('2/3'); $z = $x->bpow('5/3'); -is ($x, '31797617848703662994667839220546583581/62500000000000000000000000000000000000'); +$x = $mbr->new('1/2'); +$z = $x->bpow('3/1'); +is($x, '1/8'); + +$x = $mbr->new('1/3'); +$z = $x->bpow('4/1'); +is($x, '1/81'); + +$x = $mbr->new('2/3'); +$z = $x->bpow('4/1'); +is($x, '16/81'); + +$x = $mbr->new('2/3'); +$z = $x->bpow('5/3'); +is($x, '31797617848703662994667839220546583581/62500000000000000000000000000000000000'); ############################################################################## # bfac -$x = $cr->new('1'); $x->bfac(); is ($x,'1'); -for (my $i = 0; $i < 8; $i++) - { - $x = $cr->new("$i/1")->bfac(); is ($x,$mbi->new($i)->bfac()); - } +$x = $mbr->new('1'); +$x->bfac(); +is($x, '1'); + +for (my $i = 0; $i < 8; $i++) { + $x = $mbr->new("$i/1")->bfac(); + is($x, $mbi->new($i)->bfac()); +} # test for $self->bnan() vs. $x->bnan(); -$x = $cr->new('-1'); $x->bfac(); is ($x,'NaN'); +$x = $mbr->new('-1'); +$x->bfac(); +is($x, 'NaN'); ############################################################################## # binc/bdec -$x = $cr->new('3/2'); is ($x->binc(),'5/2'); -$x = $cr->new('15/6'); is ($x->bdec(),'3/2'); +$x = $mbr->new('3/2'); +is($x->binc(), '5/2'); +$x = $mbr->new('15/6'); +is($x->bdec(), '3/2'); ############################################################################## # bfloor/bceil -$x = $cr->new('-7/7'); is ($x->$n(), '-1'); is ($x->$d(), '1'); -$x = $cr->new('-7/7')->bfloor(); is ($x->$n(), '-1'); is ($x->$d(), '1'); +$x = $mbr->new('-7/7'); +is($x->$n(), '-1'); +is($x->$d(), '1'); +$x = $mbr->new('-7/7')->bfloor(); +is($x->$n(), '-1'); +is($x->$d(), '1'); ############################################################################## # bsstr -$x = $cr->new('7/5')->bsstr(); is ($x,'7/5'); -$x = $cr->new('-7/5')->bsstr(); is ($x,'-7/5'); +$x = $mbr->new('7/5')->bsstr(); +is($x, '7/5'); +$x = $mbr->new('-7/5')->bsstr(); +is($x, '-7/5'); ############################################################################## # numify() my @array = qw/1 2 3 4 5 6 7 8 9/; -$x = $cr->new('8/8'); is ($array[$x],2); -$x = $cr->new('16/8'); is ($array[$x],3); -$x = $cr->new('17/8'); is ($array[$x],3); -$x = $cr->new('33/8'); is ($array[$x],5); -$x = $cr->new('-33/8'); is ($array[$x],6); -$x = $cr->new('-8/1'); is ($array[$x],2); # -8 => 2 +$x = $mbr->new('8/8'); +is($array[$x], 2); + +$x = $mbr->new('16/8'); +is($array[$x], 3); + +$x = $mbr->new('17/8'); +is($array[$x], 3); -$x = $cr->new('33/8'); is ($x->numify() * 1000, 4125); -$x = $cr->new('-33/8'); is ($x->numify() * 1000, -4125); -$x = $cr->new('inf'); is ($x->numify(), 'inf'); -$x = $cr->new('-inf'); is ($x->numify(), '-inf'); -$x = $cr->new('NaN'); is ($x->numify(), 'NaN'); +$x = $mbr->new('33/8'); +is($array[$x], 5); -$x = $cr->new('4/3'); is ($x->numify(), 4/3); +$x = $mbr->new('-33/8'); +is($array[$x], 6); + +$x = $mbr->new('-8/1'); +is($array[$x], 2); # -8 => 2 + +$x = $mbr->new('33/8'); +is($x->numify() * 1000, 4125); + +$x = $mbr->new('-33/8'); +is($x->numify() * 1000, -4125); + +$x = $mbr->new('inf'); +is($x->numify(), 'inf'); + +$x = $mbr->new('-inf'); +is($x->numify(), '-inf'); + +$x = $mbr->new('NaN'); +is($x->numify(), 'NaN'); + +$x = $mbr->new('4/3'); +is($x->numify(), 4/3); ############################################################################## # as_hex(), as_bin(), as_oct() -$x = $cr->new('8/8'); -is ($x->as_hex(), '0x1'); is ($x->as_bin(), '0b1'); is ($x->as_oct(), '01'); -$x = $cr->new('80/8'); -is ($x->as_hex(), '0xa'); is ($x->as_bin(), '0b1010'); is ($x->as_oct(), '012'); +$x = $mbr->new('8/8'); +is($x->as_hex(), '0x1'); +is($x->as_bin(), '0b1'); +is($x->as_oct(), '01'); + +$x = $mbr->new('80/8'); +is($x->as_hex(), '0xa'); +is($x->as_bin(), '0b1010'); +is($x->as_oct(), '012'); ############################################################################## # broot(), blog(), bmodpow() and bmodinv() -$x = $cr->new(2) ** 32; -$y = $cr->new(4); -$z = $cr->new(3); +$x = $mbr->new(2) ** 32; +$y = $mbr->new(4); +$z = $mbr->new(3); -is ($x->copy()->broot($y), 2 ** 8); -is (ref($x->copy()->broot($y)), $cr); +is($x->copy()->broot($y), 2 ** 8); +is(ref($x->copy()->broot($y)), $mbr); -is ($x->copy()->bmodpow($y,$z), 1); -is (ref($x->copy()->bmodpow($y,$z)), $cr); +is($x->copy()->bmodpow($y, $z), 1); +is(ref($x->copy()->bmodpow($y, $z)), $mbr); -$x = $cr->new(8); -$y = $cr->new(5033); -$z = $cr->new(4404); +$x = $mbr->new(8); +$y = $mbr->new(5033); +$z = $mbr->new(4404); -is ($x->copy()->bmodinv($y), $z); -is (ref($x->copy()->bmodinv($y)), $cr); +is($x->copy()->bmodinv($y), $z); +is(ref($x->copy()->bmodinv($y)), $mbr); # square root with exact result -$x = $cr->new('1.44'); -is ($x->copy()->broot(2), '6/5'); -is (ref($x->copy()->broot(2)), $cr); +$x = $mbr->new('1.44'); +is($x->copy()->broot(2), '6/5'); +is(ref($x->copy()->broot(2)), $mbr); # log with exact result -$x = $cr->new('256.1'); -is ($x->copy()->blog(2), '8000563442710106079310294693803606983661/1000000000000000000000000000000000000000'); -is (ref($x->copy()->blog(2)), $cr); +$x = $mbr->new('256.1'); +is($x->copy()->blog(2), '8000563442710106079310294693803606983661/1000000000000000000000000000000000000000'); +is(ref($x->copy()->blog(2)), $mbr); -$x = $cr->new(144); -is ($x->copy()->broot('2'), 12, 'v/144 = 12'); +$x = $mbr->new(144); +is($x->copy()->broot('2'), 12, 'v/144 = 12'); -$x = $cr->new(12*12*12); -is ($x->copy()->broot('3'), 12, '(12*12*12) ** 1/3 = 12'); +$x = $mbr->new(12*12*12); +is($x->copy()->broot('3'), 12, '(12*12*12) ** 1/3 = 12'); ############################################################################## # from_hex(), from_bin(), from_oct() $x = Math::BigRat->from_hex('0x100'); -is ($x, '256', 'from_hex'); -$x = $cr->from_hex('0x100'); -is ($x, '256', 'from_hex'); +is($x, '256', 'from_hex'); + +$x = $mbr->from_hex('0x100'); +is($x, '256', 'from_hex'); $x = Math::BigRat->from_bin('0b100'); -is ($x, '4', 'from_bin'); -$x = $cr->from_bin('0b100'); -is ($x, '4', 'from_bin'); +is($x, '4', 'from_bin'); + +$x = $mbr->from_bin('0b100'); +is($x, '4', 'from_bin'); $x = Math::BigRat->from_oct('0100'); -is ($x, '64', 'from_oct'); -$x = $cr->from_oct('0100'); -is ($x, '64', 'from_oct'); +is($x, '64', 'from_oct'); + +$x = $mbr->from_oct('0100'); +is($x, '64', 'from_oct'); ############################################################################## # as_float() -$x = Math::BigRat->new('1/2'); my $f = $x->as_float(); +$x = Math::BigRat->new('1/2'); +my $f = $x->as_float(); -is ($x, '1/2', '$x unmodified'); -is ($f, '0.5', 'as_float(0.5)'); +is($x, '1/2', '$x unmodified'); +is($f, '0.5', 'as_float(0.5)'); -$x = Math::BigRat->new('2/3'); $f = $x->as_float(5); +$x = Math::BigRat->new('2/3'); +$f = $x->as_float(5); -is ($x, '2/3', '$x unmodified'); -is ($f, '0.66667', 'as_float(2/3,5)'); +is($x, '2/3', '$x unmodified'); +is($f, '0.66667', 'as_float(2/3, 5)'); ############################################################################## # int() -$x = Math::BigRat->new('5/2'); -is int($x), '2', '5/2 converted to integer'; -$x = Math::BigRat->new('-1/2'); -is int($x), '0', '-1/2 converted to integer'; +$x = Math::BigRat->new('5/2'); +is(int($x), '2', '5/2 converted to integer'); + +$x = Math::BigRat->new('-1/2'); +is(int($x), '0', '-1/2 converted to integer'); ############################################################################## # done diff --git a/cpan/Math-BigRat/t/bigratpm.inc b/cpan/Math-BigRat/t/bigratpm.inc index b2f507fee9..a031919bc8 100644 --- a/cpan/Math-BigRat/t/bigratpm.inc +++ b/cpan/Math-BigRat/t/bigratpm.inc @@ -1,167 +1,182 @@ #include this file into another test for subclass testing... -is ($class->config()->{lib},$CL); +use strict; +use warnings; + +our ($CLASS, $try, $x, $y, $z, $f, @args, $want, $got, $setup, $CALC); + +is($CLASS->config()->{lib}, $CALC); $setup = ''; -while (<DATA>) - { - chomp; - $_ =~ s/#.*$//; # remove comments - $_ =~ s/\s+$//; # trailing spaces - next if /^$/; # skip empty lines & comments - if (s/^&//) - { - $f = $_; +while (<DATA>) { + s/#.*$//; # remove comments + s/\s+$//; # remove trailing whitespace + next unless length; # skip empty lines + + 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 = new $class \"$args[0]\";"; - if ($f eq "bnorm") - { - $try .= "\$x;"; - } elsif ($f eq "finf") { + + $try = qq|\$x = $CLASS->new("$args[0]");|; + if ($f eq "bnorm") { + $try .= " \$x;"; + } elsif ($f eq "finf") { my $a = $args[1] || ''; - $try .= "\$x->binf('$a');"; - } elsif ($f eq "is_inf") { - $try .= "\$x->is_inf('$args[1]');"; - } elsif ($f eq "fone") { - $try .= "\$x->bone('$args[1]');"; - } elsif ($f eq "fstr") { - $try .= "\$x->accuracy($args[1]); \$x->precision($args[2]);"; - $try .= '$x->bstr();'; - } elsif ($f eq "parts") { + $try .= qq| \$x->binf("$a");|; + } elsif ($f eq "is_inf") { + $try .= qq| \$x->is_inf("$args[1]");|; + } elsif ($f eq "fone") { + $try .= qq| \$x->bone("$args[1]");|; + } elsif ($f eq "fstr") { + $try .= " \$x->accuracy($args[1]); \$x->precision($args[2]);"; + $try .= ' $x->bstr();'; + } 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 "numerator") { + $try .= ' ($a,$b) = $x->parts(); $a = $a->bstr(); $b = $b->bstr();'; + $try .= ' "$a $b";'; + } elsif ($f eq "numerator") { # ->bstr() to see if an object is returned - $try .= '$x->numerator()->bstr();'; - } elsif ($f eq "denominator") { + $try .= ' $x->numerator()->bstr();'; + } elsif ($f eq "denominator") { # ->bstr() to see if an object is returned - $try .= '$x->denominator()->bstr();'; - } elsif ($f =~ /^(length|numify)$/) { - $try .= "\$x->$f();"; - # some unary ops (can't test the fxxx form, since no AUTOLOAD in BigRat) - } elsif ($f =~ /^f(nan|sstr|neg|floor|ceil|abs)$/) { - $try .= "\$x->b$1();"; - # some is_xxx test function - } elsif ($f =~ /^is_(zero|one|pos|neg|negative|positive|odd|even|nan|int)\z/) { - $try .= "\$x->$f();"; - } elsif ($f =~ /^(as_number|as_int)\z/){ - $try .= "\$x->$1();"; - } elsif ($f eq "finc") { - $try .= '++$x;'; - } elsif ($f eq "fdec") { - $try .= '--$x;'; - } elsif ($f eq "digit") { - $try .= "\$x->digit($args[1]);"; - } elsif ($f eq "fround") { - $try .= "$setup; \$x->bround($args[1]);"; - } elsif ($f eq "ffround") { - $try .= "$setup; \$x->bfround($args[1]);"; - } elsif ($f eq "fsqrt") { - $try .= "$setup; \$x->bsqrt();"; - } elsif ($f eq "flog") { - $try .= "$setup; \$x->blog();"; - } elsif ($f eq "ffac") { - $try .= "$setup; \$x->bfac();"; - } - else - { - $try .= "\$y = new $class \"$args[1]\";"; - if ($f eq "bcmp") { - $try .= '$x <=> $y;'; - } elsif ($f eq "bacmp") { - $try .= '$x->bacmp($y);'; - } elsif ($f eq "bpow") { - $try .= '$x ** $y;'; - } elsif ($f eq "fpow") { - $try .= '$x->bpow($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;'; - } elsif( $f eq "bmodinv") { - $try .= "\$x->bmodinv(\$y);"; - } elsif( $f eq "blog") { - $try .= "\$x->blog(\$y);"; - } else { - $try .= "\$z = $class->new(\"$args[2]\");"; + $try .= ' $x->denominator()->bstr();'; + } elsif ($f =~ /^(length|numify)$/) { + $try .= " \$x->$f();"; + # some unary ops (can't test the fxxx form, since no AUTOLOAD in BigRat) + } elsif ($f =~ /^f(nan|sstr|neg|floor|ceil|abs)$/) { + $try .= " \$x->b$1();"; + # 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|pos|neg|negative|positive|odd|even|nan|int)\z/) { + $try .= " \$x->$f();"; + } elsif ($f =~ /^(as_number|as_int)\z/) { + $try .= " \$x->$1();"; + } elsif ($f eq "finc") { + $try .= ' ++$x;'; + } elsif ($f eq "fdec") { + $try .= ' --$x;'; + } elsif ($f eq "digit") { + $try .= " \$x->digit($args[1]);"; + } elsif ($f eq "fround") { + $try .= " $setup; \$x->bround($args[1]);"; + } elsif ($f eq "ffround") { + $try .= " $setup; \$x->bfround($args[1]);"; + } elsif ($f eq "fsqrt") { + $try .= " $setup; \$x->bsqrt();"; + } elsif ($f eq "flog") { + $try .= " $setup; \$x->blog();"; + } elsif ($f eq "ffac") { + $try .= " $setup; \$x->bfac();"; + } else { + $try .= qq| \$y = $CLASS->new("$args[1]");|; + if ($f eq "bcmp") { + $try .= ' $x <=> $y;'; + } elsif ($f eq "bacmp") { + $try .= ' $x->bacmp($y);'; + } elsif ($f eq "bpow") { + $try .= ' $x ** $y;'; + } elsif ($f eq "fpow") { + $try .= ' $x->bpow($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 .= 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;'; + } elsif ($f eq "bmodinv") { + $try .= " \$x->bmodinv(\$y);"; + } elsif ($f eq "blog") { + $try .= " \$x->blog(\$y);"; + } else { + $try .= qq| \$z = $CLASS->new("$args[2]");|; - # Functions with three arguments - if( $f eq "bmodpow") { - $try .= "\$x->bmodpow(\$y,\$z);"; - } else { warn "Unknown op '$f'"; } - } + # Functions with three arguments + if ($f eq "bmodpow") { + $try .= " \$x->bmodpow(\$y, \$z);"; + } else { + warn "Unknown op '$f'"; + } + } } # print "# Trying: '$try'\n"; - $ans1 = eval $try; - if ($ans =~ m|^/(.*)$|) - { - my $pat = $1; - like ($ans1, qr/$pat/); - } - else - { - if ($ans eq "") - { - is ($ans1, undef); + $got = eval $try; + 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"; + # print "# Has trailing zeros after '$try'\n" + # if !is($got->{_m}->_trailing_zeros(), 0); + #} } - else - { - is ($ans1, $ans) or diag("Tried: '$try'"); -# 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 ($ans1->{_m}->_trailing_zeros(), 0); -# } - } - } # end pattern or string - } - } # end while + } # end pattern or string +} # end while -# check whether $class->new( Math::BigInt->new()) destroys it +# 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, qq|\$x = Math::BigInt->new(1200); \$y = $CLASS->new(\$x); $y|); +is($x, 1200, qq|\$x = Math::BigInt->new(1200); \$y = $CLASS->new(\$x); $x|); ############################################################################### -# 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}|); __DATA__ &digit @@ -266,7 +281,7 @@ NaN:NaN -3:NaN &flog NaN:NaN -0:NaN +0:-inf -2:NaN &blog NaN:NaN:NaN @@ -274,7 +289,7 @@ NaN:NaN:NaN NaN:0:NaN NaN:1:NaN 1:NaN:NaN -0:2:NaN +0:2:-inf 0:-2:NaN 3:-2:NaN &finf @@ -339,7 +354,7 @@ inf/-5:-inf inf:inf +inf:inf -inf:-inf -+infinity:NaN ++InFiNiTy:inf +-inf:NaN abc:NaN 1 a:NaN @@ -577,7 +592,7 @@ NaNmul:-inf:NaN 11/7:2/3:2,5/21 -11/7:2/3:-3,3/7 &bdiv -$div_scale = 40; $round_mode = 'even' +$div_scale = 40; $round_mode = "even" abc:abc:NaN abc:+1:abc:NaN +1:abc:NaN @@ -642,9 +657,8 @@ NaN::0 +inf:+:1 -inf:-:1 -inf:+:0 -# it must be exactly /^[+-]inf$/ -+infinity::0 --infinity::0 ++infinity::1 +-infinity::1 &is_odd abc:0 0:0 @@ -914,3 +928,18 @@ NaN:NaN 1/3:-2/3 2/7:-5/7 NaN:NaN +&log +-1:NaN +0:-inf +1:0 +34803:3267955896544848894312057422508991/312500000000000000000000000000000 +-inf:inf +inf:inf +NaN:NaN +&exp +&sin +&cos +&atan2 +&int +&abs +&sqrt diff --git a/cpan/Math-BigRat/t/bigratpm.t b/cpan/Math-BigRat/t/bigratpm.t index b3f550e30c..24f95ee1d9 100644 --- a/cpan/Math-BigRat/t/bigratpm.t +++ b/cpan/Math-BigRat/t/bigratpm.t @@ -1,12 +1,14 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl use strict; -use Test::More tests => 696; +use warnings; + +use Test::More tests => 703; use Math::BigRat lib => 'Calc'; -use vars qw ($class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL); -$class = "Math::BigRat"; -$CL = "Math::BigInt::Calc"; +our ($CLASS, $CALC); +$CLASS = "Math::BigRat"; +$CALC = "Math::BigInt::Calc"; # backend require 't/bigratpm.inc'; # all tests here for sharing diff --git a/cpan/Math-BigRat/t/bigratup.t b/cpan/Math-BigRat/t/bigratup.t index a55cbb59ae..46d68f34cc 100644 --- a/cpan/Math-BigRat/t/bigratup.t +++ b/cpan/Math-BigRat/t/bigratup.t @@ -1,30 +1,40 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl # Test whether $Math::BigInt::upgrade breaks our neck use strict; +use warnings; + use Test::More tests => 5; use Math::BigInt upgrade => 'Math::BigRat'; use Math::BigRat; my $rat = 'Math::BigRat'; -my ($x,$y,$z); +my($x, $y, $z); ############################################################################## # bceil/bfloor -$x = $rat->new('49/4'); is ($x->bfloor(),'12', 'floor(49/4)'); -$x = $rat->new('49/4'); is ($x->bceil(),'13', 'ceil(49/4)'); +$x = $rat->new('49/4'); +is($x->bfloor(), '12', 'floor(49/4)'); + +$x = $rat->new('49/4'); +is($x->bceil(), '13', 'ceil(49/4)'); ############################################################################## # bsqrt -$x = $rat->new('144'); is ($x->bsqrt(),'12', 'bsqrt(144)'); -$x = $rat->new('144/16'); is ($x->bsqrt(),'3', 'bsqrt(144/16)'); -$x = $rat->new('1/3'); is ($x->bsqrt(), - '1000000000000000000000000000000000000000/1732050807568877293527446341505872366943', - 'bsqrt(1/3)'); +$x = $rat->new('144'); +is($x->bsqrt(), '12', 'bsqrt(144)'); + +$x = $rat->new('144/16'); +is($x->bsqrt(), '3', 'bsqrt(144/16)'); + +$x = $rat->new('1/3'); +is($x->bsqrt(), + '1000000000000000000000000000000000000000/1732050807568877293527446341505872366943', + 'bsqrt(1/3)'); # all tests successful diff --git a/cpan/Math-BigRat/t/bigroot.t b/cpan/Math-BigRat/t/bigroot.t index 24599482e1..8a895598e9 100644 --- a/cpan/Math-BigRat/t/bigroot.t +++ b/cpan/Math-BigRat/t/bigroot.t @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl # Test broot function (and bsqrt() function, since it is used by broot()). @@ -9,6 +9,8 @@ # it at all. use strict; +use warnings; + use Test::More tests => 8 * 2; use Math::BigFloat; diff --git a/cpan/Math-BigRat/t/bitwise.t b/cpan/Math-BigRat/t/bitwise.t index be9aa4ce38..a23c5dcf52 100644 --- a/cpan/Math-BigRat/t/bitwise.t +++ b/cpan/Math-BigRat/t/bitwise.t @@ -1,5 +1,8 @@ +#!perl + use strict; use warnings; + use Test::More tests => 22; use Math::BigRat; @@ -7,9 +10,12 @@ use Math::BigRat; my $x = Math::BigRat->new('3/7'); for my $op (qw(& | ^ << >> &= |= ^= <<= >>=)) { - ok !eval "my \$y = \$x $op 42; 1"; - like $@, qr/^bitwise operation \Q$op\E not supported in Math::BigRat/; + my $test = "\$y = \$x $op 42"; + ok(!eval "my \$y = \$x $op 42; 1", $test); + like($@, qr/^bitwise operation \Q$op\E not supported in Math::BigRat/, + $test); } -ok !eval "my \$y = ~\$x; 1"; -like $@, qr/^bitwise operation ~ not supported in Math::BigRat/; +my $test = "\$y = ~\$x"; +ok(!eval "my \$y = ~\$x; 1", $test); +like($@, qr/^bitwise operation ~ not supported in Math::BigRat/, $test); diff --git a/cpan/Math-BigRat/t/hang.t b/cpan/Math-BigRat/t/hang.t index b2b94a0011..6de22e6033 100644 --- a/cpan/Math-BigRat/t/hang.t +++ b/cpan/Math-BigRat/t/hang.t @@ -1,16 +1,18 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl # test for bug #34584: hang in exp(1/2) use strict; +use warnings; + use Test::More tests => 1; use Math::BigRat; my $result = Math::BigRat->new('1/2')->bexp(); -is ("$result", "9535900335500879457687887524133067574481/5783815921445270815783609372070483523265", - "exp(1/2) worked"); +is("$result", "9535900335500879457687887524133067574481/5783815921445270815783609372070483523265", + "exp(1/2) worked"); ############################################################################## # done diff --git a/cpan/Math-BigRat/t/requirer.t b/cpan/Math-BigRat/t/requirer.t index 06ce1f4faa..eba2f6622e 100644 --- a/cpan/Math-BigRat/t/requirer.t +++ b/cpan/Math-BigRat/t/requirer.t @@ -1,14 +1,18 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl # check that simple requiring BigRat works use strict; +use warnings; + use Test::More tests => 1; my ($x); -require Math::BigRat; $x = Math::BigRat->new(1); ++$x; +require Math::BigRat; +$x = Math::BigRat->new(1); +++$x; -is ($x, 2, '$x got successfully modified'); +is($x, 2, '$x got successfully modified'); # all tests done diff --git a/cpan/Math-BigRat/t/trap.t b/cpan/Math-BigRat/t/trap.t index 2811524a18..a26da9f72f 100644 --- a/cpan/Math-BigRat/t/trap.t +++ b/cpan/Math-BigRat/t/trap.t @@ -1,8 +1,10 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl # test that config ( trap_nan => 1, trap_inf => 1) really works/dies use strict; +use warnings; + use Test::More tests => 29; use Math::BigRat; |