How to integrate $$\int \sqrt{\cos^{2}(x)}dx$$
I know that $\sqrt{\cos^{2}(x)}=|\cos(x)|$. Therefore $|\cos(x)|=\cos(x)${when $\cos(x)>0$} , $|\cos(x)|=-\cos(x)${when $\cos(x)<0$} , $|\cos(x)|=0${when $\cos(x)=0$} Now when $|\cos(x)|=\cos(x)$, then the result of the above integral will be $$\int \cos(x)dx=\sin(x)+C$$ When $|\cos(x)|=-\cos(x)$, then the result of the above integral will be $$\int -\cos(x)dx=-\sin(x)+C_1$$ And finally, when $|\cos(x)|=0$, then the result of the above integral will be $0$. Therefore, we can clearly see here that $3$ different results are occuring. So, finally I thought of writing $|\cos(x)|=\cos(x)\text{sgn}(\cos(x))$. Therefore, we can write the above integral as
$$\int \sqrt{\cos^{2}(x)}dx$$ $$=\int |\cos(x)|dx$$ $$=\int \cos(x)\text{sgn}(\cos(x))dx$$ Now, I am facing a problem in integrating $$\int \cos(x)\text{sgn}(\cos(x))dx$$ Please help me out with this integral.