\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 r64712 = 1.0;
double r64713 = x;
double r64714 = cos(r64713);
double r64715 = r64712 - r64714;
double r64716 = sin(r64713);
double r64717 = r64715 / r64716;
return r64717;
}
double f(double x) {
double r64718 = x;
double r64719 = -0.024280922068190693;
bool r64720 = r64718 <= r64719;
double r64721 = 1.0;
double r64722 = sin(r64718);
double r64723 = r64721 / r64722;
double r64724 = cos(r64718);
double r64725 = r64724 / r64722;
double r64726 = r64723 - r64725;
double r64727 = 0.021088117470294238;
bool r64728 = r64718 <= r64727;
double r64729 = 0.041666666666666664;
double r64730 = 3.0;
double r64731 = pow(r64718, r64730);
double r64732 = 0.004166666666666667;
double r64733 = 5.0;
double r64734 = pow(r64718, r64733);
double r64735 = 0.5;
double r64736 = r64735 * r64718;
double r64737 = fma(r64732, r64734, r64736);
double r64738 = fma(r64729, r64731, r64737);
double r64739 = r64721 - r64724;
double r64740 = r64722 * r64739;
double r64741 = r64722 * r64722;
double r64742 = r64740 / r64741;
double r64743 = r64728 ? r64738 : r64742;
double r64744 = r64720 ? r64726 : r64743;
return r64744;
}




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)))