\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02322762662824425991536791968883335357532:\\
\;\;\;\;\frac{{1}^{3} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\\
\mathbf{elif}\;x \le 0.02090434993213574621506722905905917286873:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{1}^{3} - \log \left(e^{{\left(\cos x\right)}^{3}}\right)}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\\
\end{array}double f(double x) {
double r54711 = 1.0;
double r54712 = x;
double r54713 = cos(r54712);
double r54714 = r54711 - r54713;
double r54715 = sin(r54712);
double r54716 = r54714 / r54715;
return r54716;
}
double f(double x) {
double r54717 = x;
double r54718 = -0.02322762662824426;
bool r54719 = r54717 <= r54718;
double r54720 = 1.0;
double r54721 = 3.0;
double r54722 = pow(r54720, r54721);
double r54723 = cos(r54717);
double r54724 = pow(r54723, r54721);
double r54725 = pow(r54724, r54721);
double r54726 = cbrt(r54725);
double r54727 = r54722 - r54726;
double r54728 = r54723 + r54720;
double r54729 = r54723 * r54728;
double r54730 = r54720 * r54720;
double r54731 = r54729 + r54730;
double r54732 = sin(r54717);
double r54733 = r54731 * r54732;
double r54734 = r54727 / r54733;
double r54735 = 0.020904349932135746;
bool r54736 = r54717 <= r54735;
double r54737 = 0.041666666666666664;
double r54738 = pow(r54717, r54721);
double r54739 = r54737 * r54738;
double r54740 = 0.004166666666666667;
double r54741 = 5.0;
double r54742 = pow(r54717, r54741);
double r54743 = r54740 * r54742;
double r54744 = 0.5;
double r54745 = r54744 * r54717;
double r54746 = r54743 + r54745;
double r54747 = r54739 + r54746;
double r54748 = exp(r54724);
double r54749 = log(r54748);
double r54750 = r54722 - r54749;
double r54751 = r54750 / r54733;
double r54752 = r54736 ? r54747 : r54751;
double r54753 = r54719 ? r54734 : r54752;
return r54753;
}




Bits error versus x
Results
| Original | 30.4 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.02322762662824426Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied add-cbrt-cube1.1
Simplified1.1
if -0.02322762662824426 < x < 0.020904349932135746Initial program 59.7
Taylor expanded around 0 0.0
if 0.020904349932135746 < x Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied add-log-exp1.1
Final simplification0.5
herbie shell --seed 2019352
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))