\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0236105927013185481:\\
\;\;\;\;\frac{1}{\sin x} - \frac{\cos x}{\sin x}\\
\mathbf{elif}\;x \le 0.0199371016091038876:\\
\;\;\;\;\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}:\\
\;\;\;\;\log \left(e^{\frac{1}{\frac{\sin x}{1 - \cos x}}}\right)\\
\end{array}double code(double x) {
return ((1.0 - cos(x)) / sin(x));
}
double code(double x) {
double temp;
if ((x <= -0.023610592701318548)) {
temp = ((1.0 / sin(x)) - (cos(x) / sin(x)));
} else {
double temp_1;
if ((x <= 0.019937101609103888)) {
temp_1 = fma(0.041666666666666664, pow(x, 3.0), fma(0.004166666666666667, pow(x, 5.0), (0.5 * x)));
} else {
temp_1 = log(exp((1.0 / (sin(x) / (1.0 - cos(x))))));
}
temp = temp_1;
}
return temp;
}




Bits error versus x
Results
| Original | 30.1 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.023610592701318548Initial program 0.9
rmApplied div-sub1.1
if -0.023610592701318548 < x < 0.019937101609103888Initial program 59.7
Taylor expanded around 0 0.0
Simplified0.0
if 0.019937101609103888 < x Initial program 0.8
rmApplied add-log-exp0.9
rmApplied clear-num1.0
Final simplification0.5
herbie shell --seed 2020057 +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)))