\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.004893422048095925:\\
\;\;\;\;\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)\\
\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 2.98402005876572314 \cdot 10^{-5}:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{{\left(\frac{\sin x}{1 - \cos x}\right)}^{1}}\\
\end{array}double f(double x) {
double r37415 = 1.0;
double r37416 = x;
double r37417 = cos(r37416);
double r37418 = r37415 - r37417;
double r37419 = sin(r37416);
double r37420 = r37418 / r37419;
return r37420;
}
double f(double x) {
double r37421 = 1.0;
double r37422 = x;
double r37423 = cos(r37422);
double r37424 = r37421 - r37423;
double r37425 = sin(r37422);
double r37426 = r37424 / r37425;
double r37427 = -0.0048934220480959245;
bool r37428 = r37426 <= r37427;
double r37429 = exp(r37426);
double r37430 = log(r37429);
double r37431 = 2.984020058765723e-05;
bool r37432 = r37426 <= r37431;
double r37433 = 0.041666666666666664;
double r37434 = 3.0;
double r37435 = pow(r37422, r37434);
double r37436 = r37433 * r37435;
double r37437 = 0.004166666666666667;
double r37438 = 5.0;
double r37439 = pow(r37422, r37438);
double r37440 = r37437 * r37439;
double r37441 = 0.5;
double r37442 = r37441 * r37422;
double r37443 = r37440 + r37442;
double r37444 = r37436 + r37443;
double r37445 = 1.0;
double r37446 = r37425 / r37424;
double r37447 = pow(r37446, r37445);
double r37448 = r37445 / r37447;
double r37449 = r37432 ? r37444 : r37448;
double r37450 = r37428 ? r37430 : r37449;
return r37450;
}




Bits error versus x
Results
| Original | 30.4 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.0048934220480959245Initial program 0.9
rmApplied add-log-exp1.0
if -0.0048934220480959245 < (/ (- 1.0 (cos x)) (sin x)) < 2.984020058765723e-05Initial program 59.9
Taylor expanded around 0 0.1
if 2.984020058765723e-05 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.1
rmApplied clear-num1.1
rmApplied pow11.1
Final simplification0.6
herbie shell --seed 2020046
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))