\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.024260903871319413:\\
\;\;\;\;\frac{e^{\log \left(\log \left(e^{1 - \cos x}\right)\right)}}{\sin x}\\
\mathbf{elif}\;x \le 0.0222724579727386039:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + x \cdot \frac{1}{2}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - \cos x\right) \cdot \frac{1}{\sin x}\\
\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.024260903871319413)) {
VAR = ((double) (((double) exp(((double) log(((double) log(((double) exp(((double) (1.0 - ((double) cos(x)))))))))))) / ((double) sin(x))));
} else {
double VAR_1;
if ((x <= 0.022272457972738604)) {
VAR_1 = ((double) (((double) (0.041666666666666664 * ((double) pow(x, 3.0)))) + ((double) (((double) (0.004166666666666667 * ((double) pow(x, 5.0)))) + ((double) (x * 0.5))))));
} else {
VAR_1 = ((double) (((double) (1.0 - ((double) cos(x)))) * ((double) (1.0 / ((double) sin(x))))));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus x
Results
| Original | 30.4 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.024260903871319413Initial program 0.9
rmApplied add-exp-log0.9
rmApplied add-log-exp1.1
Applied add-log-exp1.1
Applied diff-log1.3
Simplified1.1
if -0.024260903871319413 < x < 0.0222724579727386039Initial program 59.9
Taylor expanded around 0 0.0
Simplified0.0
if 0.0222724579727386039 < x Initial program 0.9
rmApplied div-inv1.0
Final simplification0.5
herbie shell --seed 2020179
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2.0))
(/ (- 1.0 (cos x)) (sin x)))