\frac{1 - \cos x}{x \cdot x}\begin{array}{l}
\mathbf{if}\;x \le -0.0296756945743743734:\\
\;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\
\mathbf{elif}\;x \le 0.03505810655614032:\\
\;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\
\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 VAR;
if ((x <= -0.029675694574374373)) {
VAR = (((1.0 - cos(x)) / x) / x);
} else {
double VAR_1;
if ((x <= 0.03505810655614032)) {
VAR_1 = fma(pow(x, 4.0), 0.001388888888888889, (0.5 - (0.041666666666666664 * pow(x, 2.0))));
} else {
VAR_1 = ((log(exp((1.0 - cos(x)))) / x) / x);
}
VAR = VAR_1;
}
return VAR;
}



Bits error versus x
Results
if x < -0.029675694574374373Initial program 1.1
rmApplied associate-/r*0.5
if -0.029675694574374373 < x < 0.03505810655614032Initial program 62.2
Taylor expanded around 0 0.0
Simplified0.0
if 0.03505810655614032 < x Initial program 1.1
rmApplied associate-/r*0.4
rmApplied add-log-exp0.6
Applied add-log-exp0.6
Applied diff-log0.6
Simplified0.6
Final simplification0.3
herbie shell --seed 2020102 +o rules:numerics
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1 (cos x)) (* x x)))