Complex contour integral with sign function:$-i \int \limits_{-\infty}^\infty \frac{{\rm sgn}(x)^2 ~x~ e^{i x}}{1+ax^2} dp$ I am trying to evaluate the integral:
$-i \int \limits_{-\infty}^\infty \frac{{\rm sgn}(x)^2 ~x~ e^{i x}}{1+ax^2} dx$
with sgn$(x)$ the sign function and $a$ positive real. Naively applying the residue theorem and pushing the contour around the pole $+i/\sqrt{a}$, I obtain:
$-i \int \limits_{-\infty}^\infty \frac{{\rm sgn}(x)^2 ~x~ e^{i x}}{1+ax^2} dx=-i ~\frac{2\pi i}{a}~{\rm sgn}\left(i/\sqrt{a}\right)^2~\left(\frac{i}{\sqrt{a}}\right) \frac{\sqrt{a}}{2i}~e^{-1/\sqrt{a}}=-\frac{\pi}{a}~e^{-1/\sqrt{a}}$
where I used: ${\rm sgn}\left(i/\sqrt{a}\right)=i~{\rm sgn}\left(1/\sqrt{a}\right)=i$.
However, I know the correct result (and Mathematica agrees) should be just
$-i \int \limits_{-\infty}^\infty \frac{{\rm sgn}(x)^2 ~x~ e^{i x}}{1+ax^2} dx=\frac{\pi}{c}~e^{-1/\sqrt{a}}$
Why do I pick up the extra minus sign? Am I not applying the residue theorem correctly?
Note: this integral is a special case ($n=3$) of the integral I'm actually interested in, namely $-i \int \limits_{-\infty}^\infty \frac{{\rm sgn}(x)^{n-1} ~x^{n-2}~ e^{i x}}{1+ax^2} dx$
 A: Assume $a \gt 0$.  Ignore the $\operatorname{sgn}^2{x}$, as that is identically $1$ almost everywhere, except at $x=0$ (which can be ignored as it is measure zero).  Thus you want to find
$$-i \int_{-\infty}^{\infty} dx \frac{x \, e^{i x}}{1+a x^2}$$
Then consider the integral
$$-i \oint_C dz \frac{z \, e^{i z}}{1+a z^2}$$
where $C$ is a semicircle of radius $R$ in the upper half plane.  The contour integral is equal to
$$-i \int_{-\infty}^{\infty} dx \frac{x \, e^{i x}}{1+a x^2} + R^2 \int_0^{\pi} d\theta\, e^{i 2 \theta} \frac{e^{i R e^{i \theta}}}{1+a R^2 e^{i 2 \theta}}$$
The integral about the semicircle has a magnitude bounded by
$$\frac{2}{a} \int_0^{\pi/2} d\theta \, e^{-R \sin{\theta}} \le \frac{\pi}{a R}$$
as $R \to \infty$.  The contour integral is also equal to, by the residue theorem, $i 2 \pi$ times the residue of the pole at $z=i/\sqrt{a}$.  Then we have
$$-i \int_{-\infty}^{\infty} dx \frac{x \, e^{i x}}{1+a x^2} = i 2 \pi (-i) \frac{ e^{-1/\sqrt{a}}}{2 a} = \frac{\pi}{a} \, e^{-1/\sqrt{a}}$$
