diff options
Diffstat (limited to 'Master/tlpkg/tlperl/lib/bignum.pm')
-rw-r--r-- | Master/tlpkg/tlperl/lib/bignum.pm | 65 |
1 files changed, 17 insertions, 48 deletions
diff --git a/Master/tlpkg/tlperl/lib/bignum.pm b/Master/tlpkg/tlperl/lib/bignum.pm index f0377c60f14..3c00a89eee2 100644 --- a/Master/tlpkg/tlperl/lib/bignum.pm +++ b/Master/tlpkg/tlperl/lib/bignum.pm @@ -1,15 +1,15 @@ package bignum; use 5.006; -$VERSION = '0.29'; +$VERSION = '0.33'; use Exporter; @ISA = qw( bigint ); -@EXPORT_OK = qw( PI e bexp bpi ); +@EXPORT_OK = qw( PI e bexp bpi hex oct ); @EXPORT = qw( inf NaN ); use strict; use overload; -require bigint; # no "use" to avoid import being called +use bigint (); ############################################################################## @@ -17,6 +17,8 @@ BEGIN { *inf = \&bigint::inf; *NaN = \&bigint::NaN; + *hex = \&bigint::hex; + *oct = \&bigint::oct; } # These are all alike, and thus faked by AUTOLOAD @@ -68,23 +70,6 @@ sub in_effect } ############################################################################# -# the following two routines are for Perl 5.9.4 or later and are lexical - -sub _hex - { - return CORE::hex($_[0]) unless in_effect(1); - my $i = $_[0]; - $i = '0x'.$i unless $i =~ /^0x/; - Math::BigInt->new($i); - } - -sub _oct - { - return CORE::oct($_[0]) unless in_effect(1); - my $i = $_[0]; - return Math::BigInt->from_oct($i) if $i =~ /^0[0-7]/; - Math::BigInt->new($i); - } sub import { @@ -92,13 +77,10 @@ sub import $^H{bignum} = 1; # we are in effect - my ($hex,$oct); - # for newer Perls override hex() and oct() with a lexical version: - if ($] > 5.009003) + if ($] > 5.009004) { - $hex = \&_hex; - $oct = \&_oct; + bigint::_override(); } # some defaults @@ -156,17 +138,7 @@ sub import $trace = 1; splice @a, $j, 1; $j --; } - elsif ($_[$i] eq 'hex') - { - splice @a, $j, 1; $j --; - $hex = \&bigint::_hex_global; - } - elsif ($_[$i] eq 'oct') - { - splice @a, $j, 1; $j --; - $oct = \&bigint::_oct_global; - } - elsif ($_[$i] !~ /^(PI|e|bexp|bpi)\z/) + elsif ($_[$i] !~ /^(PI|e|bexp|bpi|hex|oct)\z/) { die ("unknown option $_[$i]"); } @@ -233,11 +205,6 @@ sub import { $self->export_to_level(1,$self,@a); # export inf and NaN } - { - no warnings 'redefine'; - *CORE::GLOBAL::oct = $oct if $oct; - *CORE::GLOBAL::hex = $hex if $hex; - } } sub PI () { Math::BigFloat->new('3.141592653589793238462643383279502884197'); } @@ -267,7 +234,7 @@ bignum - Transparent BigNumber support for Perl print 2 ** 256,"\n"; # a normal Perl scalar now } - # for older Perls, note that this will be global: + # for older Perls, import into current package: use bignum qw/hex oct/; print hex("0x1234567890123490"),"\n"; print oct("01234567890123490"),"\n"; @@ -420,14 +387,16 @@ This will be hopefully fixed soon ;) =item hex Override the built-in hex() method with a version that can handle big -integers. Note that under Perl older than v5.9.4, this will be global -and cannot be disabled with "no bigint;". +numbers. This overrides it by exporting it to the current package. Under +Perl v5.10.0 and higher, this is not so necessary, as hex() is lexically +overridden in the current scope whenever the bignum pragma is active. =item oct Override the built-in oct() method with a version that can handle big -integers. Note that under Perl older than v5.9.4, this will be global -and cannot be disabled with "no bigint;". +numbers. This overrides it by exporting it to the current package. Under +Perl v5.10.0 and higher, this is not so necessary, as oct() is lexically +overridden in the current scope whenever the bigint pragma is active. =item v or version @@ -650,7 +619,7 @@ The following modules are currently used by bignum: =head1 EXAMPLES Some cool command line examples to impress the Python crowd ;) - + perl -Mbignum -le 'print sqrt(33)' perl -Mbignum -le 'print 2*255' perl -Mbignum -le 'print 4.5+2*255' @@ -672,7 +641,7 @@ the same terms as Perl itself. Especially L<bigrat> as in C<perl -Mbigrat -le 'print 1/3+1/4'>. L<Math::BigFloat>, L<Math::BigInt>, L<Math::BigRat> and L<Math::Big> as well -as L<Math::BigInt::BitVect>, L<Math::BigInt::Pari> and L<Math::BigInt::GMP>. +as L<Math::BigInt::Pari> and L<Math::BigInt::GMP>. =head1 AUTHORS |