summaryrefslogtreecommitdiff
path: root/lib/Math/BigInt.pm
diff options
context:
space:
mode:
authorIlya Zakharevich <ilya@math.berkeley.edu>1998-06-26 19:28:41 -0400
committerGurusamy Sarathy <gsar@cpan.org>1998-06-29 06:01:35 +0000
commitb3ac6de7f0c7a63b73f1cf3ea9e371470f7d1cb0 (patch)
tree564cec3756b2fdc36f8885a6017a9b0eed22dca1 /lib/Math/BigInt.pm
parentdde527fc6256d3b4a78a8a6187a9b8048cc76da5 (diff)
downloadperl-b3ac6de7f0c7a63b73f1cf3ea9e371470f7d1cb0.tar.gz
added patch for overloading constants, made PERL_OBJECT-aware
Message-Id: <199806270328.XAA21088@monk.mps.ohio-state.edu> p4raw-id: //depot/perl@1259
Diffstat (limited to 'lib/Math/BigInt.pm')
-rw-r--r--lib/Math/BigInt.pm19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/Math/BigInt.pm b/lib/Math/BigInt.pm
index 013e55fadb..bbd15e4a88 100644
--- a/lib/Math/BigInt.pm
+++ b/lib/Math/BigInt.pm
@@ -36,6 +36,12 @@ sub stringify { "${$_[0]}" }
sub numify { 0 + "${$_[0]}" } # Not needed, additional overhead
# comparing to direct compilation based on
# stringify
+sub import {
+ shift;
+ return unless @_;
+ die "unknown import: @_" unless @_ == 1 and $_[0] eq ':constant';
+ overload::constant integer => sub {Math::BigInt->new(shift)};
+}
$zero = 0;
@@ -384,6 +390,19 @@ are not numbers, as well as the result of dividing by zero.
'1 23 456 7890' canonical value '+1234567890'
+=head1 Autocreating constants
+
+After C<use Math::BigInt ':constant'> all the integer decimal constants
+in the given scope are converted to C<Math::BigInt>. This convertion
+happens at compile time.
+
+In particular
+
+ perl -MMath::BigInt=:constant -e 'print 2**100'
+
+print the integer value of C<2**100>. Note that without convertion of
+constants the expression 2**100 will be calculatted as floating point number.
+
=head1 BUGS
The current version of this module is a preliminary version of the