6
$\begingroup$

I cannot remember where I picked this up, but during my time reading about polynomial approximation for floating-point arithmetic of sin(x), I vaguely remember that there is an extra step in argument reduction. Specifically, it seems to involve "constructing a polynomial approximation for sin(x)/x instead", as "floating-point numbers are much denser closer to zero".

Is that true? I am in a bit of a stumble since I cannot quite pin down the precise statement to perform a Google search. Any comments/suggestions?

$\endgroup$
1
  • 4
    $\begingroup$ Inside math libraries $\sin(x)$ is commonly computed as a minimax approximation of the form $x + x^{3}P(x^{2})$, where $P$ is a polynomial. This is numerically advantageous. $\endgroup$
    – njuffa
    Dec 14, 2021 at 0:59

1 Answer 1

8
$\begingroup$

The sine is an odd function, so you want that also in an approximation. A polynomial with $p(0)=0$ can be factored as $p(x)=xq(x)$, so $q(x)\approx \frac{\sin(x)}{x}$.

Each interval $[2^n,2^{n+1})$ contains as many floating point numbers as $[1,2)$. For negative $n$ these intervals concentrate around zero, the density of them around zero is so indeed much larger than anywhere else. ($n$ has to remain in the exponent range, and then there are additionally the denormal numbers.)

The proper question to ask is how the error of the polynomial approximation is measured. One could minimize $\sup_{x\in I}|xq(x)-\sin(x)|$ or $\sup_{x\in I}|q(x)-\sin(x)/x|$ for some interval $I$, getting slightly different coefficients. Using trigonometric symmetries and a corresponding cosine approximation, $I=[0,\frac\pi4]$ should be sufficient.

$\endgroup$
3
  • 10
    $\begingroup$ The denormals aren't a problem for sin(x) though, because sin(x)=x exactly for denormals. The reason is simple: sin(x)=x+O(x^3), and denormals are already in the range (0, 2^minExp). $\endgroup$
    – MSalters
    Dec 13, 2021 at 13:51
  • 3
    $\begingroup$ Indeed, the sin(x)=x approximation doesn't start breaking down until about 2e-8. $\endgroup$
    – dan04
    Dec 13, 2021 at 21:26
  • 2
    $\begingroup$ My notes say: For IEEE-754 binary64, $\sin(x) = x$ for $|x| \leq 2.1491193328908210 \cdot 10^{-8}$, $\cos(x) = 1$ for $|x| \leq 1.0536712127723507 \cdot 10^{-8}$ $\endgroup$
    – njuffa
    Dec 14, 2021 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.