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




Bits error versus x
Results
| Original | 30.2 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if x < -0.024280922068190693Initial program 0.9
rmApplied div-sub1.1
if -0.024280922068190693 < x < 0.02165047000055947Initial program 60.0
Taylor expanded around 0 0.0
if 0.02165047000055947 < x Initial program 0.9
rmApplied add-log-exp1.1
Applied add-log-exp1.1
Applied diff-log1.3
Simplified1.1
Final simplification0.6
herbie shell --seed 2020001
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))