\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.001308568773005096318520767972870544326724 \lor \neg \left(\frac{1 - \cos x}{\sin x} \le 4.957178312169810962668929968898134941213 \cdot 10^{-8}\right):\\
\;\;\;\;\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)\\
\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 r63706 = 1.0;
double r63707 = x;
double r63708 = cos(r63707);
double r63709 = r63706 - r63708;
double r63710 = sin(r63707);
double r63711 = r63709 / r63710;
return r63711;
}
double f(double x) {
double r63712 = 1.0;
double r63713 = x;
double r63714 = cos(r63713);
double r63715 = r63712 - r63714;
double r63716 = sin(r63713);
double r63717 = r63715 / r63716;
double r63718 = -0.0013085687730050963;
bool r63719 = r63717 <= r63718;
double r63720 = 4.957178312169811e-08;
bool r63721 = r63717 <= r63720;
double r63722 = !r63721;
bool r63723 = r63719 || r63722;
double r63724 = exp(r63717);
double r63725 = log(r63724);
double r63726 = 0.041666666666666664;
double r63727 = 3.0;
double r63728 = pow(r63713, r63727);
double r63729 = 0.004166666666666667;
double r63730 = 5.0;
double r63731 = pow(r63713, r63730);
double r63732 = 0.5;
double r63733 = r63732 * r63713;
double r63734 = fma(r63729, r63731, r63733);
double r63735 = fma(r63726, r63728, r63734);
double r63736 = r63723 ? r63725 : r63735;
return r63736;
}




Bits error versus x
| Original | 30.4 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.0013085687730050963 or 4.957178312169811e-08 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.1
rmApplied add-log-exp1.2
if -0.0013085687730050963 < (/ (- 1.0 (cos x)) (sin x)) < 4.957178312169811e-08Initial program 60.2
Taylor expanded around 0 0.0
Simplified0.0
Final simplification0.6
herbie shell --seed 2019347 +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)))