\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.022144219019054306:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\\
\mathbf{elif}\;x \le 0.0203937394598384565:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\sin x}}{\frac{1}{1 - \cos x}}\\
\end{array}double f(double x) {
double r40849 = 1.0;
double r40850 = x;
double r40851 = cos(r40850);
double r40852 = r40849 - r40851;
double r40853 = sin(r40850);
double r40854 = r40852 / r40853;
return r40854;
}
double f(double x) {
double r40855 = x;
double r40856 = -0.022144219019054306;
bool r40857 = r40855 <= r40856;
double r40858 = 1.0;
double r40859 = 3.0;
double r40860 = pow(r40858, r40859);
double r40861 = cos(r40855);
double r40862 = pow(r40861, r40859);
double r40863 = r40860 - r40862;
double r40864 = r40861 + r40858;
double r40865 = r40861 * r40864;
double r40866 = r40858 * r40858;
double r40867 = r40865 + r40866;
double r40868 = sin(r40855);
double r40869 = r40867 * r40868;
double r40870 = r40863 / r40869;
double r40871 = 0.020393739459838457;
bool r40872 = r40855 <= r40871;
double r40873 = 0.041666666666666664;
double r40874 = pow(r40855, r40859);
double r40875 = r40873 * r40874;
double r40876 = 0.004166666666666667;
double r40877 = 5.0;
double r40878 = pow(r40855, r40877);
double r40879 = r40876 * r40878;
double r40880 = 0.5;
double r40881 = r40880 * r40855;
double r40882 = r40879 + r40881;
double r40883 = r40875 + r40882;
double r40884 = 1.0;
double r40885 = r40884 / r40868;
double r40886 = r40858 - r40861;
double r40887 = r40884 / r40886;
double r40888 = r40885 / r40887;
double r40889 = r40872 ? r40883 : r40888;
double r40890 = r40857 ? r40870 : r40889;
return r40890;
}




Bits error versus x
Results
| Original | 29.6 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.022144219019054306Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
if -0.022144219019054306 < x < 0.020393739459838457Initial program 59.9
Taylor expanded around 0 0.0
if 0.020393739459838457 < x Initial program 0.9
rmApplied clear-num1.0
rmApplied div-inv1.0
Applied associate-/r*1.0
Final simplification0.5
herbie shell --seed 2020060
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))