\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.008960255255002240112882638811697688652202:\\
\;\;\;\;\frac{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right) \cdot \frac{1 - \cos x}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 1.05393807315382309185841647192205527972 \cdot 10^{-4}:\\
\;\;\;\;\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{1}{\sin x} - \frac{\cos x}{\sin x}\\
\end{array}double f(double x) {
double r59910 = 1.0;
double r59911 = x;
double r59912 = cos(r59911);
double r59913 = r59910 - r59912;
double r59914 = sin(r59911);
double r59915 = r59913 / r59914;
return r59915;
}
double f(double x) {
double r59916 = 1.0;
double r59917 = x;
double r59918 = cos(r59917);
double r59919 = r59916 - r59918;
double r59920 = sin(r59917);
double r59921 = r59919 / r59920;
double r59922 = -0.00896025525500224;
bool r59923 = r59921 <= r59922;
double r59924 = r59916 + r59918;
double r59925 = r59916 * r59916;
double r59926 = fma(r59918, r59924, r59925);
double r59927 = r59919 / r59926;
double r59928 = r59926 * r59927;
double r59929 = r59928 / r59920;
double r59930 = 0.00010539380731538231;
bool r59931 = r59921 <= r59930;
double r59932 = 0.041666666666666664;
double r59933 = 3.0;
double r59934 = pow(r59917, r59933);
double r59935 = 0.004166666666666667;
double r59936 = 5.0;
double r59937 = pow(r59917, r59936);
double r59938 = 0.5;
double r59939 = r59938 * r59917;
double r59940 = fma(r59935, r59937, r59939);
double r59941 = fma(r59932, r59934, r59940);
double r59942 = r59916 / r59920;
double r59943 = r59918 / r59920;
double r59944 = r59942 - r59943;
double r59945 = r59931 ? r59941 : r59944;
double r59946 = r59923 ? r59929 : r59945;
return r59946;
}




Bits error versus x
| Original | 29.7 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.00896025525500224Initial program 0.8
rmApplied flip3--1.0
Simplified1.0
rmApplied *-un-lft-identity1.0
Applied difference-cubes0.9
Applied times-frac1.0
Simplified0.9
if -0.00896025525500224 < (/ (- 1.0 (cos x)) (sin x)) < 0.00010539380731538231Initial program 59.8
Taylor expanded around 0 0.2
Simplified0.2
if 0.00010539380731538231 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.0
rmApplied div-sub1.2
Final simplification0.6
herbie shell --seed 2019344 +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)))