I drew a rough sketch of $|\cos x|$ and would guess the correct answer to this integral is $4$ because I know the area under the curve of $\cos x$ from $0$ to $\pi/2$ is $1$, and there are $4$ such areas under $|\cos x|$ between $0$ and $2\pi$.
So if I rewrite the integral as ($4$ $\times$ integral from $0$ to $\pi/2$ $|\cos x|\operatorname{d}x$) I get the answer I expect. What I don't understand is why this evaluates correctly when the original form does not. Does it have something to do with the antiderivative of an absolute trig function? I've been saying it's $|\sin x|$ in this case - is this actually incorrect?
What is it that I need to look out for in cases like this?