summaryrefslogtreecommitdiff
path: root/lib/bigrat.pm
diff options
context:
space:
mode:
authorTels <nospam-abuse@bloodgate.com>2007-05-23 21:35:58 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2007-05-24 17:18:24 +0000
commit4440d13a03087bebaa0394cf532fe7ebcda34a06 (patch)
tree0bb7c0b80ad53bc96b17fefd3f5ad1e8435e2b95 /lib/bigrat.pm
parent8b2d66400d0e016ebfcc9a22cd041309afd77ee0 (diff)
downloadperl-4440d13a03087bebaa0394cf532fe7ebcda34a06.tar.gz
Re: perl pragma [PATCH]
Message-Id: <200705232135.59546@bloodgate.com> p4raw-id: //depot/perl@31269
Diffstat (limited to 'lib/bigrat.pm')
-rw-r--r--lib/bigrat.pm54
1 files changed, 44 insertions, 10 deletions
diff --git a/lib/bigrat.pm b/lib/bigrat.pm
index a7a2c437b4..7888aa4481 100644
--- a/lib/bigrat.pm
+++ b/lib/bigrat.pm
@@ -1,7 +1,7 @@
package bigrat;
use 5.006002;
-$VERSION = '0.10';
+$VERSION = '0.22';
require Exporter;
@ISA = qw( Exporter );
@EXPORT_OK = qw( );
@@ -50,13 +50,6 @@ sub AUTOLOAD
sub upgrade
{
- my $self = shift;
- no strict 'refs';
-# if (defined $_[0])
-# {
-# $Math::BigInt::upgrade = $_[0];
-# $Math::BigFloat::upgrade = $_[0];
-# }
$Math::BigInt::upgrade;
}
@@ -73,12 +66,27 @@ sub _binary_constant
Math::BigInt->from_oct($string);
}
+sub unimport
+ {
+ $^H{bigrat} = undef; # no longer in effect
+ overload::remove_constant('binary','','float','','integer');
+ }
+
+sub in_effect
+ {
+ my $level = shift || 0;
+ my $hinthash = (caller($level))[10];
+ $hinthash->{bigrat};
+ }
+
sub import
{
my $self = shift;
# see also bignum->import() for additional comments
+ $^H{bigrat} = 1; # we are in effect
+
# some defaults
my $lib = ''; my $lib_kind = 'try'; my $upgrade = 'Math::BigFloat';
@@ -178,7 +186,14 @@ sub import
# Take care of octal/hexadecimal constants
overload::constant binary => sub { _binary_constant(shift) };
- $self->export_to_level(1,$self,@a); # export inf and NaN
+ # if another big* was already loaded:
+ my ($package) = caller();
+
+ no strict 'refs';
+ if (!defined *{"${package}::inf"})
+ {
+ $self->export_to_level(1,$self,@a); # export inf and NaN
+ }
}
sub inf () { Math::BigInt->binf(); }
@@ -196,9 +211,14 @@ bigrat - Transparent BigNumber/BigRational support for Perl
use bigrat;
- $x = 2 + 4.5,"\n"; # BigFloat 6.5
+ print 2 + 4.5,"\n"; # BigFloat 6.5
print 1/3 + 1/4,"\n"; # produces 7/12
+ {
+ no bigrat;
+ print 1/3,"\n"; # 0.33333...
+ }
+
=head1 DESCRIPTION
All operators (including basic math operations) are overloaded. Integer and
@@ -282,6 +302,20 @@ handle bareword C<NaN> properly.
Return the class that numbers are upgraded to, is in fact returning
C<$Math::BigInt::upgrade>.
+=item in_effect()
+
+ use bigrat;
+
+ print "in effect\n" if bigrat::in_effect; # true
+ {
+ no bigrat;
+ print "in effect\n" if bigrat::in_effect; # false
+ }
+
+Returns true or false if C<bigrat> is in effect in the current scope.
+
+This method only works on Perl v5.9.4 or later.
+
=back
=head2 MATH LIBRARY