\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.023342343569720127:\\
\;\;\;\;\frac{1}{\frac{\sin x}{\mathsf{expm1}\left(\mathsf{log1p}\left(1 - \cos x\right)\right)}}\\
\mathbf{elif}\;x \le 0.02343065570717855:\\
\;\;\;\;\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}:\\
\;\;\;\;\log \left(e^{\frac{1}{\frac{\sin x}{1 - \cos x}}}\right)\\
\end{array}double f(double x) {
double r49109 = 1.0;
double r49110 = x;
double r49111 = cos(r49110);
double r49112 = r49109 - r49111;
double r49113 = sin(r49110);
double r49114 = r49112 / r49113;
return r49114;
}
double f(double x) {
double r49115 = x;
double r49116 = -0.023342343569720127;
bool r49117 = r49115 <= r49116;
double r49118 = 1.0;
double r49119 = sin(r49115);
double r49120 = 1.0;
double r49121 = cos(r49115);
double r49122 = r49120 - r49121;
double r49123 = log1p(r49122);
double r49124 = expm1(r49123);
double r49125 = r49119 / r49124;
double r49126 = r49118 / r49125;
double r49127 = 0.02343065570717855;
bool r49128 = r49115 <= r49127;
double r49129 = 0.041666666666666664;
double r49130 = 3.0;
double r49131 = pow(r49115, r49130);
double r49132 = 0.004166666666666667;
double r49133 = 5.0;
double r49134 = pow(r49115, r49133);
double r49135 = 0.5;
double r49136 = r49135 * r49115;
double r49137 = fma(r49132, r49134, r49136);
double r49138 = fma(r49129, r49131, r49137);
double r49139 = r49119 / r49122;
double r49140 = r49118 / r49139;
double r49141 = exp(r49140);
double r49142 = log(r49141);
double r49143 = r49128 ? r49138 : r49142;
double r49144 = r49117 ? r49126 : r49143;
return r49144;
}




Bits error versus x
| Original | 30.6 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.023342343569720127Initial program 0.8
rmApplied clear-num0.9
rmApplied expm1-log1p-u1.0
if -0.023342343569720127 < x < 0.02343065570717855Initial program 60.0
Taylor expanded around 0 0.0
Simplified0.0
if 0.02343065570717855 < x Initial program 0.9
rmApplied clear-num1.0
rmApplied add-log-exp1.1
Final simplification0.5
herbie shell --seed 2020035 +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)))