11 ms·
Note that his last way does cos(acos(cosϕ))) after generating cosϕ uniformly. Which is a waste, you can just set sinϕ = sqrt(1-cosϕ^2). After fixing that, this
by improbable22 8y ago
Note that his last way does cos(acos(cosϕ))) after generating cosϕ uniformly. Which is a waste, you can just set sinϕ = sqrt(1-cosϕ^2).
After fixing that, this way is faster for me. Some trig, but no branches.
Edit: https://pastebin.com/UExZ5Siw https://pastebin.com/UExZ5Siw
- shpx 8y agoBut you used Julia. I'm almost certain that if you applied your optimization to the C code you'd find that it makes no difference because `gcc -O2` already made it.
- tgb 8y agoGcc collapses acos(cos(x)) to x on -O2? Surely not since this isn't even accurate for x outside of -pi to pi. That's ignoring floating point errors that make those two different which I thought was a different optimization flag, though I'm not sure about that.
- improbable22 8y agoWell, here it's cos(acos(x)) and sin(acos(x)), which are easier. But still that's pretty smart, I did not know this.
- ChrisRackauckas 8y agoJulia is usually ran with LLVM -O3. Is LLVM just missing that optimization then? This sounds like something the optimizer wouldn't due without fastmath flags enabled.