[libmath-prime-util-perl] 01/23: Add 'verbose' config option

Partha P. Mukherjee ppm-guest at moszumanska.debian.org
Thu May 21 18:45:53 UTC 2015


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

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

commit b9dde29ed3879e621dcae95541aad3c764275685
Author: Dana Jacobsen <dana at acm.org>
Date:   Mon Nov 19 18:20:31 2012 -0800

    Add 'verbose' config option
---
 TODO                   |  2 --
 XS.xs                  |  9 ++++++++-
 aks.c                  | 10 +++++-----
 lib/Math/Prime/Util.pm |  8 ++++++++
 util.c                 |  5 +++++
 util.h                 |  3 +++
 6 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/TODO b/TODO
index c704281..7da582a 100644
--- a/TODO
+++ b/TODO
@@ -33,5 +33,3 @@
 - Add Lehmer in PP (I have a version, just needs some polishing).
 
 - Move AKS tests into their own test, and add some provable prime tests.
-
-- Add a 'verbose' option to general config.
diff --git a/XS.xs b/XS.xs
index 5c69ba7..15f51ff 100644
--- a/XS.xs
+++ b/XS.xs
@@ -17,6 +17,13 @@ PROTOTYPES: ENABLE
 
 
 void
+_XS_set_verbose(IN int verbose)
+
+int
+_XS_get_verbose()
+
+
+void
 prime_precalc(IN UV n)
 
 void
@@ -220,7 +227,7 @@ _XS_factor(IN UV n)
         XPUSHs(sv_2mortal(newSVuv( facs[i-1] )));
       }
     } else {
-      int const verbose = 0;
+      int const verbose = _XS_get_verbose();
       UV const tlim_lower = 211;  /* Trial division through this prime */
       UV const tlim = 223;        /* This means we've checked through here */
       UV tofac_stack[MPU_MAX_FACTORS+1];
diff --git a/aks.c b/aks.c
index 2b43943..d37b6ac 100644
--- a/aks.c
+++ b/aks.c
@@ -15,7 +15,6 @@
  */
 
 #define SQRTN_SHORTCUT 1
-#define VERBOSE 0
 
 #include "ptypes.h"
 #include "util.h"
@@ -159,6 +158,7 @@ int _XS_is_aks_prime(UV n)
 {
   UV sqrtn, limit, r, rlimit, a;
   double log2n;
+  int verbose = _XS_get_verbose();
 
   /* Check for overflow */
 #if BITS_PER_WORD == 32
@@ -180,7 +180,7 @@ int _XS_is_aks_prime(UV n)
   log2n = log(n) / log(2);   /* C99 has a log2() function */
   limit = (UV) floor(log2n * log2n);
 
-  if (VERBOSE) { printf("limit is %lu\n", limit); }
+  if (verbose) { printf("# aks limit is %lu\n", limit); }
 
   for (r = 2; r < n; r++) {
     if ((n % r) == 0)
@@ -198,13 +198,13 @@ int _XS_is_aks_prime(UV n)
 
   rlimit = (UV) floor(sqrt(r-1) * log2n);
 
-  if (VERBOSE) { printf("r = %lu  rlimit = %lu\n", r, rlimit); }
+  if (verbose) { printf("# aks r = %lu  rlimit = %lu\n", r, rlimit); }
 
   for (a = 1; a <= rlimit; a++) {
     if (! test_anr(a, n, r) )
       return 0;
-    if (VERBOSE) { printf("."); fflush(stdout); }
+    if (verbose>1) { printf("."); fflush(stdout); }
   }
-  if (VERBOSE) { printf("\n"); }
+  if (verbose>1) { printf("\n"); }
   return 1;
 }
diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm
index 841fa30..3f2addb 100644
--- a/lib/Math/Prime/Util.pm
+++ b/lib/Math/Prime/Util.pm
@@ -104,6 +104,7 @@ if ($_Config{'maxbits'} == 32) {
   $_Config{'maxprimeidx'} = 425656284035217743;
 }
 $_Config{'assume_rh'} = 0;
+$_Config{'verbose'} = 0;
 
 # used for code like:
 #    return _XS_foo($n)  if $n <= $_XS_MAXVAL
@@ -160,6 +161,13 @@ sub prime_set_config {
       $_HAVE_GMP = $_Config{'gmp'};
     } elsif ($param =~ /^(assume[_ ]?)?[ge]?rh$/ || $param =~ /riemann\s*h/) {
       $_Config{'assume_rh'} = ($value) ? 1 : 0;
+    } elsif ($param eq 'verbose') {
+      if    ($value =~ /^\d+$/) { }
+      elsif ($value =~ /^[ty]/i) { $value = 1; }
+      elsif ($value =~ /^[fn]/i) { $value = 0; }
+      else { croak("Invalid setting for verbose.  0, 1, 2, etc."); }
+      $_Config{'verbose'} = $value;
+      _XS_set_verbose($value) if $_Config{'xs'};
     } else {
       croak "Unknown or invalid configuration setting: $param\n";
     }
diff --git a/util.c b/util.c
index 979fe51..3254cf6 100644
--- a/util.c
+++ b/util.c
@@ -33,6 +33,11 @@ extern long double fabsl(long double);
 #include "cache.h"
 #include "lehmer.h"
 
+static int _verbose = 0;
+void _XS_set_verbose(int v) { _verbose = v; }
+int _XS_get_verbose(void) { return _verbose; }
+
+
 static const unsigned char byte_zeros[256] =
   {8,7,7,6,7,6,6,5,7,6,6,5,6,5,5,4,7,6,6,5,6,5,5,4,6,5,5,4,5,4,4,3,
    7,6,6,5,6,5,5,4,6,5,5,4,5,4,4,3,6,5,5,4,5,4,4,3,5,4,4,3,4,3,3,2,
diff --git a/util.h b/util.h
index 8156590..b300a3d 100644
--- a/util.h
+++ b/util.h
@@ -3,6 +3,9 @@
 
 #include "ptypes.h"
 
+extern int  _XS_get_verbose(void);
+extern void _XS_set_verbose(int v);
+
 extern int _XS_is_prime(UV x);
 extern int is_definitely_prime(UV x);
 extern UV  next_trial_prime(UV x);

-- 
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