1
$\begingroup$

What formula is used to calculate sine in modern computers?

Is Taylor formula

enter image description here

the best? What formulas converge faster, especially out of $2\pi$ range?

  • 0
    relevant stackoverflow question: [link](http://stackoverflow.com/questions/2284860/how-does-c-compute-sin-and-other-math-functions) most notable is the following assertion: "This code is very complex. No one software algorithm is as fast as possible and also accurate over the whole range of x values, so the library implements many different algorithms and its first job is to look at x and decide which algorithm to use"2017-01-24
  • 0
    Why don't you substract the appropriate number of times $2\pi$ to have $x$ in the range $(-\pi,\,\pi)$ ? Or even slightly more efficient, use relations $\sin(x-\frac\pi2)=\cos x$ and use the sine and cosine series for $x$ in the range $(-\frac\pi2,\,\frac\pi2)$.2017-01-24
  • 0
    @Dims: You might want to narrow the question to a specific precision. For IEEE-754 single precision and double precision, the approach is pretty much always argument reduction to a narrow interval (e.g. $( -\frac{\pi}{4}, \frac{\pi}{4}$), on which a polynomial *minimax approximation* is used. [Worked example](https://devtalk.nvidia.com/default/topic/960757/a-faster-and-more-accurate-implementation-of-sincosf-/)2017-01-25

2 Answers 2

3

There is not one formula. The best known method relies on the values of $\sin 1$, $\sin 0.1$, $\sin 10^{-2}$, $\dots,\sin 10^{-k}$, $\dots,\;$ for a small number of values of $k$, which can easily be calculated with Taylor's formula at any degree of accuracy.

Then the CORDIC algorithm can compute from these data the sine of any real number.

1

I don't think the chip-makers publish their microcode, but they almost certainly don't use Taylor series. It's more likely that they use either a CORDIC algorithm or an optimized polynomial approximation on some interval.

  • 0
    Usually Pade-Chebyshov rational approximation.2017-01-24
  • 0
    Not necessarily. Remez algorithm may produce better results.2017-01-24