\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02270927157581989139223388463051378494129:\\
\;\;\;\;\log \left(e^{\frac{\log \left(e^{1 - \cos x}\right)}{\sin x}}\right)\\
\mathbf{elif}\;x \le 0.01743449574326636983268024039261945290491:\\
\;\;\;\;\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}{\sin x} - \frac{\cos x}{\sin x}\\
\end{array}double f(double x) {
double r59982 = 1.0;
double r59983 = x;
double r59984 = cos(r59983);
double r59985 = r59982 - r59984;
double r59986 = sin(r59983);
double r59987 = r59985 / r59986;
return r59987;
}
double f(double x) {
double r59988 = x;
double r59989 = -0.02270927157581989;
bool r59990 = r59988 <= r59989;
double r59991 = 1.0;
double r59992 = cos(r59988);
double r59993 = r59991 - r59992;
double r59994 = exp(r59993);
double r59995 = log(r59994);
double r59996 = sin(r59988);
double r59997 = r59995 / r59996;
double r59998 = exp(r59997);
double r59999 = log(r59998);
double r60000 = 0.01743449574326637;
bool r60001 = r59988 <= r60000;
double r60002 = 0.041666666666666664;
double r60003 = 3.0;
double r60004 = pow(r59988, r60003);
double r60005 = 0.004166666666666667;
double r60006 = 5.0;
double r60007 = pow(r59988, r60006);
double r60008 = 0.5;
double r60009 = r60008 * r59988;
double r60010 = fma(r60005, r60007, r60009);
double r60011 = fma(r60002, r60004, r60010);
double r60012 = r59991 / r59996;
double r60013 = r59992 / r59996;
double r60014 = r60012 - r60013;
double r60015 = r60001 ? r60011 : r60014;
double r60016 = r59990 ? r59999 : r60015;
return r60016;
}




Bits error versus x
| Original | 30.1 |
|---|---|
| Target | 0 |
| Herbie | 0.6 |
if x < -0.02270927157581989Initial program 0.9
rmApplied add-exp-log0.9
rmApplied add-log-exp1.1
Simplified1.1
rmApplied add-log-exp1.3
Applied add-log-exp1.3
Applied diff-log1.5
Simplified1.3
if -0.02270927157581989 < x < 0.01743449574326637Initial program 59.9
Taylor expanded around 0 0.0
Simplified0.0
if 0.01743449574326637 < x Initial program 1.0
rmApplied div-sub1.2
Final simplification0.6
herbie shell --seed 2019212 +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)))