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 396279fbeb61714944c202968ffd3bc5aee23d00
Author: Dana Jacobsen <d...@acm.org>
Date:   Mon Oct 14 13:21:15 2013 -0700

    Update iterator object value_to_i*
---
 TODO                                 |  2 --
 lib/Math/Prime/Util/PrimeIterator.pm | 34 +++++++++++++++++++++++++++-------
 t/32-iterators.t                     |  7 ++++---
 3 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/TODO b/TODO
index 4dd824b..23dd043 100644
--- a/TODO
+++ b/TODO
@@ -40,8 +40,6 @@
 
 - Use Montgomery routines in more places: Factoring.
 
-- More tests for PrimeIterator.
-
 - Put euler_phi and moebius directly in XS.
     (1) optional second argument.  Easily handled, and not hard to do in
         generic sub call.
diff --git a/lib/Math/Prime/Util/PrimeIterator.pm 
b/lib/Math/Prime/Util/PrimeIterator.pm
index 7aa20f9..f5ab634 100644
--- a/lib/Math/Prime/Util/PrimeIterator.pm
+++ b/lib/Math/Prime/Util/PrimeIterator.pm
@@ -12,7 +12,7 @@ our @EXPORT_OK = qw( );
 our %EXPORT_TAGS = (all => [ @EXPORT_OK ]);
 
 
-use Math::Prime::Util qw/next_prime prev_prime/;
+use Math::Prime::Util qw/next_prime prev_prime is_prime prime_count nth_prime/;
 use Math::BigInt try => "GMP,Pari";
 
 my $bigprime = Math::BigInt->new(
@@ -65,19 +65,19 @@ sub rewind {
 # Some methods to match Math::NumSeq
 sub tell_i {
   my $self = shift;
-  return Math::Prime::Util::prime_count($self->{p});
+  return prime_count($self->{p});
 }
 sub pred {
   my($self, $n) = @_;
-  return Math::Prime::Util::is_prime($n);
+  return is_prime($n);
 }
 sub ith {
   my($self, $n) = @_;
-  return Math::Prime::Util::nth_prime($n);
+  return nth_prime($n);
 }
 sub seek_to_i {
   my($self, $n) = @_;
-  $self->rewind( Math::Prime::Util::nth_prime($n) );
+  $self->rewind( nth_prime($n) );
 }
 sub seek_to_value {
   my($self, $n) = @_;
@@ -85,7 +85,16 @@ sub seek_to_value {
 }
 sub value_to_i {
   my($self, $n) = @_;
-  return Math::Prime::Util::prime_count($n);
+  return unless is_prime($n);
+  return prime_count($n);
+}
+sub value_to_i_ceil {
+  my($self, $n) = @_;
+  return prime_count(next_prime($n-1));
+}
+sub value_to_i_floor {
+  my($self, $n) = @_;
+  return prime_count($n);
 }
 sub value_to_i_estimate {
   my($self, $n) = @_;
@@ -216,7 +225,18 @@ Math::NumSeq::Primes returns 4708661.
 
 =head2 value_to_i
 
-Returns the index corresponding to the argument.
+If the argument is prime, then returns the index.  In this case:
+
+  ith( value_to_i( $n ) ) == $n
+
+Returns C<undef> if the argument is not prime.
+
+=head2 value_to_i_floor
+
+=head2 value_to_i_ceil
+
+Returns the index corresponding to the first prime less than or equal
+to the argument, or greater than or equal to the argument, respectively.
 
 =head2 seek_to_i
 
diff --git a/t/32-iterators.t b/t/32-iterators.t
index b7fc19c..c16440f 100644
--- a/t/32-iterators.t
+++ b/t/32-iterators.t
@@ -14,7 +14,7 @@ plan tests => 8 + 5
             + 3 + 7
             + 2
             + 3 + 7
-            + 22
+            + 25
             + 0;
 
 ok(!eval { forprimes { 1 } undef; },   "forprimes undef");
@@ -174,8 +174,9 @@ ok(!eval { prime_iterator_object(4.5); }, "iterator 4.5");
   is( $it->ith(589), 4289, "iterator object ith returns nth prime");
   ok( $it->pred(577), "iterator object pred returns true if is_prime");
   is( $it->value_to_i(4289), 589, "iterator object value_to_i works");
-  # missing: value_to_i_ceil
-  # missing: value_to_i_floor
+  is( $it->value_to_i(4290), undef, "iterator object value_to_i for non-prime 
returns undef");
+  is( $it->value_to_i_floor(4290), 589, "iterator object value_to_i_floor");
+  is( $it->value_to_i_ceil(4290), 590, "iterator object value_to_i_ceil");
   my $est = $it->value_to_i_estimate( 4171510507 );
   my $act = 197710788;
   # We will get an estimate that is much, much closer than Math::NumSeq

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