So far, I have found two questions on Stackexchange with a similar problem, the most recent is (111297). However, the question is over a year old, and reported as a bug. Nonetheless, the most recent version of Mathematica 11.1.1.0 still gives these sorts of results.
My problem is the integral
Integrate[Cos[x*Pi*j]*E^(-1 + x)^2, {x, x0, x1}]
The domain is always between 0 and 1, though I need some variation for later in the code. This integrand could not be better behaved. I can put all sorts of conditions without success: limits are real, between 0 and 1, upper limit is larger than the lower limit, the $j$ is integer and positive, etc.
No matter what, the answer involves four imaginary error functions. When I use them, I sometimes get tiny imaginary bits, probably from numerical error. Nonetheless, it causes problems later in the code.
Since this problem has been around for a long time, according to the previous questions, does that mean that it will never get fixed? I know that the answer might be technically correct, and that there might be workarounds, but that doesn't mean it isn't a bug.
Chop
when you need them later in the code? $\endgroup$Re[]
at the end if you're sure the result ought to be real-valued anyway. $\endgroup$