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



Bits error versus x
Results
if x < -0.03159820685045102Initial program 1.0
rmApplied add-exp-log1.0
if -0.03159820685045102 < x < 0.030296156057222207Initial program 62.2
Taylor expanded around 0 0.0
if 0.030296156057222207 < x Initial program 1.1
rmApplied add-sqr-sqrt1.2
Applied times-frac0.6
rmApplied div-inv0.6
rmApplied flip--0.7
Applied sqrt-div0.7
Applied associate-/l/0.7
Simplified0.7
rmApplied add-exp-log0.7
Final simplification0.4
herbie shell --seed 2020066
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1 (cos x)) (* x x)))