\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;x \le -0.0133795329351141800700020212389063090086:\\
\;\;\;\;\frac{\sin x \cdot \left(1 - \cos x\right)}{\sin x \cdot \sin x}\\
\mathbf{elif}\;x \le 0.02120826393528481637607008281065645860508:\\
\;\;\;\;0.04166666666666667129259593593815225176513 \cdot {x}^{3} + \left(0.004166666666666666608842550800773096852936 \cdot {x}^{5} + 0.5 \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{\frac{1}{\sin x} - \cos x \cdot \frac{1}{\sin x}}\right)\\
\end{array}double f(double x) {
double r59031 = 1.0;
double r59032 = x;
double r59033 = cos(r59032);
double r59034 = r59031 - r59033;
double r59035 = sin(r59032);
double r59036 = r59034 / r59035;
return r59036;
}
double f(double x) {
double r59037 = x;
double r59038 = -0.01337953293511418;
bool r59039 = r59037 <= r59038;
double r59040 = sin(r59037);
double r59041 = 1.0;
double r59042 = cos(r59037);
double r59043 = r59041 - r59042;
double r59044 = r59040 * r59043;
double r59045 = r59040 * r59040;
double r59046 = r59044 / r59045;
double r59047 = 0.021208263935284816;
bool r59048 = r59037 <= r59047;
double r59049 = 0.04166666666666667;
double r59050 = 3.0;
double r59051 = pow(r59037, r59050);
double r59052 = r59049 * r59051;
double r59053 = 0.004166666666666667;
double r59054 = 5.0;
double r59055 = pow(r59037, r59054);
double r59056 = r59053 * r59055;
double r59057 = 0.5;
double r59058 = r59057 * r59037;
double r59059 = r59056 + r59058;
double r59060 = r59052 + r59059;
double r59061 = r59041 / r59040;
double r59062 = 1.0;
double r59063 = r59062 / r59040;
double r59064 = r59042 * r59063;
double r59065 = r59061 - r59064;
double r59066 = exp(r59065);
double r59067 = log(r59066);
double r59068 = r59048 ? r59060 : r59067;
double r59069 = r59039 ? r59046 : r59068;
return r59069;
}




Bits error versus x
Results
| Original | 29.7 |
|---|---|
| Target | 0.0 |
| Herbie | 0.5 |
if x < -0.01337953293511418Initial program 0.9
rmApplied div-sub1.1
rmApplied frac-sub1.1
Simplified1.0
if -0.01337953293511418 < x < 0.021208263935284816Initial program 59.7
rmApplied div-sub59.8
Taylor expanded around 0 0.0
if 0.021208263935284816 < x Initial program 0.9
rmApplied div-sub1.1
rmApplied add-log-exp1.3
Applied add-log-exp1.3
Applied diff-log1.3
Simplified1.2
rmApplied div-inv1.2
Final simplification0.5
herbie shell --seed 2019344
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))