\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.01466625826063921:\\
\;\;\;\;\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 4.07947959306614603 \cdot 10^{-7}:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\\
\end{array}double code(double x) {
return ((1.0 - cos(x)) / sin(x));
}
double code(double x) {
double VAR;
if ((((1.0 - cos(x)) / sin(x)) <= -0.01466625826063921)) {
VAR = log(exp(((1.0 - cos(x)) / sin(x))));
} else {
double VAR_1;
if ((((1.0 - cos(x)) / sin(x)) <= 4.079479593066146e-07)) {
VAR_1 = ((0.041666666666666664 * pow(x, 3.0)) + ((0.004166666666666667 * pow(x, 5.0)) + (0.5 * x)));
} else {
VAR_1 = ((pow(1.0, 3.0) - pow(cos(x), 3.0)) / (((cos(x) * (cos(x) + 1.0)) + (1.0 * 1.0)) * sin(x)));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus x
Results
| Original | 30.2 |
|---|---|
| Target | 0.0 |
| Herbie | 0.7 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.01466625826063921Initial program 0.9
rmApplied add-log-exp1.0
if -0.01466625826063921 < (/ (- 1.0 (cos x)) (sin x)) < 4.079479593066146e-07Initial program 59.8
Taylor expanded around 0 0.3
if 4.079479593066146e-07 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.2
rmApplied flip3--1.3
Applied associate-/l/1.3
Simplified1.3
Final simplification0.7
herbie shell --seed 2020105
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))