\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0311367922052378544 \lor \neg \left(\frac{1 - \cos x}{\sin x} \le 0.0038090217065521576\right):\\
\;\;\;\;\frac{1 - \cos x}{\sin x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{24}, {x}^{3}, \mathsf{fma}\left(\frac{1}{240}, {x}^{5}, \frac{1}{2} \cdot x\right)\right)\\
\end{array}double f(double x) {
double r66090 = 1.0;
double r66091 = x;
double r66092 = cos(r66091);
double r66093 = r66090 - r66092;
double r66094 = sin(r66091);
double r66095 = r66093 / r66094;
return r66095;
}
double f(double x) {
double r66096 = 1.0;
double r66097 = x;
double r66098 = cos(r66097);
double r66099 = r66096 - r66098;
double r66100 = sin(r66097);
double r66101 = r66099 / r66100;
double r66102 = -0.031136792205237854;
bool r66103 = r66101 <= r66102;
double r66104 = 0.0038090217065521576;
bool r66105 = r66101 <= r66104;
double r66106 = !r66105;
bool r66107 = r66103 || r66106;
double r66108 = 0.041666666666666664;
double r66109 = 3.0;
double r66110 = pow(r66097, r66109);
double r66111 = 0.004166666666666667;
double r66112 = 5.0;
double r66113 = pow(r66097, r66112);
double r66114 = 0.5;
double r66115 = r66114 * r66097;
double r66116 = fma(r66111, r66113, r66115);
double r66117 = fma(r66108, r66110, r66116);
double r66118 = r66107 ? r66101 : r66117;
return r66118;
}




Bits error versus x
| Original | 30.2 |
|---|---|
| Target | 0.0 |
| Herbie | 0.7 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.031136792205237854 or 0.0038090217065521576 < (/ (- 1.0 (cos x)) (sin x)) Initial program 0.8
rmApplied add-log-exp0.9
rmApplied expm1-log1p-u1.0
Taylor expanded around inf 0.8
if -0.031136792205237854 < (/ (- 1.0 (cos x)) (sin x)) < 0.0038090217065521576Initial program 59.3
Taylor expanded around 0 0.7
Simplified0.7
Final simplification0.7
herbie shell --seed 2020089 +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)))