\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.023254737060871069620482387563242809847:\\
\;\;\;\;\frac{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}{\frac{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}{1 - \cos x}}\\
\mathbf{elif}\;x \le 0.02350362276191214974674359439177351305261:\\
\;\;\;\;\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{{1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left({\left(\cos x\right)}^{3}\right)\right)}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \frac{1 \cdot 1 - {\left(\cos x\right)}^{2}}{1 - \cos x}\right)}\\
\end{array}double f(double x) {
double r63687 = 1.0;
double r63688 = x;
double r63689 = cos(r63688);
double r63690 = r63687 - r63689;
double r63691 = sin(r63688);
double r63692 = r63690 / r63691;
return r63692;
}
double f(double x) {
double r63693 = x;
double r63694 = -0.02325473706087107;
bool r63695 = r63693 <= r63694;
double r63696 = 1.0;
double r63697 = r63696 * r63696;
double r63698 = cos(r63693);
double r63699 = r63698 * r63698;
double r63700 = r63696 * r63698;
double r63701 = r63699 + r63700;
double r63702 = r63697 + r63701;
double r63703 = sin(r63693);
double r63704 = r63696 + r63698;
double r63705 = r63698 * r63704;
double r63706 = fma(r63696, r63696, r63705);
double r63707 = r63703 * r63706;
double r63708 = r63696 - r63698;
double r63709 = r63707 / r63708;
double r63710 = r63702 / r63709;
double r63711 = 0.02350362276191215;
bool r63712 = r63693 <= r63711;
double r63713 = 0.041666666666666664;
double r63714 = 3.0;
double r63715 = pow(r63693, r63714);
double r63716 = 0.004166666666666667;
double r63717 = 5.0;
double r63718 = pow(r63693, r63717);
double r63719 = 0.5;
double r63720 = r63719 * r63693;
double r63721 = fma(r63716, r63718, r63720);
double r63722 = fma(r63713, r63715, r63721);
double r63723 = pow(r63696, r63714);
double r63724 = pow(r63698, r63714);
double r63725 = log1p(r63724);
double r63726 = expm1(r63725);
double r63727 = r63723 - r63726;
double r63728 = 2.0;
double r63729 = pow(r63698, r63728);
double r63730 = r63697 - r63729;
double r63731 = r63730 / r63708;
double r63732 = r63698 * r63731;
double r63733 = fma(r63696, r63696, r63732);
double r63734 = r63703 * r63733;
double r63735 = r63727 / r63734;
double r63736 = r63712 ? r63722 : r63735;
double r63737 = r63695 ? r63710 : r63736;
return r63737;
}




Bits error versus x
| Original | 30.3 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.02325473706087107Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied difference-cubes1.0
Applied associate-/l*1.0
if -0.02325473706087107 < x < 0.02350362276191215Initial program 60.0
Taylor expanded around 0 0.0
Simplified0.0
if 0.02350362276191215 < x Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied expm1-log1p-u1.0
rmApplied flip-+1.0
Simplified1.0
Final simplification0.5
herbie shell --seed 2019303 +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)))