\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.022628612332283863:\\
\;\;\;\;\frac{{1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left({\left(\cos x\right)}^{3}\right)\right)}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}\\
\mathbf{elif}\;x \le 0.02286088640089938:\\
\;\;\;\;\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} - {\left(\cos x\right)}^{2} \cdot \cos x}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}\\
\end{array}double f(double x) {
double r46747 = 1.0;
double r46748 = x;
double r46749 = cos(r46748);
double r46750 = r46747 - r46749;
double r46751 = sin(r46748);
double r46752 = r46750 / r46751;
return r46752;
}
double f(double x) {
double r46753 = x;
double r46754 = -0.022628612332283863;
bool r46755 = r46753 <= r46754;
double r46756 = 1.0;
double r46757 = 3.0;
double r46758 = pow(r46756, r46757);
double r46759 = cos(r46753);
double r46760 = pow(r46759, r46757);
double r46761 = log1p(r46760);
double r46762 = expm1(r46761);
double r46763 = r46758 - r46762;
double r46764 = r46756 * r46759;
double r46765 = fma(r46759, r46759, r46764);
double r46766 = fma(r46756, r46756, r46765);
double r46767 = sin(r46753);
double r46768 = r46766 * r46767;
double r46769 = r46763 / r46768;
double r46770 = 0.02286088640089938;
bool r46771 = r46753 <= r46770;
double r46772 = 0.041666666666666664;
double r46773 = pow(r46753, r46757);
double r46774 = 0.004166666666666667;
double r46775 = 5.0;
double r46776 = pow(r46753, r46775);
double r46777 = 0.5;
double r46778 = r46777 * r46753;
double r46779 = fma(r46774, r46776, r46778);
double r46780 = fma(r46772, r46773, r46779);
double r46781 = 2.0;
double r46782 = pow(r46759, r46781);
double r46783 = r46782 * r46759;
double r46784 = r46758 - r46783;
double r46785 = r46784 / r46768;
double r46786 = r46771 ? r46780 : r46785;
double r46787 = r46755 ? r46769 : r46786;
return r46787;
}




Bits error versus x
| Original | 30.0 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.022628612332283863Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied expm1-log1p-u1.1
if -0.022628612332283863 < x < 0.02286088640089938Initial program 59.9
Taylor expanded around 0 0.0
Simplified0.0
if 0.02286088640089938 < x Initial program 0.9
rmApplied flip3--1.0
Applied associate-/l/1.0
Simplified1.0
rmApplied add-cube-cbrt1.8
Applied unpow-prod-down1.8
Simplified1.3
Simplified1.0
Final simplification0.5
herbie shell --seed 2020065 +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)))