5

Possible Duplicate:
How does C compute sin() and other math functions?

I'm curious how sin and cos the are implemented on a low level.

I just had a look inside the math.h and couldn't find the declaration for sin and cos. But since this was a dead end to me, I'm turning to you, SO.

I would like to know how many operations it takes to calculate a sine and what tricks are used for speed-up. Are they implemented differently on different hardware and are there processors that support this as a native instruction? How fast are they compared to an addition, for example?

Thanks!

Community
  • 1
  • 1
devsnd
  • 7,382
  • 3
  • 42
  • 50
  • http://stackoverflow.com/questions/2284860/how-does-c-compute-sin-and-other-math-functions – Sridhar Aug 22 '12 at 13:27
  • 1
    See also: http://stackoverflow.com/questions/345085/how-do-trigonometric-functions-work/345117#345117 – tenfour Aug 22 '12 at 13:27
  • Thanks for the comments, I must have used the wrong terms to find an answer before! – devsnd Aug 22 '12 at 13:30
  • 1
    This is near impossible to answer in total. Generally, the answer would be Taylor, and roughly as much as ~200-300 additions, but this can greatly vary depending on platform and required precision (imagine a lookup table, for example). I've seen implementations that run in ~24 cycles on x86_64 with 99% the same precision as reference. – Damon Aug 22 '12 at 13:30

0 Answers0