\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0443112716287218308:\\
\;\;\;\;\frac{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right) \cdot \left(1 - \cos x\right)}{\mathsf{fma}\left(1, 1, \log \left({\left(e^{\cos x}\right)}^{\left(1 + \cos x\right)}\right)\right) \cdot \sin x}\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 0.002190375129707059:\\
\;\;\;\;\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 ((((1.0 - cos(x)) / sin(x)) <= -0.04431127162872183)) {
temp = ((fma(1.0, 1.0, (cos(x) * (cos(x) + 1.0))) * (1.0 - cos(x))) / (fma(1.0, 1.0, log(pow(exp(cos(x)), (1.0 + cos(x))))) * sin(x)));
} else {
double temp_1;
if ((((1.0 - cos(x)) / sin(x)) <= 0.002190375129707059)) {
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 | 29.7 |
|---|---|
| Target | 0.0 |
| Herbie | 1.0 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.04431127162872183Initial program 0.7
rmApplied flip3--0.8
Applied associate-/l/0.8
Simplified0.8
rmApplied difference-cubes0.8
Simplified0.8
rmApplied add-log-exp0.9
Simplified0.9
if -0.04431127162872183 < (/ (- 1.0 (cos x)) (sin x)) < 0.002190375129707059Initial program 59.1
Taylor expanded around 0 0.9
Simplified0.9
if 0.002190375129707059 < (/ (- 1.0 (cos x)) (sin x)) Initial program 0.9
rmApplied *-un-lft-identity0.9
Applied add-sqr-sqrt1.1
Applied times-frac1.1
Simplified1.1
Final simplification1.0
herbie shell --seed 2020049 +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)))