\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.022144219019054306:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}\\
\mathbf{elif}\;x \le 0.0203937394598384565:\\
\;\;\;\;\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{\frac{1}{\sin x}}{\frac{1}{1 - \cos x}}\\
\end{array}double f(double x) {
double r73027 = 1.0;
double r73028 = x;
double r73029 = cos(r73028);
double r73030 = r73027 - r73029;
double r73031 = sin(r73028);
double r73032 = r73030 / r73031;
return r73032;
}
double f(double x) {
double r73033 = x;
double r73034 = -0.022144219019054306;
bool r73035 = r73033 <= r73034;
double r73036 = 1.0;
double r73037 = 3.0;
double r73038 = pow(r73036, r73037);
double r73039 = cos(r73033);
double r73040 = pow(r73039, r73037);
double r73041 = r73038 - r73040;
double r73042 = r73036 * r73039;
double r73043 = fma(r73039, r73039, r73042);
double r73044 = fma(r73036, r73036, r73043);
double r73045 = sin(r73033);
double r73046 = r73044 * r73045;
double r73047 = r73041 / r73046;
double r73048 = 0.020393739459838457;
bool r73049 = r73033 <= r73048;
double r73050 = 0.041666666666666664;
double r73051 = pow(r73033, r73037);
double r73052 = 0.004166666666666667;
double r73053 = 5.0;
double r73054 = pow(r73033, r73053);
double r73055 = 0.5;
double r73056 = r73055 * r73033;
double r73057 = fma(r73052, r73054, r73056);
double r73058 = fma(r73050, r73051, r73057);
double r73059 = 1.0;
double r73060 = r73059 / r73045;
double r73061 = r73036 - r73039;
double r73062 = r73059 / r73061;
double r73063 = r73060 / r73062;
double r73064 = r73049 ? r73058 : r73063;
double r73065 = r73035 ? r73047 : r73064;
return r73065;
}




Bits error versus x
| 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
Simplified0.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 +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)))