The integral $\int_0^\infty \dfrac{x \sin(x)}{x^2+1} dx$ How to calculate:
$$\int_0^\infty \frac{x \sin(x)}{x^2+1} dx$$
I thought I should find the integral on the path 
$[-R,R] \cup \{Re^{i \phi} : 0 \leq \phi \leq \pi\}$.
I can easily take the residue in $i$
$$ 
Res_{z=i} \frac{x \sin(x)}{x^2+1} 
\quad = \quad
\frac{i (e^{ii}-e^{-ii})}{2i} 
\quad = \quad
\frac{i(\frac1e-e)}{2i}
\quad = \quad
\frac1{2e}-\frac e2
$$
I know that the integral on $[-R,R]$ will get nearby the real value of $ \frac12\int_0^\infty \frac{x \sin(x)}{x^2+1} dx$. That means that I'm done if I show that the integral on the other part of the path will be small, here is an attempt to do so:
$$
\left|\frac{x \sin(x)}{x^2+1} \right| 
\quad \leq \quad 
R \cdot \frac{|\sin x|}{R^2-1}
$$
I could rewrite $\sin x$ but it becomes nasty. Can you help me with this?
 A: Remember that $\sin x=(\exp(ix)-\exp(-ix))/2i$, and $\exp(-ix)$ grows large in the upper half plane.  You have to integrate the $\exp(ix)$ part in the upper half plane, and the $\exp(-ix)$ in the lower half plane.  
Also, the upper half-plane is $0<\phi<\pi$, not $2\pi$.
The trick of completing the loop does two things.
Firstly, the integral around a loop equals the sum of the residues, which are easy to calculate.  
Secondly, the extra semicircle involves large values of $x$, so the function is very small along the semicircle, and the contribution along the semicircle is negligible.  So, put together, the integral you want - along the diameter - plus the negligible amount along the semicircle, equals the sum of the residues.
So we make some effort to ensure the integral along the semicircle is negligible.
$\exp(iz)=\exp(ix-y)$, so its absolute value is $e^{-y}$.  The upper half plane is fine to integrate $\exp(iz)z/(1+z^2)$.  
But $\exp(-iz)$ has absolute value $e^y$, so contributions will be large in the upper half plane.  We integrate $\exp(-iz)z/(1+z^2)$ in the lower half plane instead.  The integral along the diameter is the same it always was, but the residue is now anticlockwise around $-i$.
A: I will share my work with you and hope that you can tell me if I understood everything well. I used two paths:
$$
\left\{ \begin{array}{ll}
          A \quad = \quad [-R,R] \ \cup \ \{Re^{i\phi} \ : \ 0 \leq \phi \leq \pi\}  \\
          B \quad = \quad[-R,R] \ \cup \ \{Re^{i\phi} \ : \ \pi \leq \phi \leq 2\pi\} \end{array} \right.
$$
I call the upper part of the circle  $U$, end the lower part of the circle $L$. Both $A$ and $B$ will be followed counter clockwiseley. 
I split up the integral as 
$$
-\frac{1}{2}i \left( 
\int_\mathbb{R} \frac{xe^{i \phi}}{x^2+1}dx 
\quad - \quad
\int_\mathbb{R} \frac{xe^{i \phi}}{x^2+1}dx
\right)
$$
Next, I took
$$
\int_A \frac{xe^{i \phi}}{x^2+1}dx  
\quad = \quad 
\int_{-R}^R \frac{xe^{i \phi}}{x^2+1}dx  
\ + \ 
\int_U \frac{xe^{i \phi}}{x^2+1}dx  
$$
On $U$, we have, for high values of $R$
$$
\pi R \cdot \left| \frac{xe^{i \phi}}{x^2+1} \right| 
\ \leq \
\frac{R}{R^2-1} \cdot  \frac{\pi R}{| e^{R \sin \phi}|} 
\ \rightarrow \ 0
$$
because $\sin \phi < 0$ on this part. It's easy to show that the integral on $L$ goes to $0$ as well, so I skip it. 
It can easily be shown that the residue in $i$ equals $\frac{1}{2e}-\frac e2$, and that 
the residue in $-i$ equals $-\frac{1}{2e}+\frac e2$. Now we find:
$$
\int_\mathbb{R}\frac{x \sin x}{x^2+1}dx
\quad = \quad 
2 \int_{\mathbb{R}^+}\frac{x \sin x}{x^2+1}dx
\quad = \quad
2(\frac{1}{2e}-\frac e2)
\quad = \quad 
\frac{1}{e}- e
$$
I hope that someone could check this.
