[libmath-prime-util-perl] 15/72: Add ifs to powmod initial mod; add verbose to factor.pl

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


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

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

commit cb1eb7ae5c701157dccbe195f864491a98a9c6a7
Author: Dana Jacobsen <dana at acm.org>
Date:   Thu Aug 29 08:51:12 2013 -0700

    Add ifs to powmod initial mod; add verbose to factor.pl
---
 bin/factor.pl          | 5 ++++-
 mulmod.h               | 4 ++--
 xt/primality-proofs.pl | 2 +-
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/bin/factor.pl b/bin/factor.pl
index 5cefe90..9fe1e0d 100755
--- a/bin/factor.pl
+++ b/bin/factor.pl
@@ -3,7 +3,7 @@ use strict;
 use warnings;
 use Getopt::Long;
 use bigint try => 'GMP';
-use Math::Prime::Util qw/factor nth_prime/;
+use Math::Prime::Util qw/factor nth_prime prime_set_config/;
 $| = 1;
 no bigint;
 
@@ -18,6 +18,7 @@ my %mpu_func_map;
 my %opts;
 GetOptions(\%opts,
            'version',   # turn off MPU::GMP for debugging
+           'verbose',
            'help',
           ) || die_usage();
 if (exists $opts{'version'}) {
@@ -29,6 +30,7 @@ if (exists $opts{'version'}) {
   die "$version_str";
 }
 die_usage() if exists $opts{'help'};
+prime_set_config(verbose => 3) if exists $opts{'verbose'};
 
 if (@ARGV) {
   foreach my $n (@ARGV) {
@@ -86,6 +88,7 @@ like prime_count(#), nth_prime(#), primorial(#), random_nbit_prime(#), etc.
 
   --help       displays this help message
   --version    displays the version information
+  --verbose    as we factor, display information about what we're doing
 
 Part of the Math::Prime::Util $Math::Prime::Util::VERSION package, wrapping
 the factor() function.  See 'man Math::Prime::Util' for more information.
diff --git a/mulmod.h b/mulmod.h
index 061ebba..9c08152 100644
--- a/mulmod.h
+++ b/mulmod.h
@@ -122,7 +122,7 @@ static INLINE UV submod(UV a, UV b, UV m) {
 #ifndef HALF_WORD
   static INLINE UV powmod(UV n, UV power, UV m) {
     UV t = 1;
-    n %= m;
+    if (n >= m) n %= m;
     while (power) {
       if (power & 1) t = mulmod(t, n, m);
       power >>= 1;
@@ -133,7 +133,7 @@ static INLINE UV submod(UV a, UV b, UV m) {
 #else
   static INLINE UV powmod(UV n, UV power, UV m) {
     UV t = 1;
-    n %= m;
+    if (n >= m) n %= m;
     if (m < HALF_WORD) {
       while (power) {
         if (power & 1) t = (t*n)%m;
diff --git a/xt/primality-proofs.pl b/xt/primality-proofs.pl
index 721c64c..7dfb951 100755
--- a/xt/primality-proofs.pl
+++ b/xt/primality-proofs.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
 use warnings;
 use strict;
 use Math::Prime::Util ':all';

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