\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.02408789324737697218337117988085083197802:\\
\;\;\;\;\frac{1}{\frac{\sin x}{\mathsf{expm1}\left(\mathsf{log1p}\left(1 - \cos x\right)\right)}}\\
\mathbf{elif}\;x \le 0.02070648332399807264869728840039897477254:\\
\;\;\;\;\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} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}\\
\end{array}double f(double x) {
double r66918 = 1.0;
double r66919 = x;
double r66920 = cos(r66919);
double r66921 = r66918 - r66920;
double r66922 = sin(r66919);
double r66923 = r66921 / r66922;
return r66923;
}
double f(double x) {
double r66924 = x;
double r66925 = -0.024087893247376972;
bool r66926 = r66924 <= r66925;
double r66927 = 1.0;
double r66928 = sin(r66924);
double r66929 = 1.0;
double r66930 = cos(r66924);
double r66931 = r66929 - r66930;
double r66932 = log1p(r66931);
double r66933 = expm1(r66932);
double r66934 = r66928 / r66933;
double r66935 = r66927 / r66934;
double r66936 = 0.020706483323998073;
bool r66937 = r66924 <= r66936;
double r66938 = 0.041666666666666664;
double r66939 = 3.0;
double r66940 = pow(r66924, r66939);
double r66941 = 0.004166666666666667;
double r66942 = 5.0;
double r66943 = pow(r66924, r66942);
double r66944 = 0.5;
double r66945 = r66944 * r66924;
double r66946 = fma(r66941, r66943, r66945);
double r66947 = fma(r66938, r66940, r66946);
double r66948 = pow(r66929, r66939);
double r66949 = pow(r66930, r66939);
double r66950 = pow(r66949, r66939);
double r66951 = cbrt(r66950);
double r66952 = r66948 - r66951;
double r66953 = r66929 + r66930;
double r66954 = r66930 * r66953;
double r66955 = fma(r66929, r66929, r66954);
double r66956 = r66928 * r66955;
double r66957 = r66952 / r66956;
double r66958 = r66937 ? r66947 : r66957;
double r66959 = r66926 ? r66935 : r66958;
return r66959;
}




Bits error versus x
| Original | 29.9 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.024087893247376972Initial program 0.9
rmApplied clear-num1.0
rmApplied expm1-log1p-u1.1
if -0.024087893247376972 < x < 0.020706483323998073Initial program 59.8
Taylor expanded around 0 0.0
Simplified0.0
if 0.020706483323998073 < x Initial program 0.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 2019323 +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)))