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

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

commit 7228a756b2f706622b2edb74033207629f596b0b
Author: Dana Jacobsen <d...@acm.org>
Date:   Mon Feb 25 19:38:46 2013 -0800

    Compiler warnings and coverage
---
 MANIFEST                  |  2 +-
 lib/Math/Prime/Util.pm    |  7 +++----
 lib/Math/Prime/Util/PP.pm |  1 +
 sieve.h                   |  4 ++++
 t/50-factoring.t          |  5 ++++-
 t/81-bignum.t             | 15 +++++++++++----
 util.c                    | 35 +----------------------------------
 util.h                    |  1 -
 8 files changed, 25 insertions(+), 45 deletions(-)

diff --git a/MANIFEST b/MANIFEST
index 6457a3a..bcd426f 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -49,7 +49,6 @@ examples/test-primes-yafu.pl
 examples/test-holf.pl
 examples/test-nthapprox.pl
 examples/test-pcapprox.pl
-examples/test-primality-small.pl
 examples/sophie_germain.pl
 examples/twin_primes.pl
 examples/find_mr_bases.pl
@@ -88,4 +87,5 @@ t/90-release-perlcritic.t
 t/91-release-pod-syntax.t
 t/92-release-pod-coverage.t
 xt/moebius-mertens.pl
+xt/primality-small.pl
 .travis.yml
diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm
index 22589e0..d2f85e8 100644
--- a/lib/Math/Prime/Util.pm
+++ b/lib/Math/Prime/Util.pm
@@ -1255,10 +1255,9 @@ sub divisor_sum {
   }
 
   croak "Second argument must be a code ref" unless ref($sub) eq 'CODE';
-  my $sum = $n - $n;
-  return ($sum+$sub->(1)) if $n == 1;
-
-  foreach my $f (1, all_factors($n), $n ) {
+  my $sum = $sub->(1);
+  return $sum if $n == 1;
+  foreach my $f (all_factors($n), $n ) {
     $sum += $sub->($f);
   }
   return $sum;
diff --git a/lib/Math/Prime/Util/PP.pm b/lib/Math/Prime/Util/PP.pm
index 6bccaed..4f036d8 100644
--- a/lib/Math/Prime/Util/PP.pm
+++ b/lib/Math/Prime/Util/PP.pm
@@ -1138,6 +1138,7 @@ sub trial_factor {
 sub factor {
   my($n) = @_;
   _validate_positive_integer($n);
+  $n = $n->copy if ref($n) eq 'Math::BigInt';
 
   return trial_factor($n) if $n < 100000;
 
diff --git a/sieve.h b/sieve.h
index 9bf8c49..8e1f3f9 100644
--- a/sieve.h
+++ b/sieve.h
@@ -27,12 +27,14 @@ static const unsigned char distancewheel30[30] =
 static const unsigned char wheeladvance30[30] =
     {0,6,0,0,0,0,0,4,0,0,0,2,0,4,0,0,0,2,0,4,0,0,0,6,0,0,0,0,0,2};
 
+#if 0
 static int is_prime_in_sieve(const unsigned char* sieve, UV p) {
   UV d = p/30;
   UV m = p - d*30;
   /* If m isn't part of the wheel, we return 0 */
   return ( (masktab30[m] != 0) && ((sieve[d] & masktab30[m]) == 0) );
 }
+#endif
 
 /* Warning -- can go off the end of the sieve */
 static UV next_prime_in_sieve(const unsigned char* sieve, UV p) {
@@ -47,6 +49,7 @@ static UV next_prime_in_sieve(const unsigned char* sieve, UV 
p) {
   } while (sieve[d] & masktab30[m]);
   return(d*30+m);
 }
+#if 0
 static UV prev_prime_in_sieve(const unsigned char* sieve, UV p) {
   UV d, m;
   if (p <= 7)
@@ -58,6 +61,7 @@ static UV prev_prime_in_sieve(const unsigned char* sieve, UV 
p) {
   } while (sieve[d] & masktab30[m]);
   return(d*30+m);
 }
+#endif
 
 /* Useful macros for the wheel-30 sieve array */
 #define START_DO_FOR_EACH_SIEVE_PRIME(sieve, a, b) \
diff --git a/t/50-factoring.t b/t/50-factoring.t
index fdc2008..35cf133 100644
--- a/t/50-factoring.t
+++ b/t/50-factoring.t
@@ -73,7 +73,7 @@ my %all_factors = (
       0 => [],
 );
 
-plan tests =>  (2 * scalar @testn) + scalar(keys %all_factors) + 7*8;
+plan tests =>  (2 * scalar @testn) + scalar(keys %all_factors) + 10*8;
 
 foreach my $n (@testn) {
   my @f = factor($n);
@@ -113,7 +113,10 @@ sub extra_factor_test {
   is_deeply( [ sort {$a<=>$b} $fsub->(1)   ], [1],       "$fname(1)" );
   is_deeply( [ sort {$a<=>$b} $fsub->(4)   ], [2, 2],    "$fname(4)" );
   is_deeply( [ sort {$a<=>$b} $fsub->(9)   ], [3, 3],    "$fname(9)" );
+  is_deeply( [ sort {$a<=>$b} $fsub->(11)  ], [11],      "$fname(11)" );
   is_deeply( [ sort {$a<=>$b} $fsub->(25)  ], [5, 5],    "$fname(25)" );
+  is_deeply( [ sort {$a<=>$b} $fsub->(30)  ], [2, 3, 5], "$fname(30)" );
+  is_deeply( [ sort {$a<=>$b} $fsub->(210) ], [2,3,5,7], "$fname(210)" );
   is_deeply( [ sort {$a<=>$b} $fsub->(175) ], [5, 5, 7], "$fname(175)" );
   is_deeply( [ sort {$a<=>$b} $fsub->(403) ], [13, 31],  "$fname(403)" );
   is_deeply( [ sort {$a<=>$b} $fsub->(549900) ], [2,2,3,3,5,5,13,47],  
"$fname(549900)" );
diff --git a/t/81-bignum.t b/t/81-bignum.t
index d7bfba8..96e5baa 100644
--- a/t/81-bignum.t
+++ b/t/81-bignum.t
@@ -74,7 +74,7 @@ plan tests =>  0
              + 6*2*$extra # more PC tests
              + scalar(keys %factors)
              + scalar(keys %allfactors)
-             + 2   # moebius, euler_phi
+             + 4   # moebius, euler_phi, jordan totient
              + 15  # random primes
              + 0;
 
@@ -95,6 +95,8 @@ use Math::Prime::Util qw/
   all_factors
   moebius
   euler_phi
+  jordan_totient
+  divisor_sum
   ExponentialIntegral
   LogarithmicIntegral
   RiemannR
@@ -199,9 +201,14 @@ SKIP: {
 ###############################################################################
 
 SKIP: {
-  skip "Your 64-bit Perl is broken, skipping moebius and euler_phi tests", 2 
if $broken64;
-  is( moebius(618970019642690137449562110), -1, 
"moebius(618970019642690137449562110)" );
-  is( euler_phi(618970019642690137449562110), 145857122964987051805507584, 
"euler_phi(618970019642690137449562110)" );
+  skip "Your 64-bit Perl is broken, skipping moebius and euler_phi tests", 4 
if $broken64;
+  my $n;
+  $n = 618970019642690137449562110;
+  is( moebius($n), -1, "moebius($n)" );
+  is( euler_phi($n), 145857122964987051805507584, "euler_phi($n)" );
+  $n = 48981631802481400359696467;
+  is( jordan_totient(5,$n), 
281946200770875813001683560563488308767928594805846855593191749929654015729263525162226378019837608857421063724603387506651820000,
 "jordan_totient(5,$n)" );
+  is( divisor_sum( $n, sub { my $d=shift; $d**5 * moebius($n/$d); }), 
281946200770875813001683560563488308767928594805846855593191749929654015729263525162226378019837608857421063724603387506651820000,
 "jordan totient using divisor_sum and moebius" );
 }
 
 ###############################################################################
diff --git a/util.c b/util.c
index b6aa33e..5e83a3a 100644
--- a/util.c
+++ b/util.c
@@ -14,7 +14,7 @@
 /* These math functions are a clusterfrack.  They're defined by C99, but
  * NetBSD doesn't have them.  You need them in both the headers and libraries,
  * but there is no standard way to find out if the libraries have them.  The
- * best way (I belive) to deal with this is having the make system do test
+ * best way (I believe) to deal with this is having the make system do test
  * compiles.  Barring that, we make limited guesses, and just give up
  * precision on any system we don't recognize.
  */
@@ -151,39 +151,6 @@ int _XS_is_prime(UV n)
   return (isprime >= 0)  ?  isprime  :  _is_prime7(n);
 }
 
-/* Shortcut, asking for a very quick response of 1 = prime, 0 = dunno.
- * No trial divisions will be done, making this useful for factoring.
- */
-int is_definitely_prime(UV n)
-{
-  UV d, m;
-  unsigned char mtab;
-  const unsigned char* sieve;
-  int isprime;
-
-  if ( n < (NPRIME_IS_SMALL*8))
-    return ((prime_is_small[n/8] >> (n%8)) & 1);
-
-  d = n/30;
-  m = n - d*30;
-  mtab = masktab30[m];  /* Bitmask in mod30 wheel */
-
-  /* Return 0 if a multiple of 2, 3, or 5 */
-  if (mtab == 0)
-    return 0;
-
-  isprime = (n <= get_prime_cache(0, &sieve))
-            ?  ((sieve[d] & mtab) == 0)
-            :  -1;
-  release_prime_cache(sieve);
-  if (isprime >= 0)  return isprime;
-
-  if (n > MPU_PROB_PRIME_BEST)
-    return (_XS_is_prob_prime(n) == 2);
-
-  return 0;
-}
-
 
 static const unsigned char prime_next_small[] =
   {2,2,3,5,5,7,7,11,11,11,11,13,13,17,17,17,17,19,19,23,23,23,23,
diff --git a/util.h b/util.h
index 18f5568..4ab091f 100644
--- a/util.h
+++ b/util.h
@@ -7,7 +7,6 @@ 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);
 extern UV  _XS_next_prime(UV x);
 extern UV  _XS_prev_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

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to