\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.03628702050037945631144609137663792353123 \lor \neg \left(\frac{1 - \cos x}{\sin x} \le 1.622109525504273900412314200758512328093 \cdot 10^{-6}\right):\\
\;\;\;\;\frac{1 - \cos x}{\sin x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{24}, {x}^{3}, \mathsf{fma}\left(\frac{1}{240}, {x}^{5}, \frac{1}{2} \cdot x\right)\right)\\
\end{array}double f(double x) {
double r53976 = 1.0;
double r53977 = x;
double r53978 = cos(r53977);
double r53979 = r53976 - r53978;
double r53980 = sin(r53977);
double r53981 = r53979 / r53980;
return r53981;
}
double f(double x) {
double r53982 = 1.0;
double r53983 = x;
double r53984 = cos(r53983);
double r53985 = r53982 - r53984;
double r53986 = sin(r53983);
double r53987 = r53985 / r53986;
double r53988 = -0.036287020500379456;
bool r53989 = r53987 <= r53988;
double r53990 = 1.622109525504274e-06;
bool r53991 = r53987 <= r53990;
double r53992 = !r53991;
bool r53993 = r53989 || r53992;
double r53994 = 0.041666666666666664;
double r53995 = 3.0;
double r53996 = pow(r53983, r53995);
double r53997 = 0.004166666666666667;
double r53998 = 5.0;
double r53999 = pow(r53983, r53998);
double r54000 = 0.5;
double r54001 = r54000 * r53983;
double r54002 = fma(r53997, r53999, r54001);
double r54003 = fma(r53994, r53996, r54002);
double r54004 = r53993 ? r53987 : r54003;
return r54004;
}




Bits error versus x
| Original | 30.5 |
|---|---|
| Target | 0.0 |
| Herbie | 0.8 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.036287020500379456 or 1.622109525504274e-06 < (/ (- 1.0 (cos x)) (sin x)) Initial program 0.9
rmApplied add-exp-log0.9
rmApplied *-un-lft-identity0.9
Applied *-un-lft-identity0.9
Applied log-prod0.9
Applied exp-sum0.9
Applied times-frac0.9
Simplified0.9
Simplified0.9
if -0.036287020500379456 < (/ (- 1.0 (cos x)) (sin x)) < 1.622109525504274e-06Initial program 59.5
Taylor expanded around 0 0.7
Simplified0.7
Final simplification0.8
herbie shell --seed 2019304 +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)))