\frac{1 - \cos x}{x \cdot x}\begin{array}{l}
\mathbf{if}\;x \le -0.0349430473850340859:\\
\;\;\;\;\frac{\frac{1}{x} - \cos x \cdot \frac{1}{x}}{x}\\
\mathbf{elif}\;x \le 0.029021184668687444:\\
\;\;\;\;\left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\log \left(e^{1 - \cos x}\right)}{x}}{x}\\
\end{array}double code(double x) {
return ((1.0 - cos(x)) / (x * x));
}
double code(double x) {
double temp;
if ((x <= -0.034943047385034086)) {
temp = (((1.0 / x) - (cos(x) * (1.0 / x))) / x);
} else {
double temp_1;
if ((x <= 0.029021184668687444)) {
temp_1 = (((0.001388888888888889 * pow(x, 4.0)) + 0.5) - (0.041666666666666664 * pow(x, 2.0)));
} else {
temp_1 = ((log(exp((1.0 - cos(x)))) / x) / x);
}
temp = temp_1;
}
return temp;
}



Bits error versus x
Results
if x < -0.034943047385034086Initial program 1.0
rmApplied associate-/r*0.5
rmApplied div-sub0.6
rmApplied div-inv0.6
if -0.034943047385034086 < x < 0.029021184668687444Initial program 62.1
Taylor expanded around 0 0.0
if 0.029021184668687444 < x Initial program 1.0
rmApplied associate-/r*0.5
rmApplied add-log-exp0.6
Applied add-log-exp0.6
Applied diff-log0.6
Simplified0.6
Final simplification0.3
herbie shell --seed 2020053
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1 (cos x)) (* x x)))