diff options
author | Peter John Acklam <pjacklam@online.no> | 2010-11-11 22:06:59 +0100 |
---|---|---|
committer | Florian Ragwitz <rafl@debian.org> | 2010-11-12 13:07:13 +0100 |
commit | 3a7a056a8cb38c8fe981ab4ff965e721f4258bd4 (patch) | |
tree | 8920747fbdba8d9c0e3a480f26c0fc98c82d0f46 /dist/Math-BigInt | |
parent | ca60ecf2e8a0b5d31d33ef233b08d53b6d62fb84 (diff) | |
download | perl-3a7a056a8cb38c8fe981ab4ff965e721f4258bd4.tar.gz |
RT ticket 62918: _modpow(x,y,z) with x = 0 and y > 0
Fix _modpow() method in Math::BigInt::Calc so it correctly returns 0
in the case (0 ** $x) % $y, with $x > 0.
- lib/Math/BigInt/Calc.pm: fix mentioned bug
- t/bigintpm.inc: add a few more test cases
- t/bare_mbi.t: increment test counter
- t/bigintpm.t: increment test counter
- t/sub_mbi.t: increment test counter
Diffstat (limited to 'dist/Math-BigInt')
-rw-r--r-- | dist/Math-BigInt/lib/Math/BigInt/Calc.pm | 16 | ||||
-rw-r--r-- | dist/Math-BigInt/t/bare_mbi.t | 2 | ||||
-rw-r--r-- | dist/Math-BigInt/t/bigintpm.inc | 2 | ||||
-rw-r--r-- | dist/Math-BigInt/t/bigintpm.t | 2 | ||||
-rw-r--r-- | dist/Math-BigInt/t/sub_mbi.t | 2 |
5 files changed, 16 insertions, 8 deletions
diff --git a/dist/Math-BigInt/lib/Math/BigInt/Calc.pm b/dist/Math-BigInt/lib/Math/BigInt/Calc.pm index a24400b166..387a231772 100644 --- a/dist/Math-BigInt/lib/Math/BigInt/Calc.pm +++ b/dist/Math-BigInt/lib/Math/BigInt/Calc.pm @@ -2383,11 +2383,17 @@ sub _modpow splice @$num,0,1; $num->[0] = 0; return $num; } - if ((scalar @$num == 1) && (($num->[0] == 0) || ($num->[0] == 1))) - { - $num->[0] = 1; - return $num; - } + + # 0^a (mod m) = 0 if m != 0, a != 0 + # 0^0 (mod m) = 1 if m != 0 + if (_is_one($c, $num)) { + if (_is_zero($c, $exp)) { + @$num = 1; + } else { + @$num = 0; + } + return $num; + } # $num = _mod($c,$num,$mod); # this does not make it faster diff --git a/dist/Math-BigInt/t/bare_mbi.t b/dist/Math-BigInt/t/bare_mbi.t index 38b82afab3..e2186109f1 100644 --- a/dist/Math-BigInt/t/bare_mbi.t +++ b/dist/Math-BigInt/t/bare_mbi.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 3279; +use Test::More tests => 3283; BEGIN { unshift @INC, 't'; } diff --git a/dist/Math-BigInt/t/bigintpm.inc b/dist/Math-BigInt/t/bigintpm.inc index 006ef4e618..530d0b52ee 100644 --- a/dist/Math-BigInt/t/bigintpm.inc +++ b/dist/Math-BigInt/t/bigintpm.inc @@ -1725,10 +1725,12 @@ abc:abc:5:NaN 5:5:abc:NaN 5:abc:5:NaN abc:5:5:NaN +3:5:0:NaN # bmodpow Expected results 0:0:2:1 1:0:2:1 0:0:1:0 +0:3:5:0 8:7:5032:3840 8:-1:5033:4404 98436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518 diff --git a/dist/Math-BigInt/t/bigintpm.t b/dist/Math-BigInt/t/bigintpm.t index 6e381e5529..f3a6da4426 100644 --- a/dist/Math-BigInt/t/bigintpm.t +++ b/dist/Math-BigInt/t/bigintpm.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 3279 + 6; +use Test::More tests => 3283 + 6; use Math::BigInt lib => 'Calc'; diff --git a/dist/Math-BigInt/t/sub_mbi.t b/dist/Math-BigInt/t/sub_mbi.t index c548cb3578..5c6f44cb03 100644 --- a/dist/Math-BigInt/t/sub_mbi.t +++ b/dist/Math-BigInt/t/sub_mbi.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 3279 +use Test::More tests => 3283 + 5; # +5 own tests BEGIN { unshift @INC, 't'; } |