Avoid Loss of significance error I want to compute $f(x)$to avoid loss of significance$$f(x)=\frac{1-\cos x}{x^2}$$
One way is writing Taylor series approximation for $\cos x$ about $x=0$. what about this approach:
$$f(x)=\frac{2\sin^2(\frac x2)}{x^2}$$
Is this ok ?

Better than Taylor series would be the $[2n,2n]$ Padé approximants. Foe example, for $n=2$ you will have
$$f(x)=\frac{1-\cos (x)}{x^2}\sim\frac {65520-3780 x^2+59 x^4 } {131040+3360 x^2+34 x^4 } $$ Compared to a Taylor expansion, the difference is
$$\text{Padé- Taylor}=\frac{127 }{87178291200}x^{10}+O\left(x^{12}\right)$$
For example, for $x=10^{-6}$, the difference between the exact and approximated values is $1.46\times 10^{-69}$.
Using the next approximant $(n=3)$,it would be
$$f(x)=\frac{1-\cos (x)}{x^2}\sim\frac {5491886400-346666320 x^2+7038360 x^4-45469 x^6} {24(457657200+9249240 x^2+86030 x^4+389 x^6 )} $$ Compared to a Taylor expansion, the difference is
$$\text{Padé- Taylor}=\frac{11321 }{438437062103040000}x^{14}+O\left(x^{16}\right)$$
For example, for $x=10^{-6}$, the difference between the exact and approximated values is $2.58\times 10^{-98}$.
