[libmath-prime-util-perl] 04/16: Round the perfect power test, note its faults

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


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

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

commit 8c4dfebfa7f1b91ac7ada32308d562b68f124df5
Author: Dana Jacobsen <dana at acm.org>
Date:   Mon Jan 14 01:39:32 2013 -0800

    Round the perfect power test, note its faults
---
 aks.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/aks.c b/aks.c
index ee48331..b9be560 100644
--- a/aks.c
+++ b/aks.c
@@ -38,14 +38,15 @@ static UV log2floor(UV n) {
 }
 
 /* See Bach and Sorenson (1993) for much better algorithm */
+/* This isn't generally going to work for numbers > 2**53 */
 static int is_perfect_power(UV x) {
   UV b, last;
   if ((x & (x-1)) == 0)  return 1;          /* powers of 2    */
-  b = sqrt(x); if (b*b == x)  return 1;     /* perfect square */
+  b = sqrt(x)+0.5; if (b*b == x)  return 1; /* perfect square */
   last = log2floor(x) + 1;
   for (b = 3; b < last; b = _XS_next_prime(b)) {
-    UV root = pow(x, 1.0 / (double)b);
-    if (pow(root, b) == x)  return 1;
+    UV root = pow(x, 1.0 / (double)b) + 0.5;
+    if ( ((UV)(pow(root, b)+0.5)) == x)  return 1;
   }
   return 0;
 }

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