I am trying to compute the integral$$\int_{-\infty}^{\infty}\frac{x-\sin x}{x^3}\,dx$$
Let $f(z)=\dfrac{z-\sin z}{z^3}$. I tried to integrate this along a semi-circular contour in the upper half plane, taking the radius to $\infty$, but the $\sin z$ term explodes along the circular arc. I then thought about a rectangular contour, but then the vertical contours on the sides do not give a very nice expression.
(By the way, $f(z)$ has no singularities.)
What contour should I choose? How can you decide this will work when approaching the problem to start with?
I have put this answer together from the hint by @DanielFischer:
First consider $$I_1=\oint_{\gamma} \frac{z-\frac1{2i}e^{iz}}{z^3}\,dz$$ where $\gamma$ is a closed contour in the upper half plane, with $4$ pieces:
The function in the integrand has a pole of order $3$ at $z=0$. The residue here is $$\begin{align}\mathop{\text{res}}_{z=0}(f(z))&=\frac1{2!}\frac{d^2}{dz^2}\left(z-\frac1{2i}e^{iz}\right)|_{z=0}\\&=\frac1{4i}\end{align}$$Then $$\int_{\gamma_\epsilon}\frac{z-\frac1{2i}e^{iz}}{z^3}\,dz=-i\pi\cdot\mathop{\text{res}}_{z=0}\left(\frac{z-\frac1{2i}e^{iz}}{z^3}\right)=-\frac\pi4$$ Here, the minus sign comes since $\gamma_\epsilon$ is clockwise. It can be shown that $\int_{\gamma_R} \frac{z-\frac1{2i}e^{iz}}{z^3}\,dz\to0$ as $R\to\infty$.
Next consider $$I_2=\oint_{\gamma} \frac{e^{-iz}}{2iz^3}\,dz$$ where this time, $\gamma$ is a closed contour in the lower half plane with $4$ pieces as above (but reflected in the $\Re$-axis). This also has a pole of order $3$ at $0$. It can be shown in a similar way to above that the residue here is $-\frac1{4i}$. Again, we get that along the radius-$\epsilon$ contour, this integral evaluates to $-\frac1{4i}$, since the residue changes sign, and the orientation of the contour changes to anticlockwise. Also, the integral along the radius-$R$ contour goes to $0$ too.
Putting this all together, $$I_1+I_2=0\\\int_{-\infty}^\infty \frac{x-\frac1{2i}e^{ix}}{x^3}\,dx-\frac\pi4+\int_{-\infty}^\infty \frac{e^{-ix}}{2ix^3}\,dx-\frac\pi4=0\\\implies\int_{-\infty}^{\infty}\frac{x-\sin x}{x^3}\,dx=\frac\pi2$$which agrees with @JackD'Aurizio and @Dr.SonnhardGraubner 's results.