\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02286110756387238 \lor \neg \left(x \le 0.0220157720715043366\right):\\
\;\;\;\;\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\end{array}double code(double x) {
return ((double) (((double) (1.0 - ((double) cos(x)))) / ((double) sin(x))));
}
double code(double x) {
double VAR;
if (((x <= -0.022861107563872385) || !(x <= 0.022015772071504337))) {
VAR = ((double) log(((double) exp(((double) (((double) (1.0 - ((double) cos(x)))) / ((double) sin(x))))))));
} else {
VAR = ((double) (((double) (0.041666666666666664 * ((double) pow(x, 3.0)))) + ((double) (((double) (0.004166666666666667 * ((double) pow(x, 5.0)))) + ((double) (0.5 * x))))));
}
return VAR;
}




Bits error versus x
Results
| Original | 29.9 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.02286110756387238 or 0.0220157720715043366 < x Initial program 0.9
rmApplied add-log-exp1.0
if -0.02286110756387238 < x < 0.0220157720715043366Initial program 59.8
Taylor expanded around 0 0.0
Final simplification0.5
herbie shell --seed 2020171
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2.0))
(/ (- 1.0 (cos x)) (sin x)))