\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02364773704659709624431584984449727926403:\\
\;\;\;\;\frac{\sqrt{e^{\log \left(1 - \cos x\right)}}}{\sin x} \cdot \sqrt{1 - \cos x}\\
\mathbf{elif}\;x \le 0.02077111946200701705911306760299339657649:\\
\;\;\;\;\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{\log \left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}\\
\end{array}double f(double x) {
double r58500 = 1.0;
double r58501 = x;
double r58502 = cos(r58501);
double r58503 = r58500 - r58502;
double r58504 = sin(r58501);
double r58505 = r58503 / r58504;
return r58505;
}
double f(double x) {
double r58506 = x;
double r58507 = -0.023647737046597096;
bool r58508 = r58506 <= r58507;
double r58509 = 1.0;
double r58510 = cos(r58506);
double r58511 = r58509 - r58510;
double r58512 = log(r58511);
double r58513 = exp(r58512);
double r58514 = sqrt(r58513);
double r58515 = sin(r58506);
double r58516 = r58514 / r58515;
double r58517 = sqrt(r58511);
double r58518 = r58516 * r58517;
double r58519 = 0.020771119462007017;
bool r58520 = r58506 <= r58519;
double r58521 = 0.041666666666666664;
double r58522 = 3.0;
double r58523 = pow(r58506, r58522);
double r58524 = 0.004166666666666667;
double r58525 = 5.0;
double r58526 = pow(r58506, r58525);
double r58527 = 0.5;
double r58528 = r58527 * r58506;
double r58529 = fma(r58524, r58526, r58528);
double r58530 = fma(r58521, r58523, r58529);
double r58531 = pow(r58509, r58522);
double r58532 = pow(r58510, r58522);
double r58533 = r58531 - r58532;
double r58534 = exp(r58533);
double r58535 = log(r58534);
double r58536 = r58509 + r58510;
double r58537 = r58510 * r58536;
double r58538 = fma(r58509, r58509, r58537);
double r58539 = r58515 * r58538;
double r58540 = r58535 / r58539;
double r58541 = r58520 ? r58530 : r58540;
double r58542 = r58508 ? r58518 : r58541;
return r58542;
}




Bits error versus x
| Original | 30.4 |
|---|---|
| Target | 0.0 |
| Herbie | 0.6 |
if x < -0.023647737046597096Initial program 0.9
rmApplied add-log-exp1.0
rmApplied add-exp-log1.1
rmApplied *-un-lft-identity1.1
Applied add-sqr-sqrt1.2
Applied times-frac1.3
Applied exp-prod1.3
Applied log-pow1.2
Simplified1.1
if -0.023647737046597096 < x < 0.020771119462007017Initial program 60.0
Taylor expanded around 0 0.0
Simplified0.0
if 0.020771119462007017 < x Initial program 0.9
rmApplied flip3--1.1
Applied associate-/l/1.1
Simplified1.1
rmApplied add-log-exp1.1
Applied add-log-exp1.1
Applied diff-log1.2
Simplified1.1
Final simplification0.6
herbie shell --seed 2019326 +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)))