This question is closely related to one I just asked here. I believe that it is just different enough to warrant another question; please let me know if it does not.
In the question mentioned above, I was informed by Joriki that
$$\int \cos\left(\frac{1}{x}\right) \mathrm{d}x = x \cos\left(\frac{1}{x}\right) + \operatorname{Si}\left(\frac{1}{x}\right)$$
where
$$\mbox{Si}(u) = \int \frac{\sin(u)}{u} \mathrm{d}x$$
is the sine integral. That is all well and good, but...
When I asked the question originally, I was trying to simplify things. The integrand I really should have asked about was $\cos(a/x), a \neq 1$. While undefined at the origin, this integrand is continuous and real on the positive real axis:

A strange thing happens, however, when I integrate. Even along the real axis, there are complex values:

I understand that the trigonometric functions are closely related to imaginary numbers via Euler's formula $\cos(x)=e^{ix}-i\sin(x)$, but I have always been told that the integral is "just the area under the curve."
How can the area under a real valued function be complex?
EDIT
See comments below. The problem was due to a software problem. The actual integral is real on the real-axis. The pretty colored complex-plot above is wrong.
$$ \begin{align} \int_1^x\cos\left(\frac{2\pi}{t}\right)\;\mathrm{d}t &\stackrel{\quad t\to1/t}{=}-\int_{1/x}^1\cos(2\pi t)\;\mathrm{d}\!\!\frac{1}{t}\\ &=x\cos\left(\frac{2\pi}{x}\right)-1-2\pi\int_{1/x}^1\frac{\sin(2\pi t)}{t}\mathrm{d}t\\ &=x\cos\left(\frac{2\pi}{x}\right)-1-2\pi\int_{2\pi/x}^{2\pi}\frac{\sin(t)}{t}\mathrm{d}t\\ &=x\cos\left(\frac{2\pi}{x}\right)-1+2\pi\operatorname{Si}\left(\frac{2\pi}{x}\right)-2\pi\operatorname{Si}(2\pi) \end{align} $$ This is essentially the formula given by Joriki. Everything is real for real $x$. If a computer-aided math program gave you a complex answer, it is a problem with the program. What program are you using? What was the expression you gave to the program?