\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0195414650842071873:\\
\;\;\;\;\frac{1 - \cos x}{\sin x}\\
\mathbf{elif}\;x \le 0.023267676544555443:\\
\;\;\;\;\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{{e}^{\left(\log \left(1 - \cos x\right)\right)}}{\sin x}\\
\end{array}double f(double x) {
double r138614 = 1.0;
double r138615 = x;
double r138616 = cos(r138615);
double r138617 = r138614 - r138616;
double r138618 = sin(r138615);
double r138619 = r138617 / r138618;
return r138619;
}
double f(double x) {
double r138620 = x;
double r138621 = -0.019541465084207187;
bool r138622 = r138620 <= r138621;
double r138623 = 1.0;
double r138624 = cos(r138620);
double r138625 = r138623 - r138624;
double r138626 = sin(r138620);
double r138627 = r138625 / r138626;
double r138628 = 0.023267676544555443;
bool r138629 = r138620 <= r138628;
double r138630 = 0.041666666666666664;
double r138631 = 3.0;
double r138632 = pow(r138620, r138631);
double r138633 = 0.004166666666666667;
double r138634 = 5.0;
double r138635 = pow(r138620, r138634);
double r138636 = 0.5;
double r138637 = r138636 * r138620;
double r138638 = fma(r138633, r138635, r138637);
double r138639 = fma(r138630, r138632, r138638);
double r138640 = exp(1.0);
double r138641 = log(r138625);
double r138642 = pow(r138640, r138641);
double r138643 = r138642 / r138626;
double r138644 = r138629 ? r138639 : r138643;
double r138645 = r138622 ? r138627 : r138644;
return r138645;
}




Bits error versus x
| Original | 30.1 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.019541465084207187Initial program 0.9
rmApplied add-exp-log0.9
rmApplied pow10.9
Applied log-pow0.9
Applied exp-prod0.9
Simplified0.9
rmApplied *-un-lft-identity0.9
Applied log-prod0.9
Applied unpow-prod-up0.9
Simplified0.9
Simplified0.9
if -0.019541465084207187 < x < 0.023267676544555443Initial program 60.0
Taylor expanded around 0 0.0
Simplified0.0
if 0.023267676544555443 < x Initial program 0.9
rmApplied add-exp-log0.9
rmApplied pow10.9
Applied log-pow0.9
Applied exp-prod1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2020047 +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)))