\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.023427378097045405:\\
\;\;\;\;\frac{\log \left(e^{1 - \cos x}\right)}{\sin x}\\
\mathbf{elif}\;x \le 0.023613340017627771:\\
\;\;\;\;\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{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, \log \left(e^{1 + \cos x}\right), 1 \cdot 1\right)}}{\sin x}\\
\end{array}double code(double x) {
return ((1.0 - cos(x)) / sin(x));
}
double code(double x) {
double VAR;
if ((x <= -0.023427378097045405)) {
VAR = (log(exp((1.0 - cos(x)))) / sin(x));
} else {
double VAR_1;
if ((x <= 0.02361334001762777)) {
VAR_1 = fma(0.041666666666666664, pow(x, 3.0), fma(0.004166666666666667, pow(x, 5.0), (0.5 * x)));
} else {
VAR_1 = (((pow(1.0, 3.0) - pow(cos(x), 3.0)) / fma(cos(x), log(exp((1.0 + cos(x)))), (1.0 * 1.0))) / sin(x));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus x
Results
| Original | 30.5 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.023427378097045405Initial program 0.9
rmApplied add-log-exp1.1
Applied add-log-exp1.1
Applied diff-log1.3
Simplified1.1
if -0.023427378097045405 < x < 0.02361334001762777Initial program 59.8
Taylor expanded around 0 0.0
Simplified0.0
if 0.02361334001762777 < x Initial program 0.9
rmApplied flip3--1.0
Simplified1.0
rmApplied add-log-exp1.0
Applied add-log-exp1.0
Applied sum-log1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2020092 +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)))