(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x)
:precision binary64
(if (<= x -0.0025)
(* (tan (/ x 2.0)) (/ (sin x) (* x x)))
(if (<= x 1e-90)
(fma
x
(* x -0.041666666666666664)
(fma 0.001388888888888889 (pow x 4.0) 0.5))
(* (/ (pow (sin x) 2.0) x) (/ (/ 1.0 (exp (log1p (cos x)))) x)))))double code(double x) {
return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
double tmp;
if (x <= -0.0025) {
tmp = tan((x / 2.0)) * (sin(x) / (x * x));
} else if (x <= 1e-90) {
tmp = fma(x, (x * -0.041666666666666664), fma(0.001388888888888889, pow(x, 4.0), 0.5));
} else {
tmp = (pow(sin(x), 2.0) / x) * ((1.0 / exp(log1p(cos(x)))) / x);
}
return tmp;
}
function code(x) return Float64(Float64(1.0 - cos(x)) / Float64(x * x)) end
function code(x) tmp = 0.0 if (x <= -0.0025) tmp = Float64(tan(Float64(x / 2.0)) * Float64(sin(x) / Float64(x * x))); elseif (x <= 1e-90) tmp = fma(x, Float64(x * -0.041666666666666664), fma(0.001388888888888889, (x ^ 4.0), 0.5)); else tmp = Float64(Float64((sin(x) ^ 2.0) / x) * Float64(Float64(1.0 / exp(log1p(cos(x)))) / x)); end return tmp end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -0.0025], N[(N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision] * N[(N[Sin[x], $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1e-90], N[(x * N[(x * -0.041666666666666664), $MachinePrecision] + N[(0.001388888888888889 * N[Power[x, 4.0], $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / x), $MachinePrecision] * N[(N[(1.0 / N[Exp[N[Log[1 + N[Cos[x], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \leq -0.0025:\\
\;\;\;\;\tan \left(\frac{x}{2}\right) \cdot \frac{\sin x}{x \cdot x}\\
\mathbf{elif}\;x \leq 10^{-90}:\\
\;\;\;\;\mathsf{fma}\left(x, x \cdot -0.041666666666666664, \mathsf{fma}\left(0.001388888888888889, {x}^{4}, 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{\sin x}^{2}}{x} \cdot \frac{\frac{1}{e^{\mathsf{log1p}\left(\cos x\right)}}}{x}\\
\end{array}



Bits error versus x
if x < -0.00250000000000000005Initial program 1.2
Applied egg-rr1.2
Taylor expanded in x around inf 1.2
Applied egg-rr0.9
if -0.00250000000000000005 < x < 9.99999999999999995e-91Initial program 62.9
Taylor expanded in x around 0 0.0
Simplified0.0
if 9.99999999999999995e-91 < x Initial program 14.2
Applied egg-rr0.9
Applied egg-rr0.5
Applied egg-rr0.5
Final simplification0.4
herbie shell --seed 2022166
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))