\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0199905813077168142:\\
\;\;\;\;\sqrt[3]{{\left(\sqrt[3]{{\left(\frac{1 - \cos x}{\sin x}\right)}^{3}}\right)}^{3}}\\
\mathbf{elif}\;x \le 0.021452837467613652:\\
\;\;\;\;\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{\sqrt{1 - \cos x}}{\sin x} \cdot \sqrt{1 - \cos x}\\
\end{array}double f(double x) {
double r77802 = 1.0;
double r77803 = x;
double r77804 = cos(r77803);
double r77805 = r77802 - r77804;
double r77806 = sin(r77803);
double r77807 = r77805 / r77806;
return r77807;
}
double f(double x) {
double r77808 = x;
double r77809 = -0.019990581307716814;
bool r77810 = r77808 <= r77809;
double r77811 = 1.0;
double r77812 = cos(r77808);
double r77813 = r77811 - r77812;
double r77814 = sin(r77808);
double r77815 = r77813 / r77814;
double r77816 = 3.0;
double r77817 = pow(r77815, r77816);
double r77818 = cbrt(r77817);
double r77819 = pow(r77818, r77816);
double r77820 = cbrt(r77819);
double r77821 = 0.02145283746761365;
bool r77822 = r77808 <= r77821;
double r77823 = 0.041666666666666664;
double r77824 = pow(r77808, r77816);
double r77825 = 0.004166666666666667;
double r77826 = 5.0;
double r77827 = pow(r77808, r77826);
double r77828 = 0.5;
double r77829 = r77828 * r77808;
double r77830 = fma(r77825, r77827, r77829);
double r77831 = fma(r77823, r77824, r77830);
double r77832 = sqrt(r77813);
double r77833 = r77832 / r77814;
double r77834 = r77833 * r77832;
double r77835 = r77822 ? r77831 : r77834;
double r77836 = r77810 ? r77820 : r77835;
return r77836;
}




Bits error versus x
| Original | 30.1 |
|---|---|
| Target | 0 |
| Herbie | 0.6 |
if x < -0.019990581307716814Initial program 0.9
rmApplied add-cbrt-cube1.1
Applied add-cbrt-cube1.3
Applied cbrt-undiv1.1
Simplified1.1
rmApplied add-cbrt-cube1.3
Applied add-cbrt-cube1.4
Applied cbrt-undiv1.3
Simplified1.2
if -0.019990581307716814 < x < 0.02145283746761365Initial program 59.8
Taylor expanded around 0 0.0
Simplified0.0
if 0.02145283746761365 < x Initial program 0.9
rmApplied add-log-exp1.0
rmApplied *-un-lft-identity1.0
Applied add-sqr-sqrt1.2
Applied times-frac1.2
Applied exp-prod1.2
Applied log-pow1.1
Simplified1.1
Final simplification0.6
herbie shell --seed 2020036 +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)))