[libmath-prime-util-perl] 118/181: Make is_bpsw_prime a first class function (though currently not exported)

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


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

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

commit 4f9aa60d94b2cb7d2ace221885f62726743204ef
Author: Dana Jacobsen <dana at acm.org>
Date:   Sun Jan 5 17:31:48 2014 -0800

    Make is_bpsw_prime a first class function (though currently not exported)
---
 XS.xs                     |  6 +++---
 lib/Math/Prime/Util.pm    |  2 +-
 lib/Math/Prime/Util/PP.pm | 20 +++++++++++++++-----
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/XS.xs b/XS.xs
index c6f7254..7e791ea 100644
--- a/XS.xs
+++ b/XS.xs
@@ -465,7 +465,7 @@ void
 is_prime(IN SV* svn, ...)
   ALIAS:
     is_prob_prime = 1
-    is_bpsw = 2
+    is_bpsw_prime = 2
     is_lucas_pseudoprime = 3
     is_strong_lucas_pseudoprime = 4
     is_extra_strong_lucas_pseudoprime = 5
@@ -501,8 +501,8 @@ is_prime(IN SV* svn, ...)
     }
     switch (ix) {
       case 0: _vcallsub_with_gmp("is_prime");       break;
-      case 1:
-      case 2: _vcallsub_with_gmp("is_prob_prime");  break;
+      case 1: _vcallsub_with_gmp("is_prob_prime");  break;
+      case 2: _vcallsub_with_gmp("is_bpsw_prime");  break;
       case 3: _vcallsub_with_gmp("is_lucas_pseudoprime"); break;
       case 4: _vcallsub_with_gmp("is_strong_lucas_pseudoprime"); break;
       case 5: _vcallsub_with_gmp("is_extra_strong_lucas_pseudoprime"); break;
diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm
index 1018b31..a0d401d 100644
--- a/lib/Math/Prime/Util.pm
+++ b/lib/Math/Prime/Util.pm
@@ -131,7 +131,7 @@ BEGIN {
     *prime_memfree  = \&Math::Prime::Util::PP::prime_memfree;
     *prime_precalc  = \&Math::Prime::Util::PP::prime_precalc;
 
-    # These probably shouldn't even be exported
+    # These probably shouldn't even be aliased, as they're not public
     *trial_factor   = \&Math::Prime::Util::PP::trial_factor;
     *fermat_factor  = \&Math::Prime::Util::PP::fermat_factor;
     *holf_factor    = \&Math::Prime::Util::PP::holf_factor;
diff --git a/lib/Math/Prime/Util/PP.pm b/lib/Math/Prime/Util/PP.pm
index 8265f9d..211b2a4 100644
--- a/lib/Math/Prime/Util/PP.pm
+++ b/lib/Math/Prime/Util/PP.pm
@@ -197,11 +197,7 @@ sub _is_prime7 {  # n must not be divisible by 2, 3, or 5
     return is_strong_pseudoprime($n, @bases)  ?  2  :  0;
   }
 
-  # BPSW probable prime.  No composites are known to have passed this test
-  # since it was published in 1980, though we know infinitely many exist.
-  # It has also been verified that no 64-bit composite will return true.
-  # Slow since it's all in PP and uses bigints.
-
+  # Inlined BPSW
   return 0 unless is_strong_pseudoprime($n, 2);
   if ($n <= 18446744073709551615) {
     return is_almost_extra_strong_lucas_pseudoprime($n) ? 2 : 0;
@@ -222,6 +218,20 @@ sub is_prime {
 # is_prob_prime is the same thing for us.
 *is_prob_prime = \&is_prime;
 
+# BPSW probable prime.  No composites are known to have passed this test
+# since it was published in 1980, though we know infinitely many exist.
+# It has also been verified that no 64-bit composite will return true.
+# Slow since it's all in PP and uses bigints.
+sub is_bpsw_prime {
+  my($n) = @_;
+  _validate_positive_integer($n);
+  return 0 unless is_strong_pseudoprime($n, 2);
+  if ($n <= 18446744073709551615) {
+    return is_almost_extra_strong_lucas_pseudoprime($n) ? 2 : 0;
+  }
+  return is_extra_strong_lucas_pseudoprime($n) ? 1 : 0;
+}
+
 # Possible sieve storage:
 #   1) vec with mod-30 wheel:   8 bits  / 30
 #   2) vec with mod-2 wheel :  15 bits  / 30

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