\frac{1 - \cos x}{\sin x}\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.02115882893523894289766751342085626674816 \lor \neg \left(\frac{1 - \cos x}{\sin x} \le 7.646982874077240654179165799120276858503 \cdot 10^{-8}\right):\\
\;\;\;\;\frac{1}{\frac{\sin x}{1 - \cos x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\
\end{array}double f(double x) {
double r54825 = 1.0;
double r54826 = x;
double r54827 = cos(r54826);
double r54828 = r54825 - r54827;
double r54829 = sin(r54826);
double r54830 = r54828 / r54829;
return r54830;
}
double f(double x) {
double r54831 = 1.0;
double r54832 = x;
double r54833 = cos(r54832);
double r54834 = r54831 - r54833;
double r54835 = sin(r54832);
double r54836 = r54834 / r54835;
double r54837 = -0.021158828935238943;
bool r54838 = r54836 <= r54837;
double r54839 = 7.64698287407724e-08;
bool r54840 = r54836 <= r54839;
double r54841 = !r54840;
bool r54842 = r54838 || r54841;
double r54843 = 1.0;
double r54844 = r54835 / r54834;
double r54845 = r54843 / r54844;
double r54846 = 0.041666666666666664;
double r54847 = 3.0;
double r54848 = pow(r54832, r54847);
double r54849 = r54846 * r54848;
double r54850 = 0.004166666666666667;
double r54851 = 5.0;
double r54852 = pow(r54832, r54851);
double r54853 = r54850 * r54852;
double r54854 = 0.5;
double r54855 = r54854 * r54832;
double r54856 = r54853 + r54855;
double r54857 = r54849 + r54856;
double r54858 = r54842 ? r54845 : r54857;
return r54858;
}




Bits error versus x
Results
| Original | 30.3 |
|---|---|
| Target | 0.0 |
| Herbie | 0.8 |
if (/ (- 1.0 (cos x)) (sin x)) < -0.021158828935238943 or 7.64698287407724e-08 < (/ (- 1.0 (cos x)) (sin x)) Initial program 1.0
rmApplied clear-num1.1
if -0.021158828935238943 < (/ (- 1.0 (cos x)) (sin x)) < 7.64698287407724e-08Initial program 59.8
Taylor expanded around 0 0.5
Final simplification0.8
herbie shell --seed 2019303
(FPCore (x)
:name "tanhf (example 3.4)"
:precision binary64
:herbie-expected 2
:herbie-target
(tan (/ x 2))
(/ (- 1 (cos x)) (sin x)))