\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.004893422048095925:\\
\;\;\;\;\log \left(\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\frac{1 - \cos x}{\sin x}}\right)\right)\right)\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 2.98402005876572314 \cdot 10^{-5}:\\
\;\;\;\;\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}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1 - \cos x}{\sin x}\right)\right)\\
\end{array}double f(double x) {
double r106597 = 1.0;
double r106598 = x;
double r106599 = cos(r106598);
double r106600 = r106597 - r106599;
double r106601 = sin(r106598);
double r106602 = r106600 / r106601;
return r106602;
}
double f(double x) {
double r106603 = 1.0;
double r106604 = x;
double r106605 = cos(r106604);
double r106606 = r106603 - r106605;
double r106607 = sin(r106604);
double r106608 = r106606 / r106607;
double r106609 = -0.0048934220480959245;
bool r106610 = r106608 <= r106609;
double r106611 = exp(r106608);
double r106612 = log1p(r106611);
double r106613 = expm1(r106612);
double r106614 = log(r106613);
double r106615 = 2.984020058765723e-05;
bool r106616 = r106608 <= r106615;
double r106617 = 0.041666666666666664;
double r106618 = 3.0;
double r106619 = pow(r106604, r106618);
double r106620 = 0.004166666666666667;
double r106621 = 5.0;
double r106622 = pow(r106604, r106621);
double r106623 = 0.5;
double r106624 = r106623 * r106604;
double r106625 = fma(r106620, r106622, r106624);
double r106626 = fma(r106617, r106619, r106625);
double r106627 = expm1(r106608);
double r106628 = log1p(r106627);
double r106629 = r106616 ? r106626 : r106628;
double r106630 = r106610 ? r106614 : r106629;
return r106630;
}




Bits error versus x
| Original | 30.4 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.0048934220480959245Initial program 0.9
rmApplied add-log-exp1.0
rmApplied expm1-log1p-u1.1
if -0.0048934220480959245 < (/ (- 1.0 (cos x)) (sin x)) < 2.984020058765723e-05Initial program 59.9
Taylor expanded around 0 0.1
Simplified0.1
if 2.984020058765723e-05 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.1
rmApplied log1p-expm1-u1.1
Final simplification0.6
herbie shell --seed 2020046 +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)))