\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02490049914676041933891958990443527000025:\\
\;\;\;\;\frac{\frac{\log \left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)}{\sin x}}{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}\\
\mathbf{elif}\;x \le 0.02315373815002300453280703607106261188164:\\
\;\;\;\;\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}:\\
\;\;\;\;\frac{\frac{{1}^{3} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}{\sin x}}{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}\\
\end{array}double f(double x) {
double r49457 = 1.0;
double r49458 = x;
double r49459 = cos(r49458);
double r49460 = r49457 - r49459;
double r49461 = sin(r49458);
double r49462 = r49460 / r49461;
return r49462;
}
double f(double x) {
double r49463 = x;
double r49464 = -0.02490049914676042;
bool r49465 = r49463 <= r49464;
double r49466 = 1.0;
double r49467 = 3.0;
double r49468 = pow(r49466, r49467);
double r49469 = cos(r49463);
double r49470 = pow(r49469, r49467);
double r49471 = r49468 - r49470;
double r49472 = exp(r49471);
double r49473 = log(r49472);
double r49474 = sin(r49463);
double r49475 = r49473 / r49474;
double r49476 = r49466 * r49466;
double r49477 = r49469 * r49469;
double r49478 = r49466 * r49469;
double r49479 = r49477 + r49478;
double r49480 = r49476 + r49479;
double r49481 = r49475 / r49480;
double r49482 = 0.023153738150023005;
bool r49483 = r49463 <= r49482;
double r49484 = 0.041666666666666664;
double r49485 = pow(r49463, r49467);
double r49486 = 0.004166666666666667;
double r49487 = 5.0;
double r49488 = pow(r49463, r49487);
double r49489 = 0.5;
double r49490 = r49489 * r49463;
double r49491 = fma(r49486, r49488, r49490);
double r49492 = fma(r49484, r49485, r49491);
double r49493 = pow(r49470, r49467);
double r49494 = cbrt(r49493);
double r49495 = r49468 - r49494;
double r49496 = r49495 / r49474;
double r49497 = r49496 / r49480;
double r49498 = r49483 ? r49492 : r49497;
double r49499 = r49465 ? r49481 : r49498;
return r49499;
}




Bits error versus x
| Original | 30.8 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.02490049914676042Initial program 0.9
rmApplied div-inv0.9
rmApplied flip3--1.0
Applied associate-*l/1.0
Simplified1.0
rmApplied add-log-exp1.0
Applied add-log-exp1.0
Applied diff-log1.1
Simplified1.0
if -0.02490049914676042 < x < 0.023153738150023005Initial program 59.9
Taylor expanded around 0 0.0
Simplified0.0
if 0.023153738150023005 < x Initial program 0.9
rmApplied div-inv0.9
rmApplied flip3--1.0
Applied associate-*l/1.0
Simplified1.0
rmApplied add-cbrt-cube1.1
Simplified1.1
Final simplification0.5
herbie shell --seed 2019346 +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)))