\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02231606801598658498808624983666959451512:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\\
\mathbf{elif}\;x \le 0.02219699502236853819181483515876607270911:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;{e}^{\left(\log \left(1 - \cos x\right)\right)} \cdot \frac{1}{\sin x}\\
\end{array}double f(double x) {
double r48436 = 1.0;
double r48437 = x;
double r48438 = cos(r48437);
double r48439 = r48436 - r48438;
double r48440 = sin(r48437);
double r48441 = r48439 / r48440;
return r48441;
}
double f(double x) {
double r48442 = x;
double r48443 = -0.022316068015986585;
bool r48444 = r48442 <= r48443;
double r48445 = 1.0;
double r48446 = 3.0;
double r48447 = pow(r48445, r48446);
double r48448 = cos(r48442);
double r48449 = pow(r48448, r48446);
double r48450 = r48447 - r48449;
double r48451 = sin(r48442);
double r48452 = r48445 + r48448;
double r48453 = r48448 * r48452;
double r48454 = r48445 * r48445;
double r48455 = r48453 + r48454;
double r48456 = r48451 * r48455;
double r48457 = r48450 / r48456;
double r48458 = 0.022196995022368538;
bool r48459 = r48442 <= r48458;
double r48460 = 0.041666666666666664;
double r48461 = pow(r48442, r48446);
double r48462 = r48460 * r48461;
double r48463 = 0.004166666666666667;
double r48464 = 5.0;
double r48465 = pow(r48442, r48464);
double r48466 = r48463 * r48465;
double r48467 = 0.5;
double r48468 = r48467 * r48442;
double r48469 = r48466 + r48468;
double r48470 = r48462 + r48469;
double r48471 = exp(1.0);
double r48472 = r48445 - r48448;
double r48473 = log(r48472);
double r48474 = pow(r48471, r48473);
double r48475 = 1.0;
double r48476 = r48475 / r48451;
double r48477 = r48474 * r48476;
double r48478 = r48459 ? r48470 : r48477;
double r48479 = r48444 ? r48457 : r48478;
return r48479;
}




Bits error versus x
Results
| Original | 29.9 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.022316068015986585Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
if -0.022316068015986585 < x < 0.022196995022368538Initial program 59.9
Taylor expanded around 0 0.0
if 0.022196995022368538 < x Initial program 0.9
rmApplied add-exp-log0.9
rmApplied pow10.9
Applied log-pow0.9
Applied exp-prod1.0
Simplified1.0
rmApplied div-inv1.0
Final simplification0.5
herbie shell --seed 2019325
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))