From: Tels Date: Sat, 2 Jun 2007 13:40:45 +0000 (+0000) Subject: Math::BigInt v1.87 take 6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=86f0d17ae7d22e132374646440ff37525d8d624b;p=p5sagit%2Fp5-mst-13.2.git Math::BigInt v1.87 take 6 Message-Id: <200706021340.46806@bloodgate.com> p4raw-id: //depot/perl@31330 --- diff --git a/lib/Math/BigFloat.pm b/lib/Math/BigFloat.pm index 3158590..3498eb8 100644 --- a/lib/Math/BigFloat.pm +++ b/lib/Math/BigFloat.pm @@ -241,27 +241,30 @@ sub new sub copy { - my ($c,$x); + # if two arguments, the first one is the class to "swallow" subclasses if (@_ > 1) { - # if two arguments, the first one is the class to "swallow" subclasses - ($c,$x) = @_; - } - else - { - $x = shift; - $c = ref($x); + my $self = bless { + sign => $_[1]->{sign}, + _es => $_[1]->{_es}, + _m => $MBI->_copy($_[1]->{_m}), + _e => $MBI->_copy($_[1]->{_e}), + }, $_[0] if @_ > 1; + + $self->{_a} = $_[1]->{_a} if defined $_[1]->{_a}; + $self->{_p} = $_[1]->{_p} if defined $_[1]->{_p}; + return $self; } - return unless ref($x); # only for objects - my $self = {}; bless $self,$c; + my $self = bless { + sign => $_[0]->{sign}, + _es => $_[0]->{_es}, + _m => $MBI->_copy($_[0]->{_m}), + _e => $MBI->_copy($_[0]->{_e}), + }, ref($_[0]); - $self->{sign} = $x->{sign}; - $self->{_es} = $x->{_es}; - $self->{_m} = $MBI->_copy($x->{_m}); - $self->{_e} = $MBI->_copy($x->{_e}); - $self->{_a} = $x->{_a} if defined $x->{_a}; - $self->{_p} = $x->{_p} if defined $x->{_p}; + $self->{_a} = $_[0]->{_a} if defined $_[0]->{_a}; + $self->{_p} = $_[0]->{_p} if defined $_[0]->{_p}; $self; } @@ -3279,6 +3282,15 @@ You can change this by using: use Math::BigFloat lib => 'GMP'; +Note: The keyword 'lib' will warn when the requested library could not be +loaded. To suppress the warning use 'try' instead: + + use Math::BigFloat try => 'GMP'; + +To turn the warning into a die(), use 'only' instead: + + use Math::BigFloat only => 'GMP'; + The following would first try to find Math::BigInt::Foo, then Math::BigInt::Bar, and when this also fails, revert to Math::BigInt::Calc: @@ -3329,7 +3341,7 @@ libraries: require Math::BigFloat; my $matter = Math::BigFloat->bone() + 4; # load BigInt and Calc Math::BigFloat->import( lib => 'Pari' ); # load Pari, too - my $anti-matter = Math::BigFloat->bone()+4; # now use Pari + my $anti_matter = Math::BigFloat->bone()+4; # now use Pari This will create objects with numbers stored in two different backend libraries, and B will happen when you use these together: diff --git a/lib/Math/BigInt.pm b/lib/Math/BigInt.pm index 24bac30..f99eea6 100644 --- a/lib/Math/BigInt.pm +++ b/lib/Math/BigInt.pm @@ -475,25 +475,26 @@ sub _scale_p sub copy { - my ($c,$x); + # if two arguments, the first one is the class to "swallow" subclasses if (@_ > 1) { - # if two arguments, the first one is the class to "swallow" subclasses - ($c,$x) = @_; - } - else - { - $x = shift; - $c = ref($x); + my $self = bless { + sign => $_[1]->{sign}, + value => $CALC->_copy($_[1]->{value}), + }, $_[0] if @_ > 1; + + $self->{_a} = $_[1]->{_a} if defined $_[1]->{_a}; + $self->{_p} = $_[1]->{_p} if defined $_[1]->{_p}; + return $self; } - return unless ref($x); # only for objects - my $self = bless {}, $c; + my $self = bless { + sign => $_[0]->{sign}, + value => $CALC->_copy($_[0]->{value}), + }, ref($_[0]); - $self->{sign} = $x->{sign}; - $self->{value} = $CALC->_copy($x->{value}); - $self->{_a} = $x->{_a} if defined $x->{_a}; - $self->{_p} = $x->{_p} if defined $x->{_p}; + $self->{_a} = $_[0]->{_a} if defined $_[0]->{_a}; + $self->{_p} = $_[0]->{_p} if defined $_[0]->{_p}; $self; } @@ -866,8 +867,8 @@ sub _find_round_parameters no strict 'refs'; # convert to normal scalar for speed and correctness in inner parts - $a = $a->numify() if defined $a && ref($a); - $p = $p->numify() if defined $a && ref($p); + $a = $a->can('numify') ? $a->numify() : "$a" if defined $a && ref($a); + $p = $p->can('numify') ? $p->numify() : "$p" if defined $p && ref($p); # now pick $a or $p, but only if we have got "arguments" if (!defined $a)