\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0205416709720201603 \lor \neg \left(x \le 0.0230298891429468987\right):\\
\;\;\;\;\frac{1 - \cos x}{\sin x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{24}, {x}^{3}, \mathsf{fma}\left(\frac{1}{240}, {x}^{5}, \frac{1}{2} \cdot x\right)\right)\\
\end{array}double code(double x) {
return ((1.0 - cos(x)) / sin(x));
}
double code(double x) {
double VAR;
if (((x <= -0.02054167097202016) || !(x <= 0.0230298891429469))) {
VAR = ((1.0 - cos(x)) / sin(x));
} else {
VAR = fma(0.041666666666666664, pow(x, 3.0), fma(0.004166666666666667, pow(x, 5.0), (0.5 * x)));
}
return VAR;
}




Bits error versus x
Results
| Original | 30.3 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.02054167097202016 or 0.0230298891429469 < x Initial program 0.9
if -0.02054167097202016 < x < 0.0230298891429469Initial program 59.9
Taylor expanded around 0 0.0
Simplified0.0
Final simplification0.5
herbie shell --seed 2020071 +o rules:numerics
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))