summaryrefslogtreecommitdiff
path: root/lib/bigrat.pm
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-07-04 20:58:05 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-07-04 20:58:05 +0000
commit990fb837ac6356023668c709e35770d2e63ec006 (patch)
tree84790f8204d4d64e5b9ae4b72620d6c22f8e5199 /lib/bigrat.pm
parent2a30c5e0c7700acf7c1205bda81f1853b9257109 (diff)
downloadperl-990fb837ac6356023668c709e35770d2e63ec006.tar.gz
Upgrade to Math::BigInt v1.65, Math::BigRat v0.10,
and bignum v0.14. p4raw-id: //depot/perl@20000
Diffstat (limited to 'lib/bigrat.pm')
-rw-r--r--lib/bigrat.pm37
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/bigrat.pm b/lib/bigrat.pm
index ddc053426e..49d1f38ff9 100644
--- a/lib/bigrat.pm
+++ b/lib/bigrat.pm
@@ -1,7 +1,7 @@
package bigrat;
require 5.005;
-$VERSION = '0.05';
+$VERSION = '0.06';
use Exporter;
@ISA = qw( Exporter );
@EXPORT_OK = qw( );
@@ -34,6 +34,7 @@ sub AUTOLOAD
{
Math::BigInt->$name($_[0]);
Math::BigFloat->$name($_[0]);
+ return Math::BigRat->$name($_[0]);
}
return Math::BigInt->$name();
};
@@ -219,6 +220,40 @@ the BigInt or BigFloat API. It is wise to use only the bxxx() notation, and not
the fxxx() notation, though. This makes you independed on the fact that the
underlying object might morph into a different class than BigFloat.
+=head2 CAVEAT
+
+But a warning is in order. When using the following to make a copy of a number,
+only a shallow copy will be made.
+
+ $x = 9; $y = $x;
+ $x = $y = 7;
+
+Using the copy or the original with overloaded math is okay, e.g. the
+following work:
+
+ $x = 9; $y = $x;
+ print $x + 1, " ", $y,"\n"; # prints 10 9
+
+but calling any method that modifies the number directly will result in
+B<both> the original and the copy beeing destroyed:
+
+ $x = 9; $y = $x;
+ print $x->badd(1), " ", $y,"\n"; # prints 10 10
+
+ $x = 9; $y = $x;
+ print $x->binc(1), " ", $y,"\n"; # prints 10 10
+
+ $x = 9; $y = $x;
+ print $x->bmul(2), " ", $y,"\n"; # prints 18 18
+
+Using methods that do not modify, but testthe contents works:
+
+ $x = 9; $y = $x;
+ $z = 9 if $x->is_zero(); # works fine
+
+See the documentation about the copy constructor and C<=> in overload, as
+well as the documentation in BigInt for further details.
+
=head1 EXAMPLES
perl -Mbigrat -le 'print sqrt(33)'