\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0245372772323286699:\\
\;\;\;\;\frac{1}{\sin x} - \frac{\cos x}{\sin x}\\
\mathbf{elif}\;x \le 0.0201005584172496386:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sin x \cdot \frac{1}{1 - \cos x}}\\
\end{array}double code(double x) {
return ((1.0 - cos(x)) / sin(x));
}
double code(double x) {
double VAR;
if ((x <= -0.02453727723232867)) {
VAR = ((1.0 / sin(x)) - (cos(x) / sin(x)));
} else {
double VAR_1;
if ((x <= 0.02010055841724964)) {
VAR_1 = ((0.041666666666666664 * pow(x, 3.0)) + ((0.004166666666666667 * pow(x, 5.0)) + (0.5 * x)));
} else {
VAR_1 = (1.0 / (sin(x) * (1.0 / (1.0 - cos(x)))));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus x
Results
| Original | 30.3 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.02453727723232867Initial program 0.9
rmApplied div-sub1.2
if -0.02453727723232867 < x < 0.02010055841724964Initial program 59.8
Taylor expanded around 0 0.0
if 0.02010055841724964 < x Initial program 0.9
rmApplied clear-num1.0
rmApplied div-inv1.0
Final simplification0.5
herbie shell --seed 2020100
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))