\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0242809220681906925976001332401210675016:\\
\;\;\;\;\frac{1}{\sin x} - \frac{\cos x}{\sin x}\\
\mathbf{elif}\;x \le 0.02165047000055947065688677355410618474707:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\log \left(e^{1 - \cos x}\right)}{\sin x}\\
\end{array}double f(double x) {
double r51210 = 1.0;
double r51211 = x;
double r51212 = cos(r51211);
double r51213 = r51210 - r51212;
double r51214 = sin(r51211);
double r51215 = r51213 / r51214;
return r51215;
}
double f(double x) {
double r51216 = x;
double r51217 = -0.024280922068190693;
bool r51218 = r51216 <= r51217;
double r51219 = 1.0;
double r51220 = sin(r51216);
double r51221 = r51219 / r51220;
double r51222 = cos(r51216);
double r51223 = r51222 / r51220;
double r51224 = r51221 - r51223;
double r51225 = 0.02165047000055947;
bool r51226 = r51216 <= r51225;
double r51227 = 0.041666666666666664;
double r51228 = 3.0;
double r51229 = pow(r51216, r51228);
double r51230 = r51227 * r51229;
double r51231 = 0.004166666666666667;
double r51232 = 5.0;
double r51233 = pow(r51216, r51232);
double r51234 = r51231 * r51233;
double r51235 = 0.5;
double r51236 = r51235 * r51216;
double r51237 = r51234 + r51236;
double r51238 = r51230 + r51237;
double r51239 = r51219 - r51222;
double r51240 = exp(r51239);
double r51241 = log(r51240);
double r51242 = r51241 / r51220;
double r51243 = r51226 ? r51238 : r51242;
double r51244 = r51218 ? r51224 : r51243;
return r51244;
}




Bits error versus x
Results
| Original | 30.2 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if x < -0.024280922068190693Initial program 0.9
rmApplied div-sub1.1
if -0.024280922068190693 < x < 0.02165047000055947Initial program 60.0
Taylor expanded around 0 0.0
if 0.02165047000055947 < x Initial program 0.9
rmApplied add-log-exp1.1
Applied add-log-exp1.1
Applied diff-log1.3
Simplified1.1
Final simplification0.6
herbie shell --seed 2020001
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))