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




Bits error versus x
Results
| Original | 30.5 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if x < -0.02298023060372375Initial program 1.0
rmApplied add-exp-log1.0
rmApplied flip3--1.1
Applied log-div1.1
if -0.02298023060372375 < x < 0.018602392475598327Initial program 59.9
Taylor expanded around 0 0.0
Simplified0.0
if 0.018602392475598327 < x Initial program 0.9
rmApplied add-exp-log0.9
rmApplied pow10.9
Applied log-pow0.9
Applied exp-prod1.0
Simplified1.0
rmApplied *-un-lft-identity1.0
Applied add-sqr-sqrt1.2
Applied times-frac1.1
Simplified1.1
Simplified1.1
Final simplification0.6
herbie shell --seed 2020058 +o rules:numerics
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))