Alt-Math-Prime-FastSieve-Inline

 view release on metacpan or  search on metacpan

lib/Math/Prime/FastSieve.pm  view on Meta::CPAN


=head3 isprime()
=head3 is_prime()

Pass a parameter consisiting of a single integer within the range of the
Sieve object.  Returns true if the integer is prime, false otherwise.
If the integer is out of the Sieve object's bounds, the result will be
false.

    if( $sieve->isprime(42) ) {
        say "42 is prime.";
    } else {
        say "42 isn't prime.";
    }

C<is_prime()> is a synonym for C<isprime()>.  They're the same method; I
just grew tired of forgetting which spelling to use when calling the
method.

This is an O(1) operation.


=head3 nearest_le()

lib/Math/Prime/FastSieve.pm  view on Meta::CPAN

the sieve, the results are cached for future calls to C<count_sieve()>.

This is an O(n) operation.


=head3 nth_prime()

This method returns the n-th prime, where C<$n> is the cardinal index in the
sequence of primes.  For example:

    say $sieve->nth_prime(1) # prints 2: the first prime is 2.
    say $sieve->nth_prime(3) # prints 5: the third prime is 5.

If there is no nth prime in the bounds of the sieve C<0> is returned.




=head1 Implementation Notes

The sieve is implemented as a bit sieve using a C++ vector<bool>.  All odd
integers from 3 to C<$n> are represented based on their index within the



( run in 0.631 second using v1.01-cache-2.11-cpan-483215c6ad5 )