summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl/lib/bigrat.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Master/tlpkg/tlperl/lib/bigrat.pm')
-rw-r--r--Master/tlpkg/tlperl/lib/bigrat.pm60
1 files changed, 15 insertions, 45 deletions
diff --git a/Master/tlpkg/tlperl/lib/bigrat.pm b/Master/tlpkg/tlperl/lib/bigrat.pm
index 6ba821d976b..d413429e433 100644
--- a/Master/tlpkg/tlperl/lib/bigrat.pm
+++ b/Master/tlpkg/tlperl/lib/bigrat.pm
@@ -1,15 +1,15 @@
package bigrat;
use 5.006;
-$VERSION = '0.29';
+$VERSION = '0.33';
require Exporter;
@ISA = qw( bigint );
-@EXPORT_OK = qw( PI e bpi bexp );
+@EXPORT_OK = qw( PI e bpi bexp hex oct );
@EXPORT = qw( inf NaN );
use strict;
use overload;
-require bigint; # no "use" to avoid callind import
+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
@@ -69,23 +71,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
{
@@ -95,12 +80,10 @@ sub import
$^H{bigrat} = 1; # we are in effect
- my ($hex,$oct);
# for newer Perls always override hex() and oct() with a lexical version:
if ($] > 5.009004)
{
- $oct = \&_oct;
- $hex = \&_hex;
+ bigint::_override();
}
# some defaults
my $lib = ''; my $lib_kind = 'try'; my $upgrade = 'Math::BigFloat';
@@ -148,17 +131,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|bpi|bexp)\z/)
+ elsif ($_[$i] !~ /^(PI|e|bpi|bexp|hex|oct)\z/)
{
die ("unknown option $_[$i]");
}
@@ -219,11 +192,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'); }
@@ -257,7 +225,7 @@ bigrat - Transparent BigNumber/BigRational support for Perl
print 1/3,"\n"; # 0.33333...
}
- # Note that this will make hex() and oct() be globally overridden:
+ # Import into current package:
use bigrat qw/hex oct/;
print hex("0x1234567890123490"),"\n";
print oct("01234567890123490"),"\n";
@@ -486,14 +454,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 v5.9.4 or ealier, 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 bigrat pragma is active.
=item oct
Override the built-in oct() method with a version that can handle big
-integers. Note that under Perl v5.9.4 or earlier, 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 bigrat pragma is active.
=item v or version
@@ -557,7 +527,7 @@ the same terms as Perl itself.
Especially L<bignum>.
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