[libmath-prime-util-perl] 175/181: znorder and znlog adjustments for edge cases
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:51:18 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 5b7938ab8d32dd6c74a03a50a1f612c245408b89
Author: Dana Jacobsen <dana at acm.org>
Date: Mon Jan 13 18:17:06 2014 -0800
znorder and znlog adjustments for edge cases
---
XS.xs | 5 +++--
util.c | 8 ++++----
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/XS.xs b/XS.xs
index cdf80e6..9ae27f8 100644
--- a/XS.xs
+++ b/XS.xs
@@ -734,8 +734,9 @@ znlog(IN SV* sva, IN SV* svg, IN SV* svp)
gstatus = _validate_int(aTHX_ svg, 0);
pstatus = _validate_int(aTHX_ svp, 0);
if (astatus == 1 && gstatus == 1 && pstatus == 1) {
- UV ret = znlog(my_svuv(sva), my_svuv(svg), my_svuv(svp));
- if (ret == 0) XSRETURN_UNDEF;
+ UV a = my_svuv(sva), g = my_svuv(svg), p = my_svuv(svp);
+ UV ret = znlog(a, g, p);
+ if (ret == 0 && a > 1) XSRETURN_UNDEF;
XSRETURN_UV(ret);
}
_vcallsub_with_pp("znlog");
diff --git a/util.c b/util.c
index dcf76a2..d15f24a 100644
--- a/util.c
+++ b/util.c
@@ -1002,8 +1002,8 @@ UV znorder(UV a, UV n) {
int i, nfactors;
UV j, phi, k = 1;
- if (n == 0 || a == 0) return 0;
- if (n == 1 || a == 1) return 1;
+ if (n <= 1) return n; /* znorder(x,0) = 0, znorder(x,1) = 1 */
+ if (a <= 1) return a; /* znorder(0,x) = 0, znorder(1,x) = 1 (x > 1) */
if (gcd_ui(a,n) > 1) return 0;
/* Abhijit Das, algorithm 1.7, applied to Carmichael Lambda */
@@ -1094,7 +1094,7 @@ UV divmod(UV a, UV b, UV n) { /* a / b mod n */
UV znlog(UV a, UV g, UV p) {
UV k;
const int verbose = _XS_get_verbose();
- if (a == 0 || g == 0 || p < 2)
+ if (a <= 1 || g == 0 || p < 2)
return 0;
k = dlp_trial(a, g, p, DLP_TRIAL_NUM);
if (k != 0 || p <= DLP_TRIAL_NUM)
@@ -1221,7 +1221,7 @@ long double _XS_ExponentialIntegral(long double x) {
fact_n *= (long double)x * invn;
term = fact_n * invn;
KAHAN_SUM(sum, term);
- /* printf("C after adding %.8lf, val = %.8lf\n", term, sum); */
+ /* printf("C after adding %.20Lf, val = %.20Lf\n", term, sum); */
if ( term < LDBL_EPSILON*sum) break;
}
KAHAN_SUM(sum, euler_mascheroni);
--
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