diff --git a/src/Primes.jl b/src/Primes.jl index fa9a916..1241201 100644 --- a/src/Primes.jl +++ b/src/Primes.jl @@ -108,7 +108,7 @@ function primes(lo::Int, hi::Int) lo ≤ 3 ≤ hi && push!(list, 3) lo ≤ 5 ≤ hi && push!(list, 5) hi < 7 && return list - sizehint!(list, floor(Int, hi / log(hi))) + sizehint!(list, 5 + floor(Int, hi / (log(hi) - 1.12) - lo / (log(max(lo,2)) - 1.12*(lo > 7))) ) # http://projecteuclid.org/euclid.rmjm/1181070157 sieve = _primesmask(max(7, lo), hi) lwi = wheel_index(lo - 1) @inbounds for i = 1:length(sieve) # don't use eachindex here diff --git a/test/runtests.jl b/test/runtests.jl index 3fbf83f..ae0f7c5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -182,6 +182,10 @@ for n = 1:100 @test n == m end +let i = rand(1:2^(3*min(WORD_SIZE,64)÷4)) + @test primes(i,i+300) == filter(isprime, i:i + 300) == filter(isprime, big(i:i + 300)) +end + @test isprime(BigInt(1000000007)) @test isprime(BigInt(1000000007), 1)