[libmath-prime-util-perl] 39/43: Fix an old random_prime() bigint case. No effect on proven, ndigit, or nbit random primes.
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:53:09 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.40
in repository libmath-prime-util-perl.
commit f7325af2dfecf0fbb8d0cbd114377a7769a0f370
Author: Dana Jacobsen <dana at acm.org>
Date: Fri Apr 18 17:42:50 2014 -0700
Fix an old random_prime() bigint case. No effect on proven, ndigit, or nbit random primes.
---
Changes | 2 ++
lib/Math/Prime/Util.pm | 4 ++--
lib/Math/Prime/Util/PP.pm | 2 +-
lib/Math/Prime/Util/RandomPrimes.pm | 3 +--
4 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/Changes b/Changes
index 96765af..3b12038 100644
--- a/Changes
+++ b/Changes
@@ -28,6 +28,8 @@ Revision history for Perl module Math::Prime::Util
- Ranged totient is slightly faster with start of 0.
+ - Fix random_prime with a bigint prime high value.
+
0.39 2014-03-01
diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm
index 480c333..9b13735 100644
--- a/lib/Math/Prime/Util.pm
+++ b/lib/Math/Prime/Util.pm
@@ -1315,7 +1315,7 @@ for the answer, using some small table acceleration.
Returns an approximation to the twin prime count of C<n>. This returns
quickly and has a very small error for large values. The method used is
conjecture B of Hardy and Littlewood 1922, as stated in
-Sebah and Gourdon 2002. For inputs under 10M, a correction factor is
+Sebah and Gourdon 2002. For inputs under 10M, a correction factor is
additionally applied to reduce the mean squared error.
@@ -3179,7 +3179,7 @@ The default L<Math::Pari> is built with Pari 2.1.7. This uses 10 M-R
tests with randomly chosen bases (fixed seed, but doesn't reset each
invocation like GMP's C<is_probab_prime>). This has a greater chance
of false positives compared to the BPSW test -- some composites such as
-C<9>, C<88831>, C<38503>, etc.
+C<9>, C<88831>, C<38503>, etc.
(L<OEIS A141768|http://oeis.org/A141768>)
have a surprisingly high chance of being indicated prime.
Using C<isprime($n,1)> will perform an C<n-1> proof,
diff --git a/lib/Math/Prime/Util/PP.pm b/lib/Math/Prime/Util/PP.pm
index be6adee..79e1d2c 100644
--- a/lib/Math/Prime/Util/PP.pm
+++ b/lib/Math/Prime/Util/PP.pm
@@ -2308,7 +2308,7 @@ sub trial_factor {
foreach my $finc (@incs) {
if ($n->copy->bmod($f)->is_zero && $f->bacmp($limit) <= 0) {
my $sf = ($f <= ''.~0) ? _bigint_to_int($f) : $f;
- do { push @factors, $sf; $n = int($n/$f); } while (($n % $f) == 0);
+ do { push @factors, $sf; $n = ($n/$f)->bfloor(); } while (($n % $f) == 0);
last SEARCH if $n->is_one;
$limit = int( sqrt($n) + 0.001);
$limit = $maxlim if $limit > $maxlim;
diff --git a/lib/Math/Prime/Util/RandomPrimes.pm b/lib/Math/Prime/Util/RandomPrimes.pm
index d1306ca..1179571 100644
--- a/lib/Math/Prime/Util/RandomPrimes.pm
+++ b/lib/Math/Prime/Util/RandomPrimes.pm
@@ -501,8 +501,7 @@ sub random_prime {
# Tighten the range to the nearest prime.
$low = ($low <= 2) ? 2 : next_prime($low-1);
- # TODO: if high is bigint, we should do high++?
- $high = ($high < ~0) ? prev_prime($high + 1) : prev_prime($high);
+ $high = ($high == ~0) ? prev_prime($high) : prev_prime($high + 1);
return $low if ($low == $high) && is_prob_prime($low);
return if $low >= $high;
--
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