-
Notifications
You must be signed in to change notification settings - Fork 31
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
Move PRs from Base #8
Comments
Moved over here #9 |
Should we drop |
"Sizehint for primes" now #11 |
@mschauer I did some tests with your |
A |
Ok, I'll bring over my PR then |
I did some more experiments last week, and I'm not sure now which implementation should be chosen for |
+1 for the "naïve" approach. It also allows us to write a generic function for all types. The only optimization that needs testing to see if it helps a little, is to check every other integer for numbers > 2 or to use a small wheel, for example (not thoroughly tested) function nextprime(x)
x < 2 && return 2
x < 3 && return 3
d, r = divrem(x + 1, 6)
x = 6d + ifelse(r > 1, 5, 1)
Δ = ifelse(r > 1, 2, 4)
while(!isprime(x))
x += Δ
Δ = ifelse(Δ == 2, 4, 2)
end
return x
end but I'm not sure this would be of much benefit. |
And for function nextprime(x::BigInt)
x < 2 && return BigInt(2)
x < 3 && return BigInt(3)
a, b = BigInt(2), BigInt(4)
d, r = divrem(x + 1, 6)
x = 6d + ifelse(r > 1, 5, 1)
Δ = ifelse(r > 1, a, b)
while(!isprime(x))
ccall((:__gmpz_add,:libgmp), Void, (Ptr{BigInt}, Ptr{BigInt}, Ptr{BigInt}), &x, &x, &Δ)
Δ = ifelse(Δ == 2, b, a)
end
return x
end |
I have done experiments last week with something like this, but using directly your wheel implementation! (so using |
Yeah, I would have thought it won't help to use a wheel given that the cost of the wheel will be similar to the cost of discarding via |
Just kind of thinking aloud here, but something that may be kind of interesting would be to define a Dunno, maybe this makes no sense, just a thought. |
Makes totally sense, actually I had this on my todo, this is similar in functionality to the |
This can imho be closed, issue #55 keeps track of the prime iterator. |
The following PRs were never merged into Base, and so weren't copied over.
isprime
performance for 32-bit integers JuliaLang/julia#16349cc: @mschauer, @pabloferz
The text was updated successfully, but these errors were encountered: