[libmath-prime-util-perl] 09/54: PP is_power with negative arguments

Partha P. Mukherjee ppm-guest at moszumanska.debian.org
Thu May 21 18:52:07 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 c02ce281cda038ed6509483ce370432ea12c4018
Author: Dana Jacobsen <dana at acm.org>
Date:   Thu Jan 30 21:30:26 2014 -0800

    PP is_power with negative arguments
---
 lib/Math/Prime/Util/PP.pm   | 8 ++++----
 lib/Math/Prime/Util/PPFE.pm | 7 ++++---
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/lib/Math/Prime/Util/PP.pm b/lib/Math/Prime/Util/PP.pm
index 27576e2..89be15f 100644
--- a/lib/Math/Prime/Util/PP.pm
+++ b/lib/Math/Prime/Util/PP.pm
@@ -1433,15 +1433,15 @@ sub is_power {
   return !(is_power($n) % $a) if defined $a && $a != 0;
   #return 2 if _is_perfect_square($n);
   $n = Math::BigInt->new("$n") unless ref($n) eq 'Math::BigInt';
-  # Perl 5.6.2 chokes on this, so do it via as_bin
-  # my $log2n = 0; { my $num = $n; $log2n++ while $num >>= 1; }
-  my $log2n = length($n->as_bin) - 2;
-  for (my $e = 2; $e <= $log2n; $e = next_prime($e)) {
+  my $e = 2;
+  while (1) {
     my $root = $n->copy()->broot($e);
+    last if $root->is_one();
     if ($root->copy->bpow($e) == $n) {
       my $next = is_power($root);
       return ($next == 0) ? $e : $e * $next;
     }
+    $e = next_prime($e);
   }
   0;
 }
diff --git a/lib/Math/Prime/Util/PPFE.pm b/lib/Math/Prime/Util/PPFE.pm
index f33f78c..70a1464 100644
--- a/lib/Math/Prime/Util/PPFE.pm
+++ b/lib/Math/Prime/Util/PPFE.pm
@@ -315,10 +315,11 @@ sub chebyshev_psi {
 }
 
 sub is_power {
-  my($x, $a) = @_;
-  _validate_positive_integer($x);
+  my($n, $a) = @_;
+  return 0 if defined $n && $n < 0;
+  _validate_positive_integer($n);
   _validate_positive_integer($a) if defined $a;
-  return Math::Prime::Util::PP::is_power($x, $a);
+  return Math::Prime::Util::PP::is_power($n, $a);
 }
 
 #############################################################################

-- 
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