summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MANIFEST6
-rw-r--r--lib/bigint.pm18
-rw-r--r--lib/bignum.pm38
-rwxr-xr-xlib/bignum/t/bignum.t2
-rw-r--r--lib/bignum/t/biinfnan.t21
-rw-r--r--lib/bignum/t/bn_lite.t30
-rw-r--r--lib/bignum/t/bninfnan.t21
-rw-r--r--lib/bignum/t/br_lite.t30
-rw-r--r--lib/bignum/t/brinfnan.t21
-rw-r--r--lib/bignum/t/infnan.inc35
-rw-r--r--lib/bigrat.pm13
11 files changed, 222 insertions, 13 deletions
diff --git a/MANIFEST b/MANIFEST
index d9e115e64a..1691353937 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -928,9 +928,15 @@ lib/bigint.pl An arbitrary precision integer arithmetic package
lib/bigint.pm bignum
lib/bigintpl.t See if bigint.pl works
lib/bignum.pm bignum
+lib/bignum/t/bn_lite.t See if bignum works
+lib/bignum/t/br_lite.t See if bignum works
lib/bignum/t/bigint.t See if bignum works
lib/bignum/t/bignum.t See if bignum works
lib/bignum/t/bigrat.t See if bignum works
+lib/bignum/t/biinfnan.t See if bignum works
+lib/bignum/t/bninfnan.t See if bignum works
+lib/bignum/t/brinfnan.t See if bignum works
+lib/bignum/t/infnan.inc See if bignum works
lib/bignum/t/option_a.t See if bignum works
lib/bignum/t/option_l.t See if bignum works
lib/bignum/t/option_p.t See if bignum works
diff --git a/lib/bigint.pm b/lib/bigint.pm
index 900fe18452..fa59d3bac9 100644
--- a/lib/bigint.pm
+++ b/lib/bigint.pm
@@ -1,10 +1,11 @@
package bigint;
require 5.005;
-$VERSION = '0.02';
+$VERSION = '0.03';
use Exporter;
-@ISA = qw( Exporter );
-@EXPORT_OK = qw( );
+@ISA = qw( Exporter );
+@EXPORT_OK = qw( );
+@EXPORT = qw( inf NaN );
use strict;
use overload;
@@ -179,22 +180,29 @@ sub import
# we take care of floating point constants, since BigFloat isn't available
# and BigInt doesn't like them:
overload::constant float => sub { Math::BigInt->new( _constant(shift) ); };
+
+ $self->export_to_level(1,$self,@a); # export inf and NaN
}
+sub inf () { Math::BigInt->binf(); }
+sub NaN () { Math::BigInt->bnan(); }
+
1;
__END__
=head1 NAME
-bigint - Transparent big integer support for Perl
+bigint - Transparent BigInteger support for Perl
=head1 SYNOPSIS
use bignt;
$x = 2 + 4.5,"\n"; # BigInt 6
- print 2 ** 512; # really is what you think it is
+ print 2 ** 512,"\n"; # really is what you think it is
+ print inf + 42,"\n"; # inf
+ print NaN * 7,"\n"; # NaN
=head1 DESCRIPTION
diff --git a/lib/bignum.pm b/lib/bignum.pm
index c900c95ea2..235f9d6a64 100644
--- a/lib/bignum.pm
+++ b/lib/bignum.pm
@@ -1,10 +1,11 @@
package bignum;
require 5.005;
-$VERSION = '0.11';
+$VERSION = '0.12';
use Exporter;
-@ISA = qw( Exporter );
-@EXPORT_OK = qw( );
+@EXPORT_OK = qw( );
+@EXPORT = qw( inf NaN );
+@ISA = qw( Exporter );
use strict;
@@ -166,8 +167,12 @@ sub import
print "Math::BigFloat\t\t v$Math::BigFloat::VERSION\n";
exit;
}
+ $self->export_to_level(1,$self,@a); # export inf and NaN
}
+sub inf () { Math::BigInt->binf(); }
+sub NaN () { Math::BigInt->bnan(); }
+
1;
__END__
@@ -181,7 +186,9 @@ bignum - Transparent BigNumber support for Perl
use bignum;
$x = 2 + 4.5,"\n"; # BigFloat 6.5
- print 2 ** 512 * 0.1; # really is what you think it is
+ print 2 ** 512 * 0.1,"\n"; # really is what you think it is
+ print inf * inf,"\n"; # prints inf
+ print NaN * 3,"\n"; # prints NaN
=head1 DESCRIPTION
@@ -233,6 +240,29 @@ This prints out the name and version of all modules used and then exits.
perl -Mbignum=v -e ''
+=head2 METHODS
+
+Beside import() and AUTOLOAD() there are only a few other methods.
+
+=over 2
+
+=item inf()
+
+A shortcut to return Math::BigInt->binf(). Usefull because Perl does not always
+handle bareword C<inf> properly.
+
+=item NaN()
+
+A shortcut to return Math::BigInt->bnan(). Usefull because Perl does not always
+handle bareword C<NaN> properly.
+
+=item upgrade()
+
+Return the class that numbers are upgraded to, is in fact returning
+C<$Math::BigInt::upgrade>.
+
+=back
+
=head2 MATH LIBRARY
Math with the numbers is done (by default) by a module called
diff --git a/lib/bignum/t/bignum.t b/lib/bignum/t/bignum.t
index 32235ea2d5..21a70e39dc 100755
--- a/lib/bignum/t/bignum.t
+++ b/lib/bignum/t/bignum.t
@@ -35,6 +35,8 @@ ok (2/3,"0.6666666666666666666666666666666666666667");
#ok (2 ** 0.5, 'NaN'); # should be sqrt(2);
+print "huh\n";
+
ok (12->bfac(),479001600);
# see if Math::BigFloat constant works
diff --git a/lib/bignum/t/biinfnan.t b/lib/bignum/t/biinfnan.t
new file mode 100644
index 0000000000..84d3a71bfa
--- /dev/null
+++ b/lib/bignum/t/biinfnan.t
@@ -0,0 +1,21 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+
+use Test;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 26;
+ }
+
+use bigint;
+
+my ($x);
+
+require "infnan.inc";
+
diff --git a/lib/bignum/t/bn_lite.t b/lib/bignum/t/bn_lite.t
new file mode 100644
index 0000000000..21247c1ee7
--- /dev/null
+++ b/lib/bignum/t/bn_lite.t
@@ -0,0 +1,30 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+
+use Test;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 1;
+ }
+
+eval 'require Math::BigInt::Lite;';
+if ($@ eq '')
+ {
+ # can use Lite, so let bignum try it
+ require bignum; bignum->import();
+ # can't get to work a ref(1+1) here, presumable because :constant phase
+ # already done
+ ok ($bignum::_lite,1);
+ }
+else
+ {
+ print "ok 1 # skipped, no Math::BigInt::Lite\n";
+ }
+
+
diff --git a/lib/bignum/t/bninfnan.t b/lib/bignum/t/bninfnan.t
new file mode 100644
index 0000000000..d097215b9e
--- /dev/null
+++ b/lib/bignum/t/bninfnan.t
@@ -0,0 +1,21 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+
+use Test;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 26;
+ }
+
+use bignum;
+
+my ($x);
+
+require "infnan.inc";
+
diff --git a/lib/bignum/t/br_lite.t b/lib/bignum/t/br_lite.t
new file mode 100644
index 0000000000..2bf77d4037
--- /dev/null
+++ b/lib/bignum/t/br_lite.t
@@ -0,0 +1,30 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+
+use Test;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 1;
+ }
+
+eval 'require Math::BigInt::Lite;';
+if ($@ eq '')
+ {
+ # can use Lite, so let bignum try it
+ require bigrat; bigrat->import();
+ # can't get to work a ref(1+1) here, presumable because :constant phase
+ # already done
+ ok ($bigrat::_lite,1);
+ }
+else
+ {
+ print "ok 1 # skipped, no Math::BigInt::Lite\n";
+ }
+
+
diff --git a/lib/bignum/t/brinfnan.t b/lib/bignum/t/brinfnan.t
new file mode 100644
index 0000000000..689a855698
--- /dev/null
+++ b/lib/bignum/t/brinfnan.t
@@ -0,0 +1,21 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+
+use Test;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 26;
+ }
+
+use bigrat;
+
+my ($x);
+
+require "infnan.inc";
+
diff --git a/lib/bignum/t/infnan.inc b/lib/bignum/t/infnan.inc
new file mode 100644
index 0000000000..771b94e748
--- /dev/null
+++ b/lib/bignum/t/infnan.inc
@@ -0,0 +1,35 @@
+
+use strict;
+
+my ($x);
+
+###############################################################################
+# inf tests
+
+$x = 1+inf; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'inf');
+$x = 1*inf; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'inf');
+
+# these don't work without exporting inf()
+$x = inf; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'inf');
+$x = inf+inf; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'inf');
+$x = inf*inf; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'inf');
+
+###############################################################################
+# NaN tests
+
+$x = 1+NaN; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'NaN');
+$x = 1*NaN; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'NaN');
+
+# these don't work without exporting NaN()
+$x = NaN; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'NaN');
+$x = NaN+NaN; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'NaN');
+$x = NaN*NaN; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'NaN');
+
+###############################################################################
+# mixed tests
+
+# these don't work without exporting NaN() or inf()
+$x = NaN+inf; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'NaN');
+$x = NaN*inf; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'NaN');
+$x = inf*NaN; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'NaN');
+
diff --git a/lib/bigrat.pm b/lib/bigrat.pm
index 54ef91ed30..ddc053426e 100644
--- a/lib/bigrat.pm
+++ b/lib/bigrat.pm
@@ -1,10 +1,11 @@
package bigrat;
require 5.005;
-$VERSION = '0.04';
+$VERSION = '0.05';
use Exporter;
-@ISA = qw( Exporter );
-@EXPORT_OK = qw( );
+@ISA = qw( Exporter );
+@EXPORT_OK = qw( );
+@EXPORT = qw( inf NaN );
use strict;
@@ -141,15 +142,19 @@ sub import
print "Math::BigRat\t\t v$Math::BigRat::VERSION\n";
exit;
}
+ $self->export_to_level(1,$self,@a); # export inf and NaN
}
+sub inf () { Math::BigInt->binf(); }
+sub NaN () { Math::BigInt->bnan(); }
+
1;
__END__
=head1 NAME
-bigrat - Transparent BigNumber/BigRational support for Perl
+bigrat - Transparent BigNumber/BigRationale support for Perl
=head1 SYNOPSIS