\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0229853120832149115:\\
\;\;\;\;\log \left(e^{\frac{1}{\frac{\sin x}{1 - \cos x}}}\right)\\
\mathbf{elif}\;x \le 0.026425734950010618:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\frac{e^{\frac{1}{\sin x}}}{e^{\frac{\cos x}{\sin x}}}\right)\\
\end{array}double f(double x) {
double r51977 = 1.0;
double r51978 = x;
double r51979 = cos(r51978);
double r51980 = r51977 - r51979;
double r51981 = sin(r51978);
double r51982 = r51980 / r51981;
return r51982;
}
double f(double x) {
double r51983 = x;
double r51984 = -0.02298531208321491;
bool r51985 = r51983 <= r51984;
double r51986 = 1.0;
double r51987 = sin(r51983);
double r51988 = 1.0;
double r51989 = cos(r51983);
double r51990 = r51988 - r51989;
double r51991 = r51987 / r51990;
double r51992 = r51986 / r51991;
double r51993 = exp(r51992);
double r51994 = log(r51993);
double r51995 = 0.026425734950010618;
bool r51996 = r51983 <= r51995;
double r51997 = 0.041666666666666664;
double r51998 = 3.0;
double r51999 = pow(r51983, r51998);
double r52000 = r51997 * r51999;
double r52001 = 0.004166666666666667;
double r52002 = 5.0;
double r52003 = pow(r51983, r52002);
double r52004 = r52001 * r52003;
double r52005 = 0.5;
double r52006 = r52005 * r51983;
double r52007 = r52004 + r52006;
double r52008 = r52000 + r52007;
double r52009 = r51988 / r51987;
double r52010 = exp(r52009);
double r52011 = r51989 / r51987;
double r52012 = exp(r52011);
double r52013 = r52010 / r52012;
double r52014 = log(r52013);
double r52015 = r51996 ? r52008 : r52014;
double r52016 = r51985 ? r51994 : r52015;
return r52016;
}




Bits error versus x
Results
| Original | 30.6 |
|---|---|
| Target | 0 |
| Herbie | 0.6 |
if x < -0.02298531208321491Initial program 0.8
rmApplied add-log-exp0.9
rmApplied clear-num1.0
if -0.02298531208321491 < x < 0.026425734950010618Initial program 60.0
Taylor expanded around 0 0.0
if 0.026425734950010618 < x Initial program 0.9
rmApplied add-log-exp1.1
rmApplied div-sub1.3
Applied exp-diff1.3
Final simplification0.6
herbie shell --seed 2020059
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))