\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0242809220681906925976001332401210675016:\\
\;\;\;\;\frac{1}{\sin x} - \frac{\cos x}{\sin x}\\
\mathbf{elif}\;x \le 0.02108811747029423755428467757155885919929:\\
\;\;\;\;\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{\sin x \cdot \left(1 - \cos x\right)}{\sin x \cdot \sin x}\\
\end{array}double f(double x) {
double r64597 = 1.0;
double r64598 = x;
double r64599 = cos(r64598);
double r64600 = r64597 - r64599;
double r64601 = sin(r64598);
double r64602 = r64600 / r64601;
return r64602;
}
double f(double x) {
double r64603 = x;
double r64604 = -0.024280922068190693;
bool r64605 = r64603 <= r64604;
double r64606 = 1.0;
double r64607 = sin(r64603);
double r64608 = r64606 / r64607;
double r64609 = cos(r64603);
double r64610 = r64609 / r64607;
double r64611 = r64608 - r64610;
double r64612 = 0.021088117470294238;
bool r64613 = r64603 <= r64612;
double r64614 = 0.041666666666666664;
double r64615 = 3.0;
double r64616 = pow(r64603, r64615);
double r64617 = 0.004166666666666667;
double r64618 = 5.0;
double r64619 = pow(r64603, r64618);
double r64620 = 0.5;
double r64621 = r64620 * r64603;
double r64622 = fma(r64617, r64619, r64621);
double r64623 = fma(r64614, r64616, r64622);
double r64624 = r64606 - r64609;
double r64625 = r64607 * r64624;
double r64626 = r64607 * r64607;
double r64627 = r64625 / r64626;
double r64628 = r64613 ? r64623 : r64627;
double r64629 = r64605 ? r64611 : r64628;
return r64629;
}




Bits error versus x
| Original | 30.2 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.024280922068190693Initial program 0.9
rmApplied div-sub1.1
if -0.024280922068190693 < x < 0.021088117470294238Initial program 60.0
Taylor expanded around 0 0.0
Simplified0.0
if 0.021088117470294238 < x Initial program 0.9
rmApplied div-sub1.1
rmApplied frac-sub1.1
Simplified1.0
Final simplification0.5
herbie shell --seed 2020001 +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)))