\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.023228222164187143 \lor \neg \left(x \le 0.0219772417603219007\right):\\
\;\;\;\;\frac{1}{\sin x \cdot \frac{1}{1 - \cos 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.023228222164187143) || !(x <= 0.0219772417603219))) {
VAR = (1.0 / (sin(x) * (1.0 / (1.0 - cos(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.023228222164187143 or 0.0219772417603219 < x Initial program 0.9
rmApplied clear-num1.0
rmApplied div-inv1.0
if -0.023228222164187143 < x < 0.0219772417603219Initial program 60.0
Taylor expanded around 0 0.0
Simplified0.0
Final simplification0.5
herbie shell --seed 2020079 +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)))