[libmath-prime-util-perl] 88/181: More updates from bulk88 suggestions
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:51:09 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 0885daa6974e5bff4dd2efbf2cf4903a1465d862
Author: Dana Jacobsen <dana at acm.org>
Date: Tue Dec 31 20:14:25 2013 -0800
More updates from bulk88 suggestions
---
XS.xs | 7 +++++--
factor.c | 16 ++++++++--------
primality.c | 5 +++--
3 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/XS.xs b/XS.xs
index d3233c3..b908084 100644
--- a/XS.xs
+++ b/XS.xs
@@ -676,6 +676,11 @@ _validate_num(SV* svn, ...)
SV* sv1;
SV* sv2;
CODE:
+ /* Internal function. Emulate the PP version of this:
+ * $is_valid = _validate_num( $n [, $min [, $max] ] )
+ * Return 0 if we're befuddled by the input.
+ * Otherwise croak if n isn't >= 0 and integer, n < min, or n > max.
+ */
RETVAL = 0;
if (_validate_int(aTHX_ svn, 0)) {
if (SvROK(svn)) { /* Convert small Math::BigInt object into scalar */
@@ -805,7 +810,6 @@ forcomposites (SV* block, IN SV* svbeg, IN SV* svend = 0)
if (cv == Nullcv)
croak("Not a subroutine reference");
- if (items <= 1) return;
if (!_validate_int(aTHX_ svbeg, 0) || (items >= 3 && !_validate_int(aTHX_ svend,0))) {
_vcallsubn(aTHX_ G_VOID|G_DISCARD, "_generic_forcomposites",items);
@@ -886,7 +890,6 @@ fordivisors (SV* block, IN SV* svn)
if (cv == Nullcv)
croak("Not a subroutine reference");
- if (items <= 1) return;
if (!_validate_int(aTHX_ svn, 0)) {
_vcallsubn(aTHX_ G_VOID|G_DISCARD, "_generic_fordivisors",2);
diff --git a/factor.c b/factor.c
index 4b0f976..092a2c9 100644
--- a/factor.c
+++ b/factor.c
@@ -1028,13 +1028,13 @@ static void squfof_unit(UV n, mult_t* mult_save, UV* f)
}
}
-#define NSQUFOF_MULT (sizeof(multipliers)/sizeof(multipliers[0]))
+static const UV squfof_multipliers[] =
+ { 3*5*7*11, 3*5*7, 3*5*11, 3*5, 3*7*11, 3*7, 5*7*11, 5*7,
+ 3*11, 3, 5*11, 5, 7*11, 7, 11, 1 };
+#define NSQUFOF_MULT (sizeof(squfof_multipliers)/sizeof(squfof_multipliers[0]))
int racing_squfof_factor(UV n, UV *factors, UV rounds)
{
- const UV multipliers[] = {
- 3*5*7*11, 3*5*7, 3*5*11, 3*5, 3*7*11, 3*7, 5*7*11, 5*7,
- 3*11, 3, 5*11, 5, 7*11, 7, 11, 1 };
const UV big2 = UV_MAX >> 2;
mult_t mult_save[NSQUFOF_MULT];
int still_racing;
@@ -1050,7 +1050,7 @@ int racing_squfof_factor(UV n, UV *factors, UV rounds)
}
for (i = 0; i < NSQUFOF_MULT; i++) {
- mult = multipliers[i];
+ mult = squfof_multipliers[i];
nn64 = n * mult;
mult_save[i].mult = mult;
if ((big2 / mult) < n) {
@@ -1083,11 +1083,11 @@ int racing_squfof_factor(UV n, UV *factors, UV rounds)
for (i = 0; i < NSQUFOF_MULT; i++) {
if (!mult_save[i].valid)
continue;
- nn64 = n * (UV)multipliers[i];
+ nn64 = n * squfof_multipliers[i];
squfof_unit(nn64, &mult_save[i], &f64);
if (f64 > 1) {
- if (f64 != multipliers[i]) {
- f64 /= gcd_ui(f64, multipliers[i]);
+ if (f64 != squfof_multipliers[i]) {
+ f64 /= gcd_ui(f64, squfof_multipliers[i]);
if (f64 != 1) {
factors[0] = f64;
factors[1] = n / f64;
diff --git a/primality.c b/primality.c
index efa6131..33880a5 100644
--- a/primality.c
+++ b/primality.c
@@ -616,11 +616,12 @@ int _XS_is_almost_extra_strong_lucas_pseudoprime(UV n, UV increment)
W = submod( mont_prod64( montP, montP, n, npi), mont2, n);
V = montP;
while (b--) {
+ UV T = submod( mont_prod64(V, W, n, npi), montP, n);
if ( (d >> b) & UVCONST(1) ) {
- V = submod( mont_prod64(V, W, n, npi), montP, n);
+ V = T;
W = submod( mont_prod64(W, W, n, npi), mont2, n);
} else {
- W = submod( mont_prod64(V, W, n, npi), montP, n);
+ W = T;
V = submod( mont_prod64(V, V, n, npi), mont2, n);
}
}
--
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