RT ticket 62949: $x -> bmodpow(1, 1) fails when $x is large
authorPeter John Acklam <pjacklam@online.no>
Sun, 14 Nov 2010 16:19:11 +0000 (17:19 +0100)
committerFlorian Ragwitz <rafl@debian.org>
Sun, 14 Nov 2010 16:24:58 +0000 (17:24 +0100)
Fix the library method in lib/Math/BigInt/Calc.pm so that it
corresponds to the fact that a^b (mod 1) = 0 for all a and b.

- lib/Math/BigInt/Calc.pm: fix mentioned bug

- t/bigintpm.inc: add one more test case

- t/bare_mbi.t: increment test counter

- t/bigintpm.t: increment test counter

- t/sub_mbi.t: increment test counter

dist/Math-BigInt/lib/Math/BigInt/Calc.pm
dist/Math-BigInt/t/bare_mbi.t
dist/Math-BigInt/t/bigintpm.inc
dist/Math-BigInt/t/bigintpm.t
dist/Math-BigInt/t/sub_mbi.t

index 387a231..e7b2102 100644 (file)
@@ -2377,11 +2377,11 @@ sub _modpow
   # modulus of power ($x ** $y) % $z
   my ($c,$num,$exp,$mod) = @_;
 
-  # in the trivial case,
+  # a^b (mod 1) = 0 for all a and b
   if (_is_one($c,$mod))
     {
-    splice @$num,0,1; $num->[0] = 0;
-    return $num;
+        @$num = 0;
+        return $num;
     }
 
   # 0^a (mod m) = 0 if m != 0, a != 0
index e218610..5f4bf5b 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use Test::More tests => 3283;
+use Test::More tests => 3285;
 
 BEGIN { unshift @INC, 't'; }
 
index 530d0b5..2acaba0 100644 (file)
@@ -1733,6 +1733,7 @@ abc:5:5:NaN
 0:3:5:0
 8:7:5032:3840
 8:-1:5033:4404
+1e50:1:1:0
 98436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
 # bmodpow Error cases
 8:8:-5:NaN
index f3a6da4..94f0327 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use Test::More tests => 3283 + 6;
+use Test::More tests => 3285 + 6;
 
 use Math::BigInt lib => 'Calc';
 
index 5c6f44c..9f10aff 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use Test::More tests => 3283
+use Test::More tests => 3285
     + 5;       # +5 own tests
 
 BEGIN { unshift @INC, 't'; }