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

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

commit 45767dff621e97f86643c59cf0510bbd64734cd8
Author: Dana Jacobsen <d...@acm.org>
Date:   Mon Oct 15 16:26:43 2012 -0600

    Fix issue with string input just a little larger than ~0
---
 lib/Math/Prime/Util.pm | 3 ++-
 t/10-isprime.t         | 6 +++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm
index 2f3bec9..5b4fa69 100644
--- a/lib/Math/Prime/Util.pm
+++ b/lib/Math/Prime/Util.pm
@@ -172,7 +172,8 @@ sub _validate_positive_integer {
   croak "Parameter '$n' must be a positive integer" if $n =~ tr/0123456789//c;
   croak "Parameter '$n' must be >= $min" if defined $min && $n < $min;
   croak "Parameter '$n' must be <= $max" if defined $max && $n > $max;
-  if ($n <= $_Config{'maxparam'}) {
+  # this used instead of '<=' to fix strings like ~0+delta
+  if ($n < $_Config{'maxparam'} || int($n) eq $_Config{'maxparam'}) {
     $_[0] = $_[0]->as_number() if ref($_[0]) eq 'Math::BigFloat';
     $_[0] = int($_[0]->bstr) if ref($_[0]) eq 'Math::BigInt';
   } elsif (ref($n) ne 'Math::BigInt') {
diff --git a/t/10-isprime.t b/t/10-isprime.t
index 4ca9e60..64a7734 100644
--- a/t/10-isprime.t
+++ b/t/10-isprime.t
@@ -8,7 +8,7 @@ use Math::Prime::Util qw/is_prime/;
 my $use64 = Math::Prime::Util::prime_get_config->{'maxbits'} > 32;
 my $extra = defined $ENV{RELEASE_TESTING} && $ENV{RELEASE_TESTING};
 
-plan tests => 6 + 19 + 3573 + (5 + 29 + 22 + 23 + 16) + 15 + 27
+plan tests => 6 + 19 + 3573 + (5 + 29 + 22 + 23 + 16) + 15 + 27 + 1
               + ($use64 ? 5+1 : 0)
               + ($extra ? 6 : 0)
               + (($extra && $use64) ? 19 : 0);
@@ -110,3 +110,7 @@ map { ok(is_prime($_), "Primegap end $_ is prime" ) }
      614487453523 738832927927 1346294310749 1408695493609 1968188556461
      2614941710599/
   if $use64 && $extra;
+
+# Check that we do the right thing near the word-size edge
+eval { is_prime( $use64 ? "18446744073709551629" : "4294967306" ); };
+like($@, qr/range/i, "is_prime on ~0 + delta without bigint should croak");

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

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to