\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.022628612332283863:\\
\;\;\;\;\frac{{1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left({\left(\cos x\right)}^{3}\right)\right)}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}\\
\mathbf{elif}\;x \le 0.02286088640089938:\\
\;\;\;\;\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}:\\
\;\;\;\;\frac{{1}^{3} - \cos x \cdot {\left(\cos x\right)}^{2}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}\\
\end{array}double code(double x) {
return ((1.0 - cos(x)) / sin(x));
}
double code(double x) {
double temp;
if ((x <= -0.022628612332283863)) {
temp = ((pow(1.0, 3.0) - expm1(log1p(pow(cos(x), 3.0)))) / (fma(1.0, 1.0, fma(cos(x), cos(x), (1.0 * cos(x)))) * sin(x)));
} else {
double temp_1;
if ((x <= 0.02286088640089938)) {
temp_1 = fma(0.041666666666666664, pow(x, 3.0), fma(0.004166666666666667, pow(x, 5.0), (0.5 * x)));
} else {
temp_1 = ((pow(1.0, 3.0) - (cos(x) * pow(cos(x), 2.0))) / (fma(1.0, 1.0, fma(cos(x), cos(x), (1.0 * cos(x)))) * sin(x)));
}
temp = temp_1;
}
return temp;
}




Bits error versus x
Results
| Original | 30.0 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.022628612332283863Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied expm1-log1p-u1.1
if -0.022628612332283863 < x < 0.02286088640089938Initial program 59.9
Taylor expanded around 0 0.0
Simplified0.0
if 0.02286088640089938 < x Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied cube-mult1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2020065 +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)))