summaryrefslogtreecommitdiff
path: root/dist
diff options
context:
space:
mode:
authorPiotr Fusik <pfusik@op.pl>2010-09-03 02:41:00 +0200
committerFlorian Ragwitz <rafl@debian.org>2010-09-03 02:41:00 +0200
commitd57359451cf4bdc0507279268f5f934be889a43e (patch)
tree61cbdc37c0c55545b4ea81f6e2ad6cf1e36f29ca /dist
parentc064d6c6600a09556bae5adafca518fb4e6da98a (diff)
downloadperl-d57359451cf4bdc0507279268f5f934be889a43e.tar.gz
Fix Math::BigInt's bnok($k) for $k==0 and $k==$n-1
Signed-off-by: Florian Ragwitz <rafl@debian.org> [rafl@debian.org: fixed bigflt tests and test plans]
Diffstat (limited to 'dist')
-rw-r--r--dist/Math-BigInt/lib/Math/BigInt.pm13
-rw-r--r--dist/Math-BigInt/lib/Math/BigInt/Calc.pm24
-rw-r--r--dist/Math-BigInt/t/bare_mbf.t4
-rw-r--r--dist/Math-BigInt/t/bare_mbi.t2
-rw-r--r--dist/Math-BigInt/t/bigfltpm.inc6
-rw-r--r--dist/Math-BigInt/t/bigfltpm.t2
-rw-r--r--dist/Math-BigInt/t/bigintpm.inc5
-rw-r--r--dist/Math-BigInt/t/bigintpm.t2
-rw-r--r--dist/Math-BigInt/t/sub_mbf.t6
-rw-r--r--dist/Math-BigInt/t/sub_mbi.t4
-rw-r--r--dist/Math-BigInt/t/with_sub.t2
11 files changed, 37 insertions, 33 deletions
diff --git a/dist/Math-BigInt/lib/Math/BigInt.pm b/dist/Math-BigInt/lib/Math/BigInt.pm
index 9f1f983ae3..a775afa66d 100644
--- a/dist/Math-BigInt/lib/Math/BigInt.pm
+++ b/dist/Math-BigInt/lib/Math/BigInt.pm
@@ -1320,18 +1320,17 @@ sub bnok
}
else
{
- # ( 7 ) 7! 7*6*5 * 4*3*2*1 7 * 6 * 5
- # ( - ) = --------- = --------------- = ---------
- # ( 3 ) 3! (7-3)! 3*2*1 * 4*3*2*1 3 * 2 * 1
+ # ( 7 ) 7! 1*2*3*4 * 5*6*7 5 * 6 * 7 6 7
+ # ( - ) = --------- = --------------- = --------- = 5 * - * -
+ # ( 3 ) (7-3)! 3! 1*2*3*4 * 1*2*3 1 * 2 * 3 2 3
- # compute n - k + 2 (so we start with 5 in the example above)
- my $z = $x - $y;
- if (!$z->is_one())
+ if (!$y->is_zero())
{
+ my $z = $x - $y;
$z->binc();
my $r = $z->copy(); $z->binc();
my $d = $self->new(2);
- while ($z->bacmp($x) <= 0) # f < x ?
+ while ($z->bacmp($x) <= 0) # f <= x ?
{
$r->bmul($z); $r->bdiv($d);
$z->binc(); $d->binc();
diff --git a/dist/Math-BigInt/lib/Math/BigInt/Calc.pm b/dist/Math-BigInt/lib/Math/BigInt/Calc.pm
index 52e33d232a..aa374ff881 100644
--- a/dist/Math-BigInt/lib/Math/BigInt/Calc.pm
+++ b/dist/Math-BigInt/lib/Math/BigInt/Calc.pm
@@ -1264,8 +1264,8 @@ sub _is_even
sub _is_odd
{
- # return true if arg is even
- (($_[1]->[0] & 1)) <=> 0;
+ # return true if arg is odd
+ (($_[1]->[0] & 1)) <=> 0;
}
sub _is_one
@@ -1536,28 +1536,26 @@ sub _nok
# ref to array, return ref to array
my ($c,$n,$k) = @_;
- # ( 7 ) 7! 7*6*5 * 4*3*2*1 7 * 6 * 5
- # ( - ) = --------- = --------------- = ---------
- # ( 3 ) 3! (7-3)! 3*2*1 * 4*3*2*1 3 * 2 * 1
-
- # compute n - k + 2 (so we start with 5 in the example above)
- my $x = _copy($c,$n);
+ # ( 7 ) 7! 1*2*3*4 * 5*6*7 5 * 6 * 7 6 7
+ # ( - ) = --------- = --------------- = --------- = 5 * - * -
+ # ( 3 ) (7-3)! 3! 1*2*3*4 * 1*2*3 1 * 2 * 3 2 3
- _sub($c,$n,$k);
- if (!_is_one($c,$n))
+ if (!_is_zero($c,$k))
{
+ my $x = _copy($c,$n);
+ _sub($c,$n,$k);
_inc($c,$n);
my $f = _copy($c,$n); _inc($c,$f); # n = 5, f = 6, d = 2
my $d = _two($c);
- while (_acmp($c,$f,$x) <= 0) # f < n ?
+ while (_acmp($c,$f,$x) <= 0) # f <= n ?
{
- # n = (n * f / d) == 5 * 6 / 2 => n == 3
+ # n = (n * f / d) == 5 * 6 / 2
$n = _mul($c,$n,$f); $n = _div($c,$n,$d);
# f = 7, d = 3
_inc($c,$f); _inc($c,$d);
}
}
- else
+ else
{
# keep ref to $n and set it to 1
splice (@$n,1); $n->[0] = 1;
diff --git a/dist/Math-BigInt/t/bare_mbf.t b/dist/Math-BigInt/t/bare_mbf.t
index 44792064ac..d5c186045c 100644
--- a/dist/Math-BigInt/t/bare_mbf.t
+++ b/dist/Math-BigInt/t/bare_mbf.t
@@ -22,7 +22,7 @@ BEGIN
}
print "# INC = @INC\n";
- plan tests => 2308;
+ plan tests => 2316;
}
use Math::BigFloat lib => 'BareCalc';
@@ -30,5 +30,5 @@ use Math::BigFloat lib => 'BareCalc';
use vars qw ($class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL);
$class = "Math::BigFloat";
$CL = "Math::BigInt::BareCalc";
-
+
require 'bigfltpm.inc'; # all tests here for sharing
diff --git a/dist/Math-BigInt/t/bare_mbi.t b/dist/Math-BigInt/t/bare_mbi.t
index f005edeccd..0a5d7314c7 100644
--- a/dist/Math-BigInt/t/bare_mbi.t
+++ b/dist/Math-BigInt/t/bare_mbi.t
@@ -21,7 +21,7 @@ BEGIN
}
print "# INC = @INC\n";
- plan tests => 3273;
+ plan tests => 3279;
}
use Math::BigInt lib => 'BareCalc';
diff --git a/dist/Math-BigInt/t/bigfltpm.inc b/dist/Math-BigInt/t/bigfltpm.inc
index 7d650e5cba..309b86e25c 100644
--- a/dist/Math-BigInt/t/bigfltpm.inc
+++ b/dist/Math-BigInt/t/bigfltpm.inc
@@ -495,8 +495,12 @@ NaN:1:NaN
1:-2:0
# 7 over 3 = 35
7:3:35
-7:6:1
+7:6:7
100:90:17310309456440
+100:95:75287520
+2:0:1
+7:0:1
+2:1:2
&flog
0::NaN
-1::NaN
diff --git a/dist/Math-BigInt/t/bigfltpm.t b/dist/Math-BigInt/t/bigfltpm.t
index 50b47afac4..dbd36ac90a 100644
--- a/dist/Math-BigInt/t/bigfltpm.t
+++ b/dist/Math-BigInt/t/bigfltpm.t
@@ -21,7 +21,7 @@ BEGIN
}
print "# INC = @INC\n";
- plan tests => 2308
+ plan tests => 2316
+ 5; # own tests
}
diff --git a/dist/Math-BigInt/t/bigintpm.inc b/dist/Math-BigInt/t/bigintpm.inc
index 87140ba44d..317e5ed8ab 100644
--- a/dist/Math-BigInt/t/bigintpm.inc
+++ b/dist/Math-BigInt/t/bigintpm.inc
@@ -2346,9 +2346,12 @@ NaN:1:NaN
1:-2:0
# 7 over 3 = 35
7:3:35
-7:6:1
+7:6:7
100:90:17310309456440
100:95:75287520
+2:0:1
+7:0:1
+2:1:2
&bround
$round_mode('trunc')
0:12:0
diff --git a/dist/Math-BigInt/t/bigintpm.t b/dist/Math-BigInt/t/bigintpm.t
index b4f5bf2fb1..4f33c9f905 100644
--- a/dist/Math-BigInt/t/bigintpm.t
+++ b/dist/Math-BigInt/t/bigintpm.t
@@ -10,7 +10,7 @@ BEGIN
my $location = $0; $location =~ s/bigintpm.t//;
unshift @INC, $location; # to locate the testing files
chdir 't' if -d 't';
- plan tests => 3273 + 6;
+ plan tests => 3279 + 6;
}
use Math::BigInt lib => 'Calc';
diff --git a/dist/Math-BigInt/t/sub_mbf.t b/dist/Math-BigInt/t/sub_mbf.t
index 94375b6998..95911940aa 100644
--- a/dist/Math-BigInt/t/sub_mbf.t
+++ b/dist/Math-BigInt/t/sub_mbf.t
@@ -19,9 +19,9 @@ BEGIN
{
unshift @INC, $location;
}
- print "# INC = @INC\n";
-
- plan tests => 2308
+ print "# INC = @INC\n";
+
+ plan tests => 2316
+ 6; # + our own tests
}
diff --git a/dist/Math-BigInt/t/sub_mbi.t b/dist/Math-BigInt/t/sub_mbi.t
index edb4daf058..fe89ba407e 100644
--- a/dist/Math-BigInt/t/sub_mbi.t
+++ b/dist/Math-BigInt/t/sub_mbi.t
@@ -21,7 +21,7 @@ BEGIN
}
print "# INC = @INC\n";
- plan tests => 3273
+ plan tests => 3279
+ 5; # +5 own tests
}
@@ -37,7 +37,7 @@ require 'bigintpm.inc'; # perform same tests as bigintpm
###############################################################################
# Now do custom tests for Subclass itself
-
+
my $ms = $class->new(23);
print "# Missing custom attribute \$ms->{_custom}" if !ok (1, $ms->{_custom});
diff --git a/dist/Math-BigInt/t/with_sub.t b/dist/Math-BigInt/t/with_sub.t
index d34d9fb885..eecc0e17a2 100644
--- a/dist/Math-BigInt/t/with_sub.t
+++ b/dist/Math-BigInt/t/with_sub.t
@@ -23,7 +23,7 @@ BEGIN
}
print "# INC = @INC\n";
- plan tests => 2308
+ plan tests => 2316
+ 1;
}