\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0202867432772082697:\\
\;\;\;\;\log \left(e^{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}}\right)\\
\mathbf{elif}\;x \le 0.026425734950010618:\\
\;\;\;\;\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(\frac{e^{\frac{1}{\sin x}}}{e^{\frac{\cos x}{\sin x}}}\right)\\
\end{array}double f(double x) {
double r63431 = 1.0;
double r63432 = x;
double r63433 = cos(r63432);
double r63434 = r63431 - r63433;
double r63435 = sin(r63432);
double r63436 = r63434 / r63435;
return r63436;
}
double f(double x) {
double r63437 = x;
double r63438 = -0.02028674327720827;
bool r63439 = r63437 <= r63438;
double r63440 = 1.0;
double r63441 = 3.0;
double r63442 = pow(r63440, r63441);
double r63443 = cos(r63437);
double r63444 = pow(r63443, r63441);
double r63445 = r63442 - r63444;
double r63446 = r63440 * r63443;
double r63447 = fma(r63443, r63443, r63446);
double r63448 = fma(r63440, r63440, r63447);
double r63449 = sin(r63437);
double r63450 = r63448 * r63449;
double r63451 = r63445 / r63450;
double r63452 = exp(r63451);
double r63453 = log(r63452);
double r63454 = 0.026425734950010618;
bool r63455 = r63437 <= r63454;
double r63456 = 0.041666666666666664;
double r63457 = pow(r63437, r63441);
double r63458 = 0.004166666666666667;
double r63459 = 5.0;
double r63460 = pow(r63437, r63459);
double r63461 = 0.5;
double r63462 = r63461 * r63437;
double r63463 = fma(r63458, r63460, r63462);
double r63464 = fma(r63456, r63457, r63463);
double r63465 = r63440 / r63449;
double r63466 = exp(r63465);
double r63467 = r63443 / r63449;
double r63468 = exp(r63467);
double r63469 = r63466 / r63468;
double r63470 = log(r63469);
double r63471 = r63455 ? r63464 : r63470;
double r63472 = r63439 ? r63453 : r63471;
return r63472;
}




Bits error versus x
| Original | 30.6 |
|---|---|
| Target | 0 |
| Herbie | 0.6 |
if x < -0.02028674327720827Initial program 0.8
rmApplied add-log-exp0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
if -0.02028674327720827 < x < 0.026425734950010618Initial program 60.0
Taylor expanded around 0 0.0
Simplified0.0
if 0.026425734950010618 < x Initial program 0.9
rmApplied add-log-exp1.1
rmApplied div-sub1.3
Applied exp-diff1.3
Final simplification0.6
herbie shell --seed 2020059 +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)))