\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
t_0 := {x}^{-2} \cdot \cos x\\
\mathbf{if}\;x \leq -0.00485777750271224:\\
\;\;\;\;\mathsf{fma}\left(1, {x}^{-2}, -t_0\right) + \mathsf{fma}\left(-{x}^{-2}, \cos x, t_0\right)\\
\mathbf{elif}\;x \leq 4.021636854798944 \cdot 10^{-12}:\\
\;\;\;\;\mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\tan \left(\frac{x}{2}\right) \cdot \left({x}^{-2} \cdot \sin x\right)\\
\end{array}
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x)
:precision binary64
(let* ((t_0 (* (pow x -2.0) (cos x))))
(if (<= x -0.00485777750271224)
(+ (fma 1.0 (pow x -2.0) (- t_0)) (fma (- (pow x -2.0)) (cos x) t_0))
(if (<= x 4.021636854798944e-12)
(fma x (* x -0.041666666666666664) 0.5)
(* (tan (/ x 2.0)) (* (pow x -2.0) (sin x)))))))double code(double x) {
return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
double t_0 = pow(x, -2.0) * cos(x);
double tmp;
if (x <= -0.00485777750271224) {
tmp = fma(1.0, pow(x, -2.0), -t_0) + fma(-pow(x, -2.0), cos(x), t_0);
} else if (x <= 4.021636854798944e-12) {
tmp = fma(x, (x * -0.041666666666666664), 0.5);
} else {
tmp = tan((x / 2.0)) * (pow(x, -2.0) * sin(x));
}
return tmp;
}



Bits error versus x
if x < -0.00485777750271223965Initial program 1.0
Applied egg-rr0.5
if -0.00485777750271223965 < x < 4.0216368547989441e-12Initial program 62.7
Taylor expanded in x around 0 0.0
Simplified0.0
if 4.0216368547989441e-12 < x Initial program 2.4
Applied egg-rr1.2
Taylor expanded in x around inf 1.2
Simplified0.9
Applied egg-rr0.2
Final simplification0.2
herbie shell --seed 2022130
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))