Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update Primes.jl #86

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Primes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ primesmask(n::Integer) = n ≤ typemax(Int) ? primesmask(Int(n)) :
Returns a collection of the prime numbers (from `lo`, if specified) up to `hi`.
"""
function primes(lo::Int, hi::Int)
if hi<1
list=Int[]
else
lo ≤ hi || throw(ArgumentError("The condition lo ≤ hi must be met."))
list = Int[]
lo ≤ 2 ≤ hi && push!(list, 2)
Expand All @@ -125,9 +128,10 @@ function primes(lo::Int, hi::Int)
@inbounds for i = 1:length(sieve) # don't use eachindex here
sieve[i] && push!(list, wheel_prime(i + lwi))
end
end
return list
end
primes(n::Int) = primes(1, n)
primes(n::Int) = primes(0, n)

const PRIMES = primes(2^16)

Expand Down