\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02322762662824425991536791968883335357532:\\
\;\;\;\;\log \left(\sqrt{e^{\frac{1 - \cos x}{\sin x}}}\right) + \log \left(\sqrt{e^{\frac{1 - \cos x}{\sin x}}}\right)\\
\mathbf{elif}\;x \le 0.02090434993213574621506722905905917286873:\\
\;\;\;\;\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}^{3} - \log \left(e^{{\left(\cos x\right)}^{3}}\right)}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}\\
\end{array}double f(double x) {
double r41960 = 1.0;
double r41961 = x;
double r41962 = cos(r41961);
double r41963 = r41960 - r41962;
double r41964 = sin(r41961);
double r41965 = r41963 / r41964;
return r41965;
}
double f(double x) {
double r41966 = x;
double r41967 = -0.02322762662824426;
bool r41968 = r41966 <= r41967;
double r41969 = 1.0;
double r41970 = cos(r41966);
double r41971 = r41969 - r41970;
double r41972 = sin(r41966);
double r41973 = r41971 / r41972;
double r41974 = exp(r41973);
double r41975 = sqrt(r41974);
double r41976 = log(r41975);
double r41977 = r41976 + r41976;
double r41978 = 0.020904349932135746;
bool r41979 = r41966 <= r41978;
double r41980 = 0.041666666666666664;
double r41981 = 3.0;
double r41982 = pow(r41966, r41981);
double r41983 = 0.004166666666666667;
double r41984 = 5.0;
double r41985 = pow(r41966, r41984);
double r41986 = 0.5;
double r41987 = r41986 * r41966;
double r41988 = fma(r41983, r41985, r41987);
double r41989 = fma(r41980, r41982, r41988);
double r41990 = pow(r41969, r41981);
double r41991 = pow(r41970, r41981);
double r41992 = exp(r41991);
double r41993 = log(r41992);
double r41994 = r41990 - r41993;
double r41995 = r41969 * r41970;
double r41996 = fma(r41970, r41970, r41995);
double r41997 = fma(r41969, r41969, r41996);
double r41998 = r41997 * r41972;
double r41999 = r41994 / r41998;
double r42000 = r41979 ? r41989 : r41999;
double r42001 = r41968 ? r41977 : r42000;
return r42001;
}




Bits error versus x
| Original | 30.4 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if x < -0.02322762662824426Initial program 0.9
rmApplied add-log-exp1.0
rmApplied add-sqr-sqrt1.2
Applied log-prod1.2
if -0.02322762662824426 < x < 0.020904349932135746Initial program 59.7
Taylor expanded around 0 0.0
Simplified0.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.6
herbie shell --seed 2019352 +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)))