Useless Snippet #4: Basic trigonometry (sin/cos)
Thursday, December 15th, 2011Goal: Calculate the sin/cos of an arbitrary angle.
Restrictions:
- Should be faster than CRT’s sin/cos and faster than FPU’s fsin/fcos
- The error should be kept to a minimum compared to the above functions
- Double precision is required
- Function should be in the form: double func(double), ie. no xmm regs passed to the function, result should be returned on the FPU stack and it should calculate only 1 angle at a time
For the rest of the post we’ll be talking about sin(). Calculating cos(), or even sincos() should be easily derived from the code below. The required changes will be described at the end of the post.
(more…)