[libmath-prime-util-perl] 18/54: PP is_power(n, a) has to deal with 0 return unlike the split XS code

Partha P. Mukherjee ppm-guest at moszumanska.debian.org
Thu May 21 18:52:08 UTC 2015


This is an automated email from the git hooks/post-receive script.

ppm-guest pushed a commit to annotated tag v0.38
in repository libmath-prime-util-perl.

commit 35f38473a54f29f92a425868c9462a0b06354df5
Author: Dana Jacobsen <dana at acm.org>
Date:   Mon Feb 3 17:05:48 2014 -0800

    PP is_power(n,a) has to deal with 0 return unlike the split XS code
---
 lib/Math/Prime/Util/PP.pm | 6 +++++-
 t/81-bignum.t             | 3 ++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/Math/Prime/Util/PP.pm b/lib/Math/Prime/Util/PP.pm
index 89be15f..358abee 100644
--- a/lib/Math/Prime/Util/PP.pm
+++ b/lib/Math/Prime/Util/PP.pm
@@ -1430,7 +1430,11 @@ sub _gcd_ui {
 sub is_power {
   my ($n, $a) = @_;
   return 0 if $n <= 3 || $n != int($n);
-  return !(is_power($n) % $a) if defined $a && $a != 0;
+  if (defined $a && $a != 0) {
+    my $power = is_power($n);
+    return 0 unless $power != 0;
+    return !($power % $a);
+  }
   #return 2 if _is_perfect_square($n);
   $n = Math::BigInt->new("$n") unless ref($n) eq 'Math::BigInt';
   my $e = 2;
diff --git a/t/81-bignum.t b/t/81-bignum.t
index 0684139..129ec3e 100644
--- a/t/81-bignum.t
+++ b/t/81-bignum.t
@@ -80,7 +80,7 @@ plan tests =>  0
              + 2   # liouville
              + 3   # gcd
              + 3   # lcm
-             + 1   # ispower
+             + 2   # ispower
              + 15  # random primes
              + 2   # miller-rabin random
              + 1;
@@ -285,6 +285,7 @@ is( lcm(9999999998987,10000000001011), 99999999999979999998975857, "lcm(p1,p2)"
 is( lcm(892478777297173184633,892478777297173184633), 892478777297173184633, "lcm(p1,p1)" );
 is( lcm(23498324,32497832409432,328732487324,328973248732,3487234897324), 1124956497899814324967019145509298020838481660295598696, "lcm(a,b,c,d,e)" );
 
+is( is_power(18475335773296164196), 0, "ispower(18475335773296164196) == 0" );
 is( is_power(3089265681159475043336839581081873360674602365963130114355701114591322241990483812812582393906477998611814245513881), 14, "ispower(150607571^14) == 14" );
 
 ###############################################################################

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git



More information about the Pkg-perl-cvs-commits mailing list