\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0206102587514720333:\\
\;\;\;\;\frac{1}{\frac{1}{\frac{1 - \cos x}{\sin x}}}\\
\mathbf{elif}\;x \le 0.021098151530649319:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{24}, {x}^{3}, \mathsf{fma}\left(\frac{1}{240}, {x}^{5}, \frac{1}{2} \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\sin x}}{\frac{1}{1 - \cos x}}\\
\end{array}double code(double x) {
return ((1.0 - cos(x)) / sin(x));
}
double code(double x) {
double VAR;
if ((x <= -0.020610258751472033)) {
VAR = (1.0 / (1.0 / ((1.0 - cos(x)) / sin(x))));
} else {
double VAR_1;
if ((x <= 0.02109815153064932)) {
VAR_1 = fma(0.041666666666666664, pow(x, 3.0), fma(0.004166666666666667, pow(x, 5.0), (0.5 * x)));
} else {
VAR_1 = ((1.0 / sin(x)) / (1.0 / (1.0 - cos(x))));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus x
Results
| Original | 30.0 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.020610258751472033Initial program 0.9
rmApplied clear-num1.0
rmApplied clear-num1.0
if -0.020610258751472033 < x < 0.02109815153064932Initial program 59.8
Taylor expanded around 0 0.0
Simplified0.0
if 0.02109815153064932 < x Initial program 0.9
rmApplied clear-num1.0
rmApplied div-inv1.0
Applied associate-/r*1.0
Final simplification0.5
herbie shell --seed 2020078 +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)))