How to evaluate these improper integrals (if they’re even possible)? I’m trying to evaluate the following two integrals: $$\int\limits_{-\infty}^\infty\frac{e^{-x^2}\cos(x)}{1+x^2}\,dx$$
and
$$\int\limits_{-\infty}^\infty\frac{e^{x^2}\cos(x)}{1+x^2}dx.$$
The first one I know is convergent (from wolframalpha) but I cannot calculate its value.
The second one i suspect to be divergent since the integrand oscillates a lot, but maybe you can find some sort of symmetry in it where things cancel out each other.
I’ve tried looking at some complex contour integrals along for example a semicircle closed by the real axis to be able to make use of the residue theorem, but I always end up with the integral being divergent on some part of the curve. I think a different approach is needed.
 A: Reference... Item 3.945.2 in G&R:
Gradshteyn, I. S.; Ryzhik, I. M.; Zwillinger, Daniel (ed.); Moll, Victor (ed.), Table of integrals, series, and products. Translated from the Russian. Translation edited and with a preface by Victor Moll and Daniel Zwillinger, Amsterdam: Elsevier/Academic Press (ISBN 978-0-12-384933-5/hbk; 978-0-12-384934-2/ebook). xlv, 1133 p. (2015). ZBL1300.65001.
\begin{align}
&\int_{0}^\infty \frac{e^{-\beta x^2}\cos (ax)}{x^2+\gamma^2}\;dx 
\\ &=
\frac{\pi e^{\beta\gamma^2}}{4\gamma}\left[2\cosh(a\gamma)+
e^{-a\gamma}\Phi\left(-\gamma\sqrt{\beta}+\frac{a}{2\sqrt{\beta}}\right)
-e^{a\gamma}\Phi\left(\gamma\sqrt{\beta}+\frac{a}{2\sqrt{\beta}}\right)
\right],
\\
&\qquad \text{Re }\beta > 0, \text{Re }\gamma > 0, a > 0 .
\end{align}
Note that $\int_{-\infty}^\infty = 2 \int_0^\infty$; plug in $\beta=1, \gamma=1, a=1$; recall the notation $\Phi = \text{erf}$.  We then get
$$
\int_{-\infty}^\infty \frac{e^{-x^2}\cos x}{x^2+1}\;dx =
-\frac{\pi}{2}\, \left( {{\rm e}^{2}}{\rm erf} \left(3/2\right)-{{\rm e}^{2
}}+{\rm erf} \left(1/2\right)-1 \right) 
$$
