How to evaluate the integral $\int\frac{\sin x+\cos x}{|\sin x+\cos x|}dx$? When I was trying to solve the integral $\int\frac{\sin x+\cos x}{\sqrt{1+\sin2x}}dx$ by using $(1+\sin2x)=(\sin x+\cos x)^2$, I obtained this integral 
$\int\frac{\sin x+\cos x}{|\sin x+\cos x|}dx$ where $|\cdot|$ is the absolute value function. If this problem were a definite integral then I would have simplified the denominator by removing the absolute value function. But here it's an indefinite integral. So, how to proceed further?
In my book, the integral $\int\frac{\sin x+\cos x}{\sqrt{1+\sin2x}}dx$ was solved by expressing the denominator of the integrand as $\sqrt{2-(\sin x-\cos x)^2}$ and then using the method of substitution $t=(\sin x-\cos x)$, $dt=(\sin x+\cos x)dx$ and so on. I totally understood this method but I'm interested in solving the integral $\int\frac{\sin x+\cos x}{|\sin x+\cos x|}dx$ to obtain the final result. 
The final result obtained by the method outlined in the book is $\sin^{-1}\sin(x-\pi/4)+C$. It would be helpful if you could explain how to obtain this result by evaluating the integral in the question.
 A: Use the identity $\sin(x)+\cos(x) = \sqrt{2}\sin\left(x+\frac{\pi}{4}\right) = \sqrt{2}\cos\left(x-\frac{\pi}{4}\right)$ to get that
$$\frac{\sin(x)+\cos(x)}{|\sin(x)+\cos(x)|} = \operatorname{sgn}\left(\sin\left(x+\frac{\pi}{4}\right)\right)$$
We can find its antiderivative graphically, it is a triangle wave with crests/troughs at $x = k\pi - \frac{\pi}{4}$ for $k\in\mathbb{Z}$. The triangles have slope $\pm 1$ and can be elevated by any arbitrary constant $C$.
A: I'll convert my comment into an answer with more details.
One can have
$$\int\frac{\sin x+\cos x}{|\sin x+\cos x|}dx=x\times\frac{\sin x+\cos x}{|\sin x+\cos x|}+C$$
You've written the following as an answer :
$$\int\frac{\sin x+\cos x}{|\sin x+\cos x|}dx=\sin^{-1}\bigg(\sin\bigg(x-\frac{\pi}{4}\bigg)\bigg)+C$$
For $m\in\mathbb Z$, we have
$$\begin{align}&x\times\frac{\sin x+\cos x}{|\sin x+\cos x|}
\\\\&=\begin{cases}x&\text{if $\quad\sin x+\cos x\gt 0$}\\ -x&\text{if $\quad\sin x+\cos x\lt 0$}\end{cases}
\\\\&=\begin{cases}x&\text{if $\quad 2m\pi-\frac{\pi}{4}\lt x\lt 2m\pi+\frac{3}{4}\pi$}\\ -x&\text{if $\quad 2m\pi-\frac{5}{4}\pi\lt x\lt 2m\pi -\frac{\pi}{4}$}\end{cases}
\\\\&=\begin{cases}(x-\frac{\pi}{4})-2m\pi+\frac{\pi}{4}+2m\pi&\text{if $\quad 2m\pi-\frac{\pi}{4}\lt x\lt 2m\pi+\frac{3}{4}\pi$}\\ -(x-\frac{\pi}{4})+(2m-1)\pi-\frac{\pi}{4}-(2m-1)\pi&\text{if $\quad 2m\pi-\frac{5}{4}\pi\lt x\lt 2m\pi -\frac{\pi}{4}$}\end{cases}
\\\\&=\begin{cases}\sin^{-1}(\sin(x-\frac{\pi}{4}))+\frac{\pi}{4}+2m\pi&\text{if $\quad 2m\pi-\frac{\pi}{4}\lt x\lt 2m\pi+\frac{3}{4}\pi$}\\ \sin^{-1}(\sin(x-\frac{\pi}{4}))-\frac{\pi}{4}-(2m-1)\pi&\text{if $\quad 2m\pi-\frac{5}{4}\pi\lt x\lt 2m\pi -\frac{\pi}{4}$}\end{cases}
\\\\&=\sin^{-1}\bigg(\sin\bigg(x-\frac{\pi}{4}\bigg)\bigg)+(\text{constant})\end{align}$$
A: Hint: notice, that if you place $t=\sin{x} + \cos{x}$, the integrated function becomes $\frac{t}{|t|}=sign(t)$. Since integral is just an area under function, we need to have limits provided.
A: Hint:
The integrand will be undefined if $\sin x+\cos x=0$
$$|\sin x+\cos x|=\sqrt2\left|\cos\left(x-\dfrac\pi4\right)\right|=\begin{cases} (\sin x+\cos x)&\mbox{if } \cos\left(x-\dfrac\pi4\right)\ge0 \\
-(\sin x+\cos x) & \mbox{if } \cos\left(x-\dfrac\pi4\right)<0 \end{cases} $$
Now $\cos\left(x-\dfrac\pi4\right)\ge0$ if $2m\pi-\dfrac\pi2\le x-\dfrac\pi4\le2m\pi+\dfrac\pi2\iff2m\pi-\dfrac\pi4\le x\le 2m\pi+\dfrac{3\pi}4$
