\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0107629324502667868:\\
\;\;\;\;\frac{\frac{{1}^{3}}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1} - \frac{{\left(\cos x\right)}^{3}}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{\sin x}\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 4.3298603204685633 \cdot 10^{-4}:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\sqrt{e^{\frac{1 - \cos x}{\sin x}}} \cdot \sqrt{e^{\frac{1 - \cos x}{\sin x}}}\right)\\
\end{array}double code(double x) {
return ((1.0 - cos(x)) / sin(x));
}
double code(double x) {
double temp;
if ((((1.0 - cos(x)) / sin(x)) <= -0.010762932450266787)) {
temp = (((pow(1.0, 3.0) / ((cos(x) * (cos(x) + 1.0)) + (1.0 * 1.0))) - (pow(cos(x), 3.0) / ((cos(x) * (cos(x) + 1.0)) + (1.0 * 1.0)))) / sin(x));
} else {
double temp_1;
if ((((1.0 - cos(x)) / sin(x)) <= 0.00043298603204685633)) {
temp_1 = ((0.041666666666666664 * pow(x, 3.0)) + ((0.004166666666666667 * pow(x, 5.0)) + (0.5 * x)));
} else {
temp_1 = log((sqrt(exp(((1.0 - cos(x)) / sin(x)))) * sqrt(exp(((1.0 - cos(x)) / sin(x))))));
}
temp = temp_1;
}
return temp;
}




Bits error versus x
Results
| Original | 30.1 |
|---|---|
| Target | 0.0 |
| Herbie | 0.7 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.010762932450266787Initial program 0.9
rmApplied flip3--1.0
Simplified1.0
rmApplied div-sub1.0
if -0.010762932450266787 < (/ (- 1.0 (cos x)) (sin x)) < 0.00043298603204685633Initial program 59.8
Taylor expanded around 0 0.3
if 0.00043298603204685633 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.0
rmApplied add-log-exp1.0
rmApplied add-sqr-sqrt1.3
Final simplification0.7
herbie shell --seed 2020056
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))