[libmath-prime-util-perl] 10/11: pedantic cleanup
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:44:18 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.03
in repository libmath-prime-util-perl.
commit 15e84bd2e48825b2f3f29f3289bff757a7bfa0a0
Author: Dana Jacobsen <dana at acm.org>
Date: Wed Jun 6 19:42:38 2012 -0600
pedantic cleanup
---
Changes | 2 +-
XS.xs | 1 -
factor.c | 33 ++++++++++++++++-----------------
util.c | 24 +++++++++++++-----------
4 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/Changes b/Changes
index d5f7bd5..6a51075 100644
--- a/Changes
+++ b/Changes
@@ -2,7 +2,7 @@ Revision history for Perl extension Math::Prime::Util.
0.03 6 June 2012
- Speed up factoring a little by moving some work into the XS routine.
- - fixed powmod routine
+ - fixed powmod routine, speedup for smaller numbers
- Add Miller-Rabin and deterministic probable prime functions.
0.02 5 June 2012
diff --git a/XS.xs b/XS.xs
index 53c1a5f..f034c51 100644
--- a/XS.xs
+++ b/XS.xs
@@ -81,7 +81,6 @@ _maxbits()
SV*
sieve_primes(IN UV low, IN UV high)
PREINIT:
- UV s;
const unsigned char* sieve;
AV* av = newAV();
CODE:
diff --git a/factor.c b/factor.c
index 31b33c3..6a4503e 100644
--- a/factor.c
+++ b/factor.c
@@ -93,7 +93,6 @@ static UV gcd_ui(UV x, UV y) {
#define HALF_WORD (UVCONST(1) << (BITS_PER_WORD/2))
static UV mulmod(UV a, UV b, UV m) {
- UV p;
UV r = 0;
while (b > 0) {
if (b & 1) {
@@ -223,30 +222,30 @@ int is_prob_prime(UV n)
nbases = 3;
} else if (n < UVCONST(105936894253)) {
bases[0] = 2;
- bases[1] = 1005905886;
- bases[2] = 1340600841;
+ bases[1] = UVCONST( 1005905886 );
+ bases[2] = UVCONST( 1340600841 );
nbases = 3;
} else if (n < UVCONST(31858317218647)) {
bases[0] = 2;
- bases[1] = 642735;
- bases[2] = 553174392;
- bases[3] = 3046413974;
+ bases[1] = UVCONST( 642735 );
+ bases[2] = UVCONST( 553174392 );
+ bases[3] = UVCONST( 3046413974 );
nbases = 4;
} else if (n < UVCONST(3071837692357849)) {
bases[0] = 2;
- bases[1] = 75088;
- bases[2] = 642735;
- bases[3] = 203659041;
- bases[4] = 3613982119;
+ bases[1] = UVCONST( 75088 );
+ bases[2] = UVCONST( 642735 );
+ bases[3] = UVCONST( 203659041 );
+ bases[4] = UVCONST( 3613982119 );
nbases = 5;
} else {
bases[0] = 2;
- bases[1] = 325;
- bases[2] = 9375;
- bases[3] = 28178;
- bases[4] = 450775;
- bases[5] = 9780504;
- bases[6] = 1795265022;
+ bases[1] = UVCONST( 325 );
+ bases[2] = UVCONST( 9375 );
+ bases[3] = UVCONST( 28178 );
+ bases[4] = UVCONST( 450775 );
+ bases[5] = UVCONST( 9780504 );
+ bases[6] = UVCONST( 1795265022 );
nbases = 7;
}
#else
@@ -409,7 +408,7 @@ int pminus1_factor(UV n, UV *factors, UV rounds)
return 2;
}
}
- factors[0] = f;
+ factors[0] = n;
return 1;
}
diff --git a/util.c b/util.c
index 44ebf7f..3d0c116 100644
--- a/util.c
+++ b/util.c
@@ -275,17 +275,17 @@ static const unsigned char prime_count_small[] =
16,16,16,16,16,16,17,17,18,18,18,18,18,18,19};
#define NPRIME_COUNT_SMALL (sizeof(prime_count_small)/sizeof(prime_count_small[0]))
-static const float F1 = 1.0;
+static const double F1 = 1.0;
UV prime_count_lower(UV x)
{
- float fx, flogx;
- float a = 1.80;
+ double fx, flogx;
+ double a = 1.80;
if (x < NPRIME_COUNT_SMALL)
return prime_count_small[x];
- fx = (float)x;
- flogx = logf(x);
+ fx = (double)x;
+ flogx = log(x);
if (x < 599)
return (UV) (fx / (flogx-0.7));
@@ -308,14 +308,14 @@ UV prime_count_lower(UV x)
UV prime_count_upper(UV x)
{
- float fx, flogx;
- float a = 2.51;
+ double fx, flogx;
+ double a = 2.51;
if (x < NPRIME_COUNT_SMALL)
return prime_count_small[x];
- fx = (float)x;
- flogx = logf(x);
+ fx = (double)x;
+ flogx = log(x);
/* This function is unduly complicated. */
@@ -554,7 +554,10 @@ UV nth_prime_approx(UV n)
else if (n < 12000) approx += 3.0 * order;
else if (n <150000) approx += 2.1 * order;
- return (UV) rint(approx);
+ if (approx > (double)UV_MAX)
+ return 0;
+
+ return (UV) (approx + 0.5);
}
@@ -569,7 +572,6 @@ UV nth_prime_approx(UV n)
static UV count_segment(const unsigned char* sieve, UV nbytes, UV maxcount, UV* pos)
{
UV count = 0;
- UV bytes_left;
UV byte = 0;
assert(sieve != 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