\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0195414650842071873:\\
\;\;\;\;\frac{1 - \cos x}{\sin x}\\
\mathbf{elif}\;x \le 0.023267676544555443:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{e}^{\left(\log \left(1 - \cos x\right)\right)}}{\sin x}\\
\end{array}double f(double x) {
double r39417 = 1.0;
double r39418 = x;
double r39419 = cos(r39418);
double r39420 = r39417 - r39419;
double r39421 = sin(r39418);
double r39422 = r39420 / r39421;
return r39422;
}
double f(double x) {
double r39423 = x;
double r39424 = -0.019541465084207187;
bool r39425 = r39423 <= r39424;
double r39426 = 1.0;
double r39427 = cos(r39423);
double r39428 = r39426 - r39427;
double r39429 = sin(r39423);
double r39430 = r39428 / r39429;
double r39431 = 0.023267676544555443;
bool r39432 = r39423 <= r39431;
double r39433 = 0.041666666666666664;
double r39434 = 3.0;
double r39435 = pow(r39423, r39434);
double r39436 = r39433 * r39435;
double r39437 = 0.004166666666666667;
double r39438 = 5.0;
double r39439 = pow(r39423, r39438);
double r39440 = r39437 * r39439;
double r39441 = 0.5;
double r39442 = r39441 * r39423;
double r39443 = r39440 + r39442;
double r39444 = r39436 + r39443;
double r39445 = exp(1.0);
double r39446 = log(r39428);
double r39447 = pow(r39445, r39446);
double r39448 = r39447 / r39429;
double r39449 = r39432 ? r39444 : r39448;
double r39450 = r39425 ? r39430 : r39449;
return r39450;
}




Bits error versus x
Results
| Original | 30.1 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.019541465084207187Initial program 0.9
rmApplied add-exp-log0.9
rmApplied rem-exp-log0.9
if -0.019541465084207187 < x < 0.023267676544555443Initial program 60.0
Taylor expanded around 0 0.0
if 0.023267676544555443 < x Initial program 0.9
rmApplied add-exp-log0.9
rmApplied pow10.9
Applied log-pow0.9
Applied exp-prod1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2020047
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))