I've tried to resolve an exercise and at some point I have to compare the integral : $ \int_{0}^{\infty} f(x) \, \mathrm{d}x $
with the series : $ \sum_{k=0}^{n-1} \int_{k\pi}^{(k+1)\pi} f(x) \, \mathrm{d}x $
in order to figure out if the integral converges or not.
In the exercise, we have $f(x) \geq 0$, and it's explained that as $f(x) \geq 0$ the series converges $\iff$ the integral converges.
But actually, I can't figure out why $f$ must have a constant sign, because maybe what I'm gonna written is absolutely wrong, but I want to say : $ \int_{0}^{n\pi} f(x) \, \mathrm{d}x = \sum_{k=0}^{n-1} \int_{k\pi}^{(k+1)\pi} f(x) \, \mathrm{d}x $, and so : $\lim\limits_{n \rightarrow +\infty} \int_{0}^{n\pi} f(x) \, \mathrm{d}x = \lim\limits_{n \rightarrow +\infty} \sum_{k=0}^{n-1} \int_{k\pi}^{(k+1)\pi} f(x) \, \mathrm{d}x $
whatever the sign of $f$, and then both the series and the integral have the same nature (convergent of divergent).
So, where is the mistake ?