[libmath-prime-util-perl] 01/06: Fix next_prime

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


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

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

commit 04af4abecd65b6c3c55f202f42b87a5f540b7236
Author: Dana Jacobsen <dana at acm.org>
Date:   Thu Jun 7 13:16:46 2012 -0600

    Fix next_prime
---
 Changes                |  4 ++++
 README                 |  2 +-
 lib/Math/Prime/Util.pm |  4 ++--
 t/12-nextprime.t       |  2 +-
 util.c                 | 14 +++++++-------
 5 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/Changes b/Changes
index cd77577..69b2f9b 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 Revision history for Perl extension Math::Prime::Util.
 
+0.04  7 June 2012
+    - Didn't do tests on 32-bit machine before release.  Test suite caught
+      problem with next_prime overflow.
+
 0.03  6 June 2012
     - Speed up factoring.
     - fixed powmod routine, speedup for smaller numbers
diff --git a/README b/README
index 391fec9..bffb345 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-Math::Prime::Util version 0.03
+Math::Prime::Util version 0.04
 
 A set of utilities related to prime numbers.  These include multiple sieving
 methods, is_prime, prime_count, nth_prime, approximations and bounds for
diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm
index 6a155c2..70e93b9 100644
--- a/lib/Math/Prime/Util.pm
+++ b/lib/Math/Prime/Util.pm
@@ -5,7 +5,7 @@ use Carp qw/croak confess/;
 
 BEGIN {
   $Math::Prime::Util::AUTHORITY = 'cpan:DANAJ';
-  $Math::Prime::Util::VERSION = '0.03';
+  $Math::Prime::Util::VERSION = '0.04';
 }
 
 # parent is cleaner, and in the Perl 5.10.1 / 5.12.0 core, but not earlier.
@@ -132,7 +132,7 @@ Math::Prime::Util - Utilities related to prime numbers, including fast sieves an
 
 =head1 VERSION
 
-Version 0.03
+Version 0.04
 
 
 =head1 SYNOPSIS
diff --git a/t/12-nextprime.t b/t/12-nextprime.t
index 20c8518..6cd225b 100644
--- a/t/12-nextprime.t
+++ b/t/12-nextprime.t
@@ -64,4 +64,4 @@ is( prev_prime(19660), 19609, "prev prime of 19660 is 19609" );
 is( prev_prime(19610), 19609, "prev prime of 19610 is 19609" );
 
 is( prev_prime(2), 0, "Previous prime of 2 returns 0" );
-is( next_prime(~0-5), 0, "Next prime of ~0-5 returns 0" );
+is( next_prime(~0-4), 0, "Next prime of ~0-4 returns 0" );
diff --git a/util.c b/util.c
index cc920a5..71607b4 100644
--- a/util.c
+++ b/util.c
@@ -185,6 +185,13 @@ UV next_prime(UV n)
   if (n < NPRIME_NEXT_SMALL)
     return prime_next_small[n];
 
+  /* Overflow */
+#if BITS_PER_WORD == 32
+  if (n >= UVCONST(4294967291))  return 0;
+#else
+  if (n >= UVCONST(18446744073709551557))  return 0;
+#endif
+
   sieve_size = get_prime_cache(0, &sieve);
   if (n < sieve_size) {
     START_DO_FOR_EACH_SIEVE_PRIME(sieve, n+1, sieve_size)
@@ -194,13 +201,6 @@ UV next_prime(UV n)
     n = sieve_size;
   }
 
-  /* Overflow */
-#if BITS_PER_WORD == 32
-  if (n > UVCONST(4294967291))  return 0;
-#else
-  if (n > UVCONST(18446744073709551557))  return 0;
-#endif
-
   d = n/30;
   m = n - d*30;
   m = nextwheel30[m];  if (m == 1) d++;

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