Skip Menu |

This queue is for tickets about the Math-Prime-FastSieve CPAN distribution.

Report information
The Basics
Id: 81399
Status: resolved
Worked: 20 min
Priority: 0/
Queue: Math-Prime-FastSieve

People
Owner: davido [...] cpan.org
Requestors: sflitman [...] xenoscience.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.16
Fixed in: (no value)



Subject: count_sieve returns 1
my $sieve=Math::Prime::FastSieve->new( 5_000_000 ); my $num_found=$sieve->count_num(); # $num_found == 1, should be 348513
On Fri Nov 23 23:47:14 2012, sflitman wrote: Show quoted text
> my $sieve=Math::Prime::FastSieve->new( 5_000_000 ); > my $num_found=$sieve->count_num(); > # $num_found == 1, should be 348513 >
Thanks for your report. The tests contained in t/03sieve_object.t, lines 159-185 already test a fresh sieve of 5_000_000 and get 348_513, which is accurate. You may, indeed, be seeing an error. But the code you provided doesn't compile, so I don't know what needs to be done to reproduce the error. I tried this snippet, which seems to be exactly what your snippet of code intended to do (after fixing its two errors): my $sieve = Math::Prime::FastSieve::Sieve->new(); my $num_found = $sieve->count_sieve; print "$num_found\n"; # Prints 348513. If the snippet above doesn't produce 384513 for you, please provide more information on your system; Perl version, 32/64 bit, OS type, etc. Once you provide a test case that demonstrates the bug I'll work on it.
On Sat Nov 24 00:11:16 2012, DAVIDO wrote: Show quoted text
> > my $sieve = Math::Prime::FastSieve::Sieve->new(); > my $num_found = $sieve->count_sieve; > print "$num_found\n"; > # Prints 348513. >
....should be... my $sieve = Math::Prime::FastSieve::Sieve->new(5_000_000); # of course. ...The issue is still open; I haven't been able to reproduce the error.
On Sat Nov 24 02:47:14 2012, sflitman wrote: Show quoted text
> my $sieve=Math::Prime::FastSieve->new( 5_000_000 ); > my $num_found=$sieve->count_num(); > # $num_found == 1, should be 34851
sorry that should be count_sieve, not count_num This is odd, testing that function alone shows it works, but it fails when I tried to test it from the synopsis with the enclosed file. c:\> perl -MMath::Prime::FastSieve -e "my $sieve=Math::Prime::FastSieve::Sieve->new(5_000_000); print $sieve- Show quoted text
>count_sieve"
348513 That's what I get for typing instead of cut and paste! By the way, it doesn't fail for a sieve of 5_000_000_000 on my Core i7 laptop with 8G RAM, it reports 36500086 This module is a tour de force, and it ran on Windows 7 under Strawberry Perl no less. Thanks, you've really opened my eyes to what is possible with Inline::CPP! SSF
Subject: sieve.pl
#!/usr/bin/perl # SSF 112412 - test Math::Prime::FastSieve use Math::Prime::FastSieve; # Create a new sieve and flag all primes less or equal to n. my $sieve = Math::Prime::FastSieve::Sieve->new( 5_000_000 ); # Obtain a ref to an array containing all primes <= 5 Million. my $aref = $sieve->primes( 5_000_000 ); print "Number of primes up to 5,000,000: ",scalar @$aref,"\n"; # Obtain a ref to an array containing all primes >= 5, and <= 16. my $aref = $sieve->ranged_primes( 5, 16 ); print "Primes between 5 and 16: ",join(',',@$aref),"\n"; # Query the sieve: Is 17 prime? Return a true or false value. my $result = $sieve->isprime( 17 ); print "Is 17 prime: ",$result ? "Yes" : "No","\n"; # Get the value of the nearest prime less than or equal to 42. my $less_or_equal = $sieve->nearest_le( 42 ); print "Nearest prime less than or equal to 42: ",$less_or_equal,"\n"; # Get the value of the nearest prime greater than or equal to 42. my $greater_or_equal = $sieve->nearest_ge( 42 ); print "Nearest prime greater than or equal to 42: ",$greater_or_equal,"\n"; # Count how many primes exist within the sieve (ie, count all primes less # than or equal to 5 Million, assuming we instantiated the sieve with # Math::Prime::FastSieve::Sieve->new( 5_000_000 );. my $num_found = $sieve->count_sieve(); print "How many primes in sieve: ",$num_found,"\n"; # Count how many primes fall between 1 and 42 inclusive. my $quantity_le = $sieve->count_le( 42 ); print "How many primes fall between 1 and 42 inclusive: ",$quantity_le,"\n"; # Return the value of the 42nd prime number. my $forty_second_prime = $sieve->nth_prime( 42 ); print "The 42nd prime number is ",$forty_second_prime,"\n"; exit;
On Sat Nov 24 00:20:28 2012, sflitman wrote: Show quoted text
> On Sat Nov 24 02:47:14 2012, sflitman wrote:
> > my $sieve=Math::Prime::FastSieve->new( 5_000_000 ); > > my $num_found=$sieve->count_num(); > > # $num_found == 1, should be 34851
> > sorry that should be count_sieve, not count_num > > This is odd, testing that function alone shows it works, but it fails > when I tried to test it from the synopsis with the enclosed file. >
Thanks. That demonstrates it, and gives me something to work with in isolating it. It probably has something to do with how the module caches the sieve count so that count_sieve() can be O(1) once the sieve is built. One of the other actions must be clobbering it. I'll upload v0.17 with a fix before Monday.
The call to primes() was clobbering the cached sieve count. Remove one line, fix one bug. ;) This issue is resolved in v0.17, uploaded to CPAN on 11/24/2012.