Complex integration help 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. 
 A: Condensing what you did and comments, define
$$f(z):=\frac{e^{iz}-1}{z^2}\;,\;\;\gamma_r:=\{\,z\in\Bbb C\;;\;z=re^{it}\;,\;t\in(0,\pi)\;,\;r\in\Bbb R_+\,\}$$
and define the path
$$\Gamma_{R,\epsilon}:=[-R,\epsilon]\cup\left(-\gamma_\epsilon\right)\cup[\epsilon,R]\cup\gamma_R\;,\;\;R>>\epsilon>0$$
where $\,-\gamma_r\,$ means the integration path is taken in the clockwise direction (the negative one, thus).
Since the pole at $\,z=0\,$ is simple (why?), we get
$$\text{Re}_{z=0}(f)=\lim_{z\to 0}\,zf(z)\stackrel{\text{l'Hospital}}=ie^0=i$$
so by the lemma and in particular its corollary in an answer here, and by CIT we get
$$2\pi i\cdot i=\oint\limits_{\Gamma_{R,\epsilon}}\,f(z)\,dz\implies$$
$$ -2\pi=\lim_{R\to\infty\,,\,\epsilon\to 0}\left(\int\limits_{-R}^{-\epsilon}\,f(x)dx+\int\limits_{\gamma_\epsilon}f(z)\,dz+\int\limits_\epsilon^Rf(x)\,dx+\int\limits_{\gamma_R}f(z)\,dz\right)=$$
$$=\int\limits_{-\infty}^\infty\frac{\cos x-1+i\sin x}{x^2}dx-\pi $$
And comparing real and imaginary parts you get what you need.
Note: the integral on $\,\gamma_R\,$ vanishes as $\,R\to\infty\,$ either by Jordan's Lemma or directly estimating the integral's modulus.
A: 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 !
