Hacker News new | ask | show | jobs
by topaz0 1359 days ago
That's an obfuscation from the blog post. If you read further down in the code that is mentioned, the actual computation of sin is done by a polynomial expansion in x (radians), not y (turns). The purpose of y is mainly in case x is more than pi, and if so, what the corresponding angle in [0,pi/4) is.
1 comments

You can if you want make a polynomial in turns. The CPU isn’t going to care one way or the other.

Implementations which are accurate in terms of turns even for values close to half a turn can be useful for avoiding numerical issues that sometimes pop up because π is not exactly expressible as a floating point number. These functions usually names like sinpi, cospi, etc. It would be nice if they were provided more often in standard libraries.

Based on the article, CUDA has a sinpi instruction (or whatever they call them in CUDA-land). Does anyone know -- is sinpi commonly provided in the CPU assembly extension ecosystem (avx & friends)? Light googling showed me some APIs that had implementations, but I didn't dig in enough to see if they are directly implemented in assembly (this seems like the sort of info a wizard here would know about, and probably whether these types of instructions tend to be well-implemented...).