[libmath-prime-util-perl] 09/13: bigint / bignum changes

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


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

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

commit 1d54e81f62ae4e0d8f4eb05b77725514171af153
Author: Dana Jacobsen <dana at acm.org>
Date:   Sun Jul 22 18:00:44 2012 -0600

    bigint / bignum changes
---
 lib/Math/Prime/Util.pm    | 11 +++++------
 lib/Math/Prime/Util/PP.pm | 15 +++++++++------
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm
index e65c299..e92c858 100644
--- a/lib/Math/Prime/Util.pm
+++ b/lib/Math/Prime/Util.pm
@@ -745,10 +745,9 @@ sub next_prime {
   my($n) = @_;
   _validate_positive_integer($n);
 
-  # If n is native precision AND not a bigint or not the last native prime,
-  # then we can call the XS function.
+  # If we have XS and n is either small or bigint is unknown, then use XS.
   return _XS_next_prime($n) if $n <= $_XS_MAXVAL
-                            && (ref($_[0]) ne 'Math::BigInt' || $n < $_Config{'maxprime'});
+             && (!defined $bigint::VERSION || $n < $_Config{'maxprime'} );
 
   if ($_HAVE_GMP) {
     # If $n is a bigint object, try to make the return value the same
@@ -1386,7 +1385,7 @@ for many of the functions.  This does require the L<GMP|gttp://gmplib.org>
 library be installed on your system, but this increasingly comes pre-installed
 or easily available using the OS vendor package installation tool.  If you
 do not want to use that, I recommend L<Math::BigInt::GMP> or
-L<Math::BigInt::Pari> and then writing C<use bigint try => 'GMP,Pari'>.
+L<Math::BigInt::Pari> and then writing C<use bigint try =E<gt> 'GMP,Pari'>.
 Large modular exponentiation is much faster using the GMP or Pari backends.
 This is not so important if you installed L<Math::Prime::Util::GMP>, but it can
 still speed up large random Maurer primes.
@@ -1824,7 +1823,7 @@ for "hard" numbers.  Installing the L<Math::Prime::Util::GMP> module will speed
 up bigint factoring a B<lot>, and all future effort on large number factoring
 will be in that module.  If you do not have that module for some reason, use
 the GMP or Pari version of bigint if possible
-(e.g. C<use bigint try => 'GMP,Pari'>), which will run 2-3x faster (though
+(e.g. C<use bigint try =E<gt> 'GMP,Pari'>), which will run 2-3x faster (though
 still 100x slower than the real GMP code).
 
 
@@ -2092,7 +2091,7 @@ The presentation here:
  L<http://math.boisestate.edu/~liljanab/BOISECRYPTFall09/Jacobsen.pdf>
 has a lot of data on 64-bit and GMP factoring performance I collected in 2009.
 Assuming you do not know anything about the inputs, trial division and
-optimized Fermat or Lehmen work very well for small numbers (<= 10 digits),
+optimized Fermat or Lehman work very well for small numbers (<= 10 digits),
 while native SQUFOF is typically the method of choice for 11-18 digits (I've
 seen claims that a lightweight QS can be faster for 15+ digits).  Some form
 of Quadratic Sieve is usually used for inputs in the 19-100 digit range, and
diff --git a/lib/Math/Prime/Util/PP.pm b/lib/Math/Prime/Util/PP.pm
index 4a589bc..6a59411 100644
--- a/lib/Math/Prime/Util/PP.pm
+++ b/lib/Math/Prime/Util/PP.pm
@@ -300,8 +300,8 @@ sub primes {
   # At some point even the pretty-fast pure perl sieve is going to be a
   # dog, and we should move to trials.  This is typical with a small range
   # on a large base.  More thought on the switchover should be done.
-  return trial_primes($low, $high) if ref($low)  =~ /^Math::Big/
-                                   || ref($high) =~ /^Math::Big/
+  return trial_primes($low, $high) if ref($low)  eq 'Math::BigInt'
+                                   || ref($high) eq 'Math::BigInt'
                                    || ($low > 1_000_000_000_000 && ($high-$low) < int($low/1_000_000));
 
   push @$sref, 2  if ($low <= 2) && ($high >= 2);
@@ -333,7 +333,10 @@ sub primes {
 sub next_prime {
   my($n) = @_;
   _validate_positive_integer($n);
-  return 0 if ($n >= ((_PP_prime_maxbits == 32) ? 4294967291 : 18446744073709551557)) && ref($n) ne 'Math::BigInt';
+  if ($n >= ((_PP_prime_maxbits == 32) ? 4294967291 : 18446744073709551557)) {
+    return 0 if ref($_[0]) ne 'Math::BigInt';
+    $n = $_[0];  # $n is a bigint now
+  }
   return $_prime_next_small[$n] if $n <= $#_prime_next_small;
 
   # Be careful trying to do:
@@ -401,7 +404,7 @@ sub prime_count {
   $high-- if ($high % 2) == 0; # Make high go to odd number.
   return $count if $low > $high;
 
-  if (   ref($low)  =~ /^Math::Big/ || ref($high) =~ /^Math::Big/
+  if (   ref($low) eq 'Math::BigInt' || ref($high) eq 'Math::BigInt'
       || $high > 16_000_000_000
       || ($high-$low) < int($low/1_000_000) ) {
     # Too big to sieve.
@@ -1147,7 +1150,7 @@ sub ExponentialIntegral {
 
   croak "Invalid input to ExponentialIntegral:  x must be != 0" if $x == 0;
 
-  $x = new Math::BigFloat "$x"  if defined $Math::BigFloat::VERSION && ref($x) ne 'Math::BigFloat';
+  $x = new Math::BigFloat "$x"  if defined $bignum::VERSION && ref($x) ne 'Math::BigFloat';
 
   my $val; # The result from one of the four methods
 
@@ -1296,7 +1299,7 @@ sub RiemannR {
 
   croak "Invalid input to ReimannR:  x must be > 0" if $x <= 0;
 
-  $x = new Math::BigFloat "$x"  if defined $Math::BigFloat::VERSION && ref($x) ne 'Math::BigFloat';
+  $x = new Math::BigFloat "$x"  if defined $bignum::VERSION && ref($x) ne 'Math::BigFloat';
 
   $y = 1.0-$c; $t = $sum+$y; $c = ($t-$sum)-$y; $sum = $t;
   my $flogx = log($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