\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02354046714369385437382042880471999524161:\\
\;\;\;\;\frac{\frac{{1}^{3} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}}{\sin x}\\
\mathbf{elif}\;x \le 0.02128798787360045713379363974127045366913:\\
\;\;\;\;\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{\frac{{1}^{3}}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)} - \frac{\mathsf{log1p}\left(\mathsf{expm1}\left({\left(\cos x\right)}^{3}\right)\right)}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}}{\sin x}\\
\end{array}double f(double x) {
double r73748 = 1.0;
double r73749 = x;
double r73750 = cos(r73749);
double r73751 = r73748 - r73750;
double r73752 = sin(r73749);
double r73753 = r73751 / r73752;
return r73753;
}
double f(double x) {
double r73754 = x;
double r73755 = -0.023540467143693854;
bool r73756 = r73754 <= r73755;
double r73757 = 1.0;
double r73758 = 3.0;
double r73759 = pow(r73757, r73758);
double r73760 = cos(r73754);
double r73761 = pow(r73760, r73758);
double r73762 = pow(r73761, r73758);
double r73763 = cbrt(r73762);
double r73764 = r73759 - r73763;
double r73765 = r73757 + r73760;
double r73766 = r73760 * r73765;
double r73767 = fma(r73757, r73757, r73766);
double r73768 = r73764 / r73767;
double r73769 = sin(r73754);
double r73770 = r73768 / r73769;
double r73771 = 0.021287987873600457;
bool r73772 = r73754 <= r73771;
double r73773 = 0.041666666666666664;
double r73774 = pow(r73754, r73758);
double r73775 = 0.004166666666666667;
double r73776 = 5.0;
double r73777 = pow(r73754, r73776);
double r73778 = 0.5;
double r73779 = r73778 * r73754;
double r73780 = fma(r73775, r73777, r73779);
double r73781 = fma(r73773, r73774, r73780);
double r73782 = r73759 / r73767;
double r73783 = expm1(r73761);
double r73784 = log1p(r73783);
double r73785 = r73784 / r73767;
double r73786 = r73782 - r73785;
double r73787 = r73786 / r73769;
double r73788 = r73772 ? r73781 : r73787;
double r73789 = r73756 ? r73770 : r73788;
return r73789;
}




Bits error versus x
| Original | 29.9 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if x < -0.023540467143693854Initial program 0.9
rmApplied flip3--1.0
Simplified1.0
rmApplied add-cbrt-cube1.1
Simplified1.1
if -0.023540467143693854 < x < 0.021287987873600457Initial program 60.0
Taylor expanded around 0 0.0
Simplified0.0
if 0.021287987873600457 < x Initial program 1.0
rmApplied flip3--1.1
Simplified1.1
rmApplied div-sub1.1
rmApplied log1p-expm1-u1.1
Final simplification0.6
herbie shell --seed 2019322 +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)))