lib/bigfloatpl.t See if bigfloat.pl works
lib/bigint.pl An arbitrary precision integer arithmetic package
lib/bigintpl.t See if bigint.pl works
-lib/bigint.pm bignum
+lib/bigint.pm bigint
lib/bignum.pm bignum
lib/bignum/t/bigexp.t See if bignum works
lib/bignum/t/bigint.t See if bigint works
lib/bignum/t/bn_lite.t See if bignum with Math::BigInt::Lite works
lib/bignum/t/brinfnan.t See if bignum works
lib/bignum/t/br_lite.t See if bigrat with Math::BigInt::Lite works
-lib/bignum/t/infnan.inc See if bignum works
+lib/bignum/t/infnan.inc See if bignum with inf/NaN works
+lib/bignum/t/in_effect.t See if in_effect() works
lib/bignum/t/option_a.t See if bignum a => X works
lib/bignum/t/option_l.t See if bignum l => X works
lib/bignum/t/option_p.t See if bignum p => X works
lib/bignum/t/ratopt_a.t See if bigrat a => X works
+lib/bignum/t/scope_i.t See if no bigint works
+lib/bignum/t/scope_f.t See if no bignum works
+lib/bignum/t/scope_r.t See if no bigrat works
lib/bigrat.pl An arbitrary precision rational arithmetic package
-lib/bigrat.pm bignum
+lib/bigrat.pm bigrat
lib/blib.pm For "use blib"
lib/blib.t blib.pm test
lib/bytes_heavy.pl Support routines for byte pragma
package bigint;
use 5.006002;
-$VERSION = '0.10';
+$VERSION = '0.22';
use Exporter;
@ISA = qw( Exporter );
@EXPORT_OK = qw( );
sub upgrade
{
- my $self = shift;
- no strict 'refs';
-# if (defined $_[0])
-# {
-# $Math::BigInt::upgrade = $_[0];
-# }
$Math::BigInt::upgrade;
}
$sign.$$miv.$mfv; # 123.45e+1 => 1234
}
+sub unimport
+ {
+ $^H{bigint} = undef; # no longer in effect
+ overload::remove_constant('binary','','float','','integer');
+ }
+
+sub in_effect
+ {
+ my $level = shift || 0;
+ my $hinthash = (caller($level))[10];
+ $hinthash->{bigint};
+ }
+
sub import
{
my $self = shift;
+ $^H{bigint} = 1; # we are in effect
+
# some defaults
my $lib = ''; my $lib_kind = 'try';
# 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(); }
print inf + 42,"\n"; # inf
print NaN * 7,"\n"; # NaN
+ {
+ no bigint;
+ print 2 ** 256,"\n"; # a normal Perl scalar now
+ }
+
=head1 DESCRIPTION
All operators (including basic math operations) are overloaded. Integer
Return the class that numbers are upgraded to, is in fact returning
C<$Math::BigInt::upgrade>.
+=item in_effect()
+
+ use bigint;
+
+ print "in effect\n" if bigint::in_effect; # true
+ {
+ no bigint;
+ print "in effect\n" if bigint::in_effect; # false
+ }
+
+Returns true or false if C<bigint> is in effect in the current scope.
+
+This method only works on Perl v5.9.4 or later.
+
=back
=head2 MATH LIBRARY
package bignum;
use 5.006002;
-$VERSION = '0.21_02';
+$VERSION = '0.22';
use Exporter;
@EXPORT_OK = qw( );
@EXPORT = qw( inf NaN );
sub upgrade
{
- my $self = shift;
- no strict 'refs';
-# if (defined $_[0])
-# {
-# $Math::BigInt::upgrade = $_[0];
-# $Math::BigFloat::upgrade = $_[0];
-# }
$Math::BigInt::upgrade;
}
Math::BigInt->from_oct($string);
}
+sub unimport
+ {
+ $^H{bignum} = undef; # no longer in effect
+ overload::remove_constant('binary','','float','','integer');
+ }
+
+sub in_effect
+ {
+ my $level = shift || 0;
+ my $hinthash = (caller($level))[10];
+ $hinthash->{bignum};
+ }
+
sub import
{
my $self = shift;
+ $^H{bignum} = 1; # we are in effect
+
# some defaults
my $lib = ''; my $lib_kind = 'try';
my $upgrade = 'Math::BigFloat';
}
# Take care of octal/hexadecimal constants
- overload::constant 'binary' => sub { _binary_constant(shift) };
+ 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(); }
print inf * inf,"\n"; # prints inf
print NaN * 3,"\n"; # prints NaN
+ {
+ no bignum;
+ print 2 ** 256,"\n"; # a normal Perl scalar now
+ }
+
=head1 DESCRIPTION
All operators (including basic math operations) are overloaded. Integer and
the fxxx() notation, though. This makes it possible that the underlying object
might morph into a different class than BigFloat.
-=head2 Caveat
+=head2 Caveats
But a warning is in order. When using the following to make a copy of a number,
only a shallow copy will be made.
Return the class that numbers are upgraded to, is in fact returning
C<$Math::BigInt::upgrade>.
+=item in_effect()
+
+ use bignum;
+
+ print "in effect\n" if bignum::in_effect; # true
+ {
+ no bignum;
+ print "in effect\n" if bignum::in_effect; # false
+ }
+
+Returns true or false if C<bignum> is in effect in the current scope.
+
+This method only works on Perl v5.9.4 or later.
+
=back
=head2 Math Library
--- /dev/null
+#!/usr/bin/perl -w
+
+###############################################################################
+# Test in_effect()
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 9;
+ }
+
+use bigint;
+use bignum;
+use bigrat;
+
+can_ok ('bigint', qw/in_effect/);
+can_ok ('bignum', qw/in_effect/);
+can_ok ('bigrat', qw/in_effect/);
+
+SKIP: {
+ skip ('Need at least Perl v5.9.4', 3) unless $] > 5.009004;
+
+ is (bigint::in_effect(), 1, 'bigint in effect');
+ is (bignum::in_effect(), 1, 'bignum in effect');
+ is (bigrat::in_effect(), 1, 'bigrat in effect');
+ }
+
+{
+ no bigint;
+ no bignum;
+ no bigrat;
+
+ is (bigint::in_effect(), undef, 'bigint not in effect');
+ is (bignum::in_effect(), undef, 'bignum not in effect');
+ is (bigrat::in_effect(), undef, 'bigrat not in effect');
+}
+
--- /dev/null
+#!/usr/bin/perl -w
+
+###############################################################################
+# Test no bignum;
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 6;
+ }
+
+use bignum;
+
+isnt (ref(1), '', 'is in effect');
+isnt (ref(2.0), '', 'is in effect');
+isnt (ref(0x20), '', 'is in effect');
+
+{
+ no bignum;
+
+ is (ref(1), '', 'is not in effect');
+ is (ref(2.0), '', 'is not in effect');
+ is (ref(0x20), '', 'is not in effect');
+}
+
--- /dev/null
+#!/usr/bin/perl -w
+
+###############################################################################
+# Test no bigint;
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 6;
+ }
+
+use bigint;
+
+isnt (ref(1), '', 'is in effect');
+isnt (ref(2.0), '', 'is in effect');
+isnt (ref(0x20), '', 'is in effect');
+
+{
+ no bigint;
+
+ is (ref(1), '', 'is not in effect');
+ is (ref(2.0), '', 'is not in effect');
+ is (ref(0x20), '', 'is not in effect');
+}
+
--- /dev/null
+#!/usr/bin/perl -w
+
+###############################################################################
+# Test no bigint;
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 6;
+ }
+
+use bigrat;
+
+isnt (ref(1), '', 'is in effect');
+isnt (ref(2.0), '', 'is in effect');
+isnt (ref(0x20), '', 'is in effect');
+
+{
+ no bigrat;
+
+ is (ref(1), '', 'is not in effect');
+ is (ref(2.0), '', 'is not in effect');
+ is (ref(0x20), '', 'is not in effect');
+}
+
package bigrat;
use 5.006002;
-$VERSION = '0.10';
+$VERSION = '0.22';
require Exporter;
@ISA = qw( Exporter );
@EXPORT_OK = qw( );
sub upgrade
{
- my $self = shift;
- no strict 'refs';
-# if (defined $_[0])
-# {
-# $Math::BigInt::upgrade = $_[0];
-# $Math::BigFloat::upgrade = $_[0];
-# }
$Math::BigInt::upgrade;
}
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';
# 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(); }
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
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