summaryrefslogtreecommitdiff
path: root/lib/Math/BigInt
diff options
context:
space:
mode:
authorTels <nospam-abuse@bloodgate.com>2005-04-03 12:43:10 +0200
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2005-04-05 10:40:35 +0000
commit233f7bc03a8f0557d08657ec772040b570b403cd (patch)
tree79d51b536240e85541715cab4dfd5099e0bd29b5 /lib/Math/BigInt
parent43e4f2c68f8de551ce4632b5fbfb077a650c967e (diff)
downloadperl-233f7bc03a8f0557d08657ec772040b570b403cd.tar.gz
[Patch] Math::BigInt v1.76, Math::BigRat v0.15, bignum v0.17
Message-Id: <200504031043.12273@bloodgate.com> p4raw-id: //depot/perl@24155
Diffstat (limited to 'lib/Math/BigInt')
-rw-r--r--lib/Math/BigInt/Calc.pm6
-rw-r--r--lib/Math/BigInt/t/_e_math.t2
-rw-r--r--lib/Math/BigInt/t/bare_mbf.t2
-rw-r--r--lib/Math/BigInt/t/bigfltpm.inc14
-rwxr-xr-xlib/Math/BigInt/t/bigfltpm.t4
-rwxr-xr-xlib/Math/BigInt/t/bigintpm.t2
-rw-r--r--lib/Math/BigInt/t/calling.t17
-rw-r--r--lib/Math/BigInt/t/config.t8
-rw-r--r--lib/Math/BigInt/t/req_mbf0.t6
-rw-r--r--lib/Math/BigInt/t/req_mbfw.t12
-rwxr-xr-xlib/Math/BigInt/t/sub_mbf.t4
-rw-r--r--lib/Math/BigInt/t/trap.t55
-rw-r--r--lib/Math/BigInt/t/with_sub.t4
13 files changed, 77 insertions, 59 deletions
diff --git a/lib/Math/BigInt/Calc.pm b/lib/Math/BigInt/Calc.pm
index eb5ba98a67..56b6aab497 100644
--- a/lib/Math/BigInt/Calc.pm
+++ b/lib/Math/BigInt/Calc.pm
@@ -6,7 +6,7 @@ use strict;
use vars qw/$VERSION/;
-$VERSION = '0.45';
+$VERSION = '0.46';
# Package to store unsigned big integers in decimal and do math with them
@@ -36,7 +36,7 @@ $VERSION = '0.45';
sub api_version () { 1; }
# constants for easier life
-my ($MBASE,$BASE,$RBASE,$BASE_LEN,$MAX_VAL,$BASE_LEN_SMALL);
+my ($BASE,$BASE_LEN,$MBASE,$RBASE,$MAX_VAL,$BASE_LEN_SMALL);
my ($AND_BITS,$XOR_BITS,$OR_BITS);
my ($AND_MASK,$XOR_MASK,$OR_MASK);
@@ -94,7 +94,7 @@ sub _base_len
}
}
return $BASE_LEN unless wantarray;
- return ($BASE_LEN, $AND_BITS, $XOR_BITS, $OR_BITS, $BASE_LEN_SMALL, $MAX_VAL);
+ return ($BASE_LEN, $AND_BITS, $XOR_BITS, $OR_BITS, $BASE_LEN_SMALL, $MAX_VAL, $BASE);
}
sub _new
diff --git a/lib/Math/BigInt/t/_e_math.t b/lib/Math/BigInt/t/_e_math.t
index 3db33183a8..b3eb644437 100644
--- a/lib/Math/BigInt/t/_e_math.t
+++ b/lib/Math/BigInt/t/_e_math.t
@@ -31,7 +31,7 @@ BEGIN
plan tests => 26;
}
-use Math::BigFloat;
+use Math::BigFloat lib => 'Calc';
#############################################################################
# add
diff --git a/lib/Math/BigInt/t/bare_mbf.t b/lib/Math/BigInt/t/bare_mbf.t
index 9a12572e14..29a73a0153 100644
--- a/lib/Math/BigInt/t/bare_mbf.t
+++ b/lib/Math/BigInt/t/bare_mbf.t
@@ -27,7 +27,7 @@ BEGIN
}
print "# INC = @INC\n";
- plan tests => 1992;
+ plan tests => 2012;
}
use Math::BigFloat lib => 'BareCalc';
diff --git a/lib/Math/BigInt/t/bigfltpm.inc b/lib/Math/BigInt/t/bigfltpm.inc
index 5f27a8b8cb..4099521fe7 100644
--- a/lib/Math/BigInt/t/bigfltpm.inc
+++ b/lib/Math/BigInt/t/bigfltpm.inc
@@ -1221,6 +1221,11 @@ NaNmul:-inf:NaN
0:1:0,0
9:4:2.25,1
9:5:1.8,4
+# bug in v1.74 with bdiv in list context, when $y is 1 or -1
+2.1:-1:-2.1,0
+2.1:1:2.1,0
+-2.1:-1:2.1,0
+-2.1:1:-2.1,0
&fdiv
$div_scale = 40; $round_mode = 'even'
abc:abc:NaN
@@ -1382,6 +1387,15 @@ abc:1:abc:NaN
1230:2.5:0
123.4:2.5:0.9
123e1:25:5
+# 1 or -1 always gives remainder zero (bug up to v1.74)
+-2.1:1:0
+2.1:1:0
+-2.1:-1:0
+2.1:-1:0
+-3:1:0
+3:1:0
+-3:-1:0
+3:-1:0
&ffac
Nanfac:NaN
-1:NaN
diff --git a/lib/Math/BigInt/t/bigfltpm.t b/lib/Math/BigInt/t/bigfltpm.t
index 5cc9ddbbda..c44402877b 100755
--- a/lib/Math/BigInt/t/bigfltpm.t
+++ b/lib/Math/BigInt/t/bigfltpm.t
@@ -26,11 +26,11 @@ BEGIN
}
print "# INC = @INC\n";
- plan tests => 1992
+ plan tests => 2012
+ 2; # own tests
}
-use Math::BigInt;
+use Math::BigInt lib => 'Calc';
use Math::BigFloat;
use vars qw ($class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL);
diff --git a/lib/Math/BigInt/t/bigintpm.t b/lib/Math/BigInt/t/bigintpm.t
index 9923256a89..431ab02c3b 100755
--- a/lib/Math/BigInt/t/bigintpm.t
+++ b/lib/Math/BigInt/t/bigintpm.t
@@ -13,7 +13,7 @@ BEGIN
plan tests => 3014;
}
-use Math::BigInt;
+use Math::BigInt lib => 'Calc';
use vars qw ($scale $class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL);
$class = "Math::BigInt";
diff --git a/lib/Math/BigInt/t/calling.t b/lib/Math/BigInt/t/calling.t
index 71c6b48c97..7376bad0f5 100644
--- a/lib/Math/BigInt/t/calling.t
+++ b/lib/Math/BigInt/t/calling.t
@@ -55,11 +55,11 @@ use overload;
package main;
-use Math::BigInt;
+use Math::BigInt lib => 'Calc';
use Math::BigFloat;
my ($x,$y,$z,$u);
-my $version = '1.61'; # adjust manually to match latest release
+my $version = '1.76'; # adjust manually to match latest release
###############################################################################
# check whether op's accept normal strings, even when inherited by subclasses
@@ -106,7 +106,7 @@ $class = 'Math::BigInt';
$try = "use $class ($version,'lib','foo, bar , ');";
$try .= "$class\->config()->{lib};";
$ans = eval $try;
-ok ( $ans, "Math::BigInt::Calc");
+ok ( $ans =~ /^Math::BigInt::(Fast)?Calc\z/, 1);
# test whether constant works or not, also test for qw($version)
# bgcd() is present in subclass, too
@@ -125,17 +125,6 @@ $ans = eval $try; ok ( $ans, "1024");
# all done
-###############################################################################
-# Perl 5.005 does not like ok ($x,undef)
-
-sub ok_undef
- {
- my $x = shift;
-
- ok (1,1) and return if !defined $x;
- ok ($x,'undef');
- }
-
__END__
&is_zero
1:0
diff --git a/lib/Math/BigInt/t/config.t b/lib/Math/BigInt/t/config.t
index da75344f2a..68509c0e00 100644
--- a/lib/Math/BigInt/t/config.t
+++ b/lib/Math/BigInt/t/config.t
@@ -13,7 +13,7 @@ BEGIN
# test whether Math::BigInt->config() and Math::BigFloat->config() works
-use Math::BigInt;
+use Math::BigInt lib => 'Calc';
use Math::BigFloat;
my $mbi = 'Math::BigInt'; my $mbf = 'Math::BigFloat';
@@ -105,16 +105,16 @@ foreach my $key (keys %$test)
##############################################################################
# test setting illegal keys (should croak)
-my $never_reached = 0;
+$@ = ""; my $never_reached = 0;
eval ("$mbi\->config( 'some_garbage' => 1 ); $never_reached = 1;");
ok ($never_reached,0);
-$never_reached = 0;
+$@ = ""; $never_reached = 0;
eval ("$mbf\->config( 'some_garbage' => 1 ); $never_reached = 1;");
ok ($never_reached,0);
# this does not work. Why?
-#ok (@!, "Illegal keys 'some_garbage' passed to Math::BigInt->config() at ./config.t line 104");
+#ok ($@ eq "Illegal keys 'some_garbage' passed to Math::BigInt->config() at ./config.t line 104", 1);
# all tests done
diff --git a/lib/Math/BigInt/t/req_mbf0.t b/lib/Math/BigInt/t/req_mbf0.t
index af312f1b92..90cd57cc9a 100644
--- a/lib/Math/BigInt/t/req_mbf0.t
+++ b/lib/Math/BigInt/t/req_mbf0.t
@@ -3,7 +3,7 @@
# check that simple requiring BigFloat and then bzero() works
use strict;
-use Test;
+use Test::More;
BEGIN
{
@@ -31,7 +31,9 @@ BEGIN
plan tests => 1;
}
-require Math::BigFloat; my $x = Math::BigFloat->bzero(); ok ($x,0);
+require Math::BigFloat;
+my $x = Math::BigFloat->bzero(); $x++;
+is ($x,1, '$x is 1');
# all tests done
diff --git a/lib/Math/BigInt/t/req_mbfw.t b/lib/Math/BigInt/t/req_mbfw.t
index 025722d277..10afc7a272 100644
--- a/lib/Math/BigInt/t/req_mbfw.t
+++ b/lib/Math/BigInt/t/req_mbfw.t
@@ -3,7 +3,7 @@
# check that requiring BigFloat and then calling import() works
use strict;
-use Test;
+use Test::More;
BEGIN
{
@@ -32,15 +32,17 @@ BEGIN
}
# normal require that calls import automatically (we thus have MBI afterwards)
-require Math::BigFloat; my $x = Math::BigFloat->new(1); ++$x; ok ($x,2);
+require Math::BigFloat;
+my $x = Math::BigFloat->new(1); ++$x;
+is ($x,2, '$x is 2');
-ok (Math::BigFloat->config()->{with}, 'Math::BigInt::Calc' );
+like (Math::BigFloat->config()->{with}, qr/^Math::BigInt::(Fast)?Calc\z/, 'with ignored' );
# now override
Math::BigFloat->import ( with => 'Math::BigInt::Subclass' );
-# thw with argument is ignored
-ok (Math::BigFloat->config()->{with}, 'Math::BigInt::Calc' );
+# the "with" argument is ignored
+like (Math::BigFloat->config()->{with}, qr/^Math::BigInt::(Fast)?Calc\z/, 'with ignored' );
# all tests done
diff --git a/lib/Math/BigInt/t/sub_mbf.t b/lib/Math/BigInt/t/sub_mbf.t
index 73d7fc0e21..3033ee2c66 100755
--- a/lib/Math/BigInt/t/sub_mbf.t
+++ b/lib/Math/BigInt/t/sub_mbf.t
@@ -26,7 +26,7 @@ BEGIN
}
print "# INC = @INC\n";
- plan tests => 1992
+ plan tests => 2012
+ 6; # + our own tests
}
@@ -34,7 +34,7 @@ use Math::BigFloat::Subclass;
use vars qw ($class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL);
$class = "Math::BigFloat::Subclass";
-$CL = "Math::BigInt::Calc";
+$CL = Math::BigFloat->config()->{lib}; # "Math::BigInt::Calc"; or FastCalc
require 'bigfltpm.inc'; # perform same tests as bigfltpm
diff --git a/lib/Math/BigInt/t/trap.t b/lib/Math/BigInt/t/trap.t
index af454092a2..94a7da4acb 100644
--- a/lib/Math/BigInt/t/trap.t
+++ b/lib/Math/BigInt/t/trap.t
@@ -3,14 +3,14 @@
# test that config ( trap_nan => 1, trap_inf => 1) really works/dies
use strict;
-use Test;
+use Test::More;
BEGIN
{
$| = 1;
chdir 't' if -d 't';
unshift @INC, '../lib'; # for running manually
- plan tests => 35;
+ plan tests => 43;
}
use Math::BigInt;
@@ -22,42 +22,54 @@ my ($cfg,$x);
foreach my $class ($mbi, $mbf)
{
# can do and defaults are okay?
- ok ($class->can('config'));
- ok ($class->config()->{trap_nan}, 0);
- ok ($class->config()->{trap_inf}, 0);
+ ok ($class->can('config'), 'can config()');
+ is ($class->config()->{trap_nan}, 0, 'trap_nan defaults to 0');
+ is ($class->config()->{trap_inf}, 0, 'trap_inf defaults to 0');
# can set?
- $cfg = $class->config( trap_nan => 1 ); ok ($cfg->{trap_nan},1);
+ $cfg = $class->config( trap_nan => 1 );
+ is ($cfg->{trap_nan},1, 'trap_nan now true');
# also test that new() still works normally
eval ("\$x = \$class->new('42'); \$x->bnan();");
- ok ($@ =~/^Tried to set/, 1);
- ok ($x,42); # after new() never modified
+ like ($@, qr/^Tried to set/, 'died');
+ is ($x,42,'$x after new() never modified');
# can reset?
- $cfg = $class->config( trap_nan => 0 ); ok ($cfg->{trap_nan},0);
+ $cfg = $class->config( trap_nan => 0 );
+ is ($cfg->{trap_nan}, 0, 'trap_nan disabled');
# can set?
- $cfg = $class->config( trap_inf => 1 ); ok ($cfg->{trap_inf},1);
+ $cfg = $class->config( trap_inf => 1 );
+ is ($cfg->{trap_inf}, 1, 'trap_inf enabled');
+
eval ("\$x = \$class->new('4711'); \$x->binf();");
- ok ($@ =~/^Tried to set/, 1);
- ok ($x,4711); # after new() never modified
+ like ($@, qr/^Tried to set/, 'died');
+ is ($x,4711,'$x after new() never modified');
+
+ eval ("\$x = \$class->new('inf');");
+ like ($@, qr/^Tried to set/, 'died');
+ is ($x,4711,'$x after new() never modified');
+
+ eval ("\$x = \$class->new('-inf');");
+ like ($@, qr/^Tried to set/, 'died');
+ is ($x,4711,'$x after new() never modified');
# +$x/0 => +inf
eval ("\$x = \$class->new('4711'); \$x->bdiv(0);");
- ok ($@ =~/^Tried to set/, 1);
- ok ($x,4711); # after new() never modified
+ like ($@, qr/^Tried to set/, 'died');
+ is ($x,4711,'$x after new() never modified');
# -$x/0 => -inf
eval ("\$x = \$class->new('-0815'); \$x->bdiv(0);");
- ok ($@ =~/^Tried to set/, 1);
- ok ($x,-815); # after new() never modified
+ like ($@, qr/^Tried to set/, 'died');
+ is ($x,'-815', '$x after new not modified');
$cfg = $class->config( trap_nan => 1 );
# 0/0 => NaN
eval ("\$x = \$class->new('0'); \$x->bdiv(0);");
- ok ($@ =~/^Tried to set/, 1);
- ok ($x,0); # after new() never modified
+ like ($@, qr/^Tried to set/, 'died');
+ is ($x,'0', '$x after new not modified');
}
##############################################################################
@@ -65,17 +77,16 @@ foreach my $class ($mbi, $mbf)
$x = Math::BigInt->new(2);
eval ("\$x = \$mbi->new('0.1');");
-ok ($x,2); # never modified since it dies
+is ($x,2,'never modified since it dies');
eval ("\$x = \$mbi->new('0a.1');");
-ok ($x,2); # never modified since it dies
-
+is ($x,2,'never modified since it dies');
##############################################################################
# BigFloat
$x = Math::BigFloat->new(2);
eval ("\$x = \$mbf->new('0.1a');");
-ok ($x,2); # never modified since it dies
+is ($x,2,'never modified since it dies');
# all tests done
diff --git a/lib/Math/BigInt/t/with_sub.t b/lib/Math/BigInt/t/with_sub.t
index 0ed85a4f4c..07320a961f 100644
--- a/lib/Math/BigInt/t/with_sub.t
+++ b/lib/Math/BigInt/t/with_sub.t
@@ -28,11 +28,11 @@ BEGIN
}
print "# INC = @INC\n";
- plan tests => 1992
+ plan tests => 2012
+ 1;
}
-use Math::BigFloat with => 'Math::BigInt::Subclass';
+use Math::BigFloat with => 'Math::BigInt::Subclass', lib => 'Calc';
use vars qw ($class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL);
$class = "Math::BigFloat";