\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0195414650842071873:\\
\;\;\;\;\frac{1 - \cos x}{\sin x}\\
\mathbf{elif}\;x \le 0.023267676544555443:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{e}^{\left(\log \left(1 - \cos x\right)\right)}}{\sin x}\\
\end{array}double f(double x) {
double r50991 = 1.0;
double r50992 = x;
double r50993 = cos(r50992);
double r50994 = r50991 - r50993;
double r50995 = sin(r50992);
double r50996 = r50994 / r50995;
return r50996;
}
double f(double x) {
double r50997 = x;
double r50998 = -0.019541465084207187;
bool r50999 = r50997 <= r50998;
double r51000 = 1.0;
double r51001 = cos(r50997);
double r51002 = r51000 - r51001;
double r51003 = sin(r50997);
double r51004 = r51002 / r51003;
double r51005 = 0.023267676544555443;
bool r51006 = r50997 <= r51005;
double r51007 = 0.041666666666666664;
double r51008 = 3.0;
double r51009 = pow(r50997, r51008);
double r51010 = r51007 * r51009;
double r51011 = 0.004166666666666667;
double r51012 = 5.0;
double r51013 = pow(r50997, r51012);
double r51014 = r51011 * r51013;
double r51015 = 0.5;
double r51016 = r51015 * r50997;
double r51017 = r51014 + r51016;
double r51018 = r51010 + r51017;
double r51019 = exp(1.0);
double r51020 = log(r51002);
double r51021 = pow(r51019, r51020);
double r51022 = r51021 / r51003;
double r51023 = r51006 ? r51018 : r51022;
double r51024 = r50999 ? r51004 : r51023;
return r51024;
}




Bits error versus x
Results
| Original | 30.1 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.019541465084207187Initial program 0.9
rmApplied add-log-exp0.9
rmApplied rem-log-exp0.9
if -0.019541465084207187 < x < 0.023267676544555443Initial program 60.0
Taylor expanded around 0 0.0
if 0.023267676544555443 < x Initial program 0.9
rmApplied add-exp-log0.9
rmApplied pow10.9
Applied log-pow0.9
Applied exp-prod1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2020047
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))