diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2000-12-15 15:32:22 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2000-12-15 15:32:22 +0000 |
commit | 1725693fac4322554ed5d17f384f2502ef67bf23 (patch) | |
tree | 0127e8a978e18c11dd1f14627bce770b9b3ba369 /lib/Tie | |
parent | d86ca223b7bea516175c99c61fc271cc462a2de7 (diff) | |
download | perl-1725693fac4322554ed5d17f384f2502ef67bf23.tar.gz |
Still buggy findgteprime, fix from Eric Joanis <joanis@cs.toronto.edu>.
p4raw-id: //depot/perl@8128
Diffstat (limited to 'lib/Tie')
-rw-r--r-- | lib/Tie/SubstrHash.pm | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/Tie/SubstrHash.pm b/lib/Tie/SubstrHash.pm index 3b92bd1cee..afe5d8dc25 100644 --- a/lib/Tie/SubstrHash.pm +++ b/lib/Tie/SubstrHash.pm @@ -186,19 +186,21 @@ sub ceil { sub findgteprime { # find the smallest prime integer greater than or equal to use integer; +# It may be sufficient (and more efficient, IF IT IS CORRECT) to use +# $max = 1 + int sqrt $num and calculate it once only, but is it correct? + my $num = ceil(shift); return 2 if $num <= 2; $num++ unless $num % 2; - my $max = int sqrt $num; - NUM: for (;; $num += 2) { - for ($i = 3; $i <= $max; $i += 2) { - next NUM unless $num % $i; - } - return $num; + my $max = int sqrt $num; + for ($i = 3; $i <= $max; $i += 2) { + next NUM unless $num % $i; + } + return $num; } } |