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 e3def2d1867c8e81183c0b0d9af48267aacee352
Author: Dana Jacobsen <d...@acm.org>
Date:   Wed Dec 25 01:31:53 2013 -0800

    Fix _XS_legendre_phi for new table phi
---
 lehmer.c          |  6 +++---
 xt/legendre_phi.t | 28 ++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/lehmer.c b/lehmer.c
index c4d0a59..725ed4a 100644
--- a/lehmer.c
+++ b/lehmer.c
@@ -863,14 +863,14 @@ static const unsigned char primes_small[] =
 #define NPRIMES_SMALL (sizeof(primes_small)/sizeof(primes_small[0]))
 
 UV _XS_legendre_phi(UV x, UV a) {
+  phitableinit();
   /* For small values, calculate directly */
   if (a <= PHIC) return tablephi(x, a);
   /* For large values, do our non-recursive phi */
-  if (a > NPRIMES_SMALL) return phi(x,a);
+  if (a >= NPRIMES_SMALL) return phi(x,a);
   /* Otherwise, recurse */
   {
-    UV i;
-    UV sum = tablephi(x, PHIC);
+    UV i, sum = tablephi(x, PHIC);
     for (i = PHIC+1; i <= a; i++) {
       uint32_t p = primes_small[i];
       UV xp = x/p;
diff --git a/xt/legendre_phi.t b/xt/legendre_phi.t
new file mode 100644
index 0000000..a887984
--- /dev/null
+++ b/xt/legendre_phi.t
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+use Test::More;
+use Math::Prime::Util qw/nth_prime prime_count/;
+
+my $x = shift || 50000;
+
+my $sqrtx = int(sqrt($x));
+my $pcx = prime_count($x);
+my $pcsqrtx = prime_count($sqrtx);
+
+my @a = 1 .. $x;
+
+foreach my $a (0 .. $sqrtx+1) {
+  if ($a > 0) {
+    my $p = nth_prime($a);
+    @a = grep { $_ % $p } @a;
+  }
+  my $expect = scalar @a;
+  if ($a > $pcsqrtx) {
+    is ( $expect, $pcx - $a + 1, "sieved phi($x,$a) = Pi($x) - $a + 1" );
+  }
+  my $phixa = Math::Prime::Util::_XS_legendre_phi($x, $a);
+  is( $phixa, $expect, "Legendre phi($x,$a) = $expect" );
+}
+done_testing();

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