The integral given is
$$\int_{-\infty}^{\infty} \frac{\cos(x)-1}{x^2}\,dx $$
Ok, so, I've used the upper semi circular contour with the function
$$f(z) = \frac{e^{iz}-1}{z^2}$$
Now the residue I get is $i$ which when used with the residue theorem gives me the answer of $-2\pi$ as the answer to the integral of the $f(z)$ and through this I get my answer to the original integral as $-2\pi$. However in the answers to this question the answer states that the solution is $-\pi$. I've double checked with Wolfram Alpha and Wolfram Alpha also gives this as an answer. Can anyone please correct me where I'm going wrong? Thanks.
DonAntonio gave a fine answer (+1) but let's finish too...
Let's start with : \begin{align} \int_{-\infty}^{\infty} \frac{\cos(x)-1}{x^2}\,dx&=2\int_0^{\infty} \frac{\cos(x)-1}{x^2}\,dx\\ &=\int_0^{\infty} \frac{e^{ix}+e^{-ix}-2}{x^2}\,dx\\ &=\lim_{\epsilon\to 0^+}\left[\int_{\epsilon}^{\infty} \frac{e^{ix}-1}{x^2}\,dx+\int_{\epsilon}^{\infty} \frac{e^{-ix}-1}{x^2}\,dx\right]\\ &=PV\int_{-\infty}^{\infty} \frac{e^{ix}-1}{x^2}\,dx\\ \end{align} (we had to replace $0$ by $\epsilon>0$ because of the singular part $\frac 1x$ of the integral at $0$)
Now let's integrate $\displaystyle \frac{e^{iz}-1}{z^2}$ over this contour (with a small circle of radius $\epsilon$ excluding $0$) :
direct link on upper half-disk http://math.fullerton.edu/mathews/c2003/integralsindentedcontour/IntegralsIndentedContourModHome/Images/IntegralsIndentedContourModHome_gr_545.gif
The integral over $C_R$ will go to $0$ as $R\to\;+\infty$ (because $e^{iz}=e^{ix-y}$ with $y\ge 0$) and there is no residue at all in the contour so that we get (supposing $z=\epsilon\;e^{i\theta}$): $$PV\int_{-\infty}^{\infty} \frac{e^{ix}-1}{x^2}\,dx+\lim_{\epsilon\to 0}\int_{\pi}^0 \frac{e^{i\epsilon e^{i\theta}}-1}{\epsilon^2\;e^{2i\theta}}\,\epsilon\;i\;e^{i\theta}\;d\theta=0$$
Use $e^{a\epsilon}=1+a\epsilon+O(\epsilon^2)$ to get $\pi$ in the second integral and conclude !