\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0221624842952990557:\\
\;\;\;\;\frac{e^{\sqrt[3]{{\left(\log \left(1 - \cos x\right)\right)}^{2}} \cdot \sqrt[3]{\log \left(1 - \cos x\right)}}}{\sin x}\\
\mathbf{elif}\;x \le 0.0226084732357230804:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + x \cdot \frac{1}{2}\right)\\
\mathbf{else}:\\
\;\;\;\;{e}^{\left(\log \left(1 - \cos x\right)\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.022162484295299056)) {
VAR = ((double) (((double) exp(((double) (((double) cbrt(((double) pow(((double) log(((double) (1.0 - ((double) cos(x)))))), 2.0)))) * ((double) cbrt(((double) log(((double) (1.0 - ((double) cos(x)))))))))))) / ((double) sin(x))));
} else {
double VAR_1;
if ((x <= 0.02260847323572308)) {
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) pow(((double) M_E), ((double) log(((double) (1.0 - ((double) cos(x)))))))) * ((double) (1.0 / ((double) sin(x))))));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus x
Results
| Original | 29.5 |
|---|---|
| Target | 0 |
| Herbie | 0.6 |
if x < -0.0221624842952990557Initial program 0.9
rmApplied add-exp-log0.9
rmApplied add-cbrt-cube1.1
Simplified1.1
rmApplied add-cube-cbrt1.4
Applied unpow-prod-down1.4
Applied cbrt-prod1.5
Simplified1.2
Simplified1.2
if -0.0221624842952990557 < x < 0.0226084732357230804Initial program 59.9
Taylor expanded around 0 0.0
Simplified0.0
if 0.0226084732357230804 < x Initial program 0.9
rmApplied add-exp-log0.9
rmApplied pow10.9
Applied log-pow0.9
Applied exp-prod1.0
Simplified1.0
rmApplied div-inv1.0
Final simplification0.6
herbie shell --seed 2020185
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2.0))
(/ (- 1.0 (cos x)) (sin x)))