Calculating the integral $\int \sqrt{1+\sin x}\, dx$. I want to calculate the integral $\int \sqrt{1+\sin x}\, dx$. 
I have done the following:
\begin{equation*}\int \sqrt{1+\sin x}\, dx=\int \sqrt{\frac{(1+\sin x)(1-\sin x)}{1-\sin x}}\, dx=\int \sqrt{\frac{1-\sin^2 x}{1-\sin x}}\, dx=\int \sqrt{\frac{\cos^2x}{1-\sin x}}\, dx=\int \frac{\cos x}{\sqrt{1-\sin x}}\, dx\end{equation*} 
We substitute $$u=\sqrt{1-\sin x} \Rightarrow du=\frac{1}{2\sqrt{1-\sin x}}\cdot (1-\sin x)'\, dx \Rightarrow du=-\frac{\cos x}{2\sqrt{1-\sin x}}\, dx \\ \Rightarrow  -2\, du=\frac{\cos x}{\sqrt{1-\sin x}}\, dx $$ 
We get the following: 
\begin{equation*}\int \frac{\cos x}{\sqrt{1-\sin x}}\, dx=\int(-2)\, du=-2\cdot \int 1\, du=-2u+c\end{equation*} 
Therefore \begin{equation*}\int \frac{\cos x}{\sqrt{1-\sin x}}\, dx=-2\sqrt{1-\sin x}+c\end{equation*} 
In Wolfram the answer is a different one. What have I done wrong? 
 A: As pointed out by other answers, you need to take signs into consideration. Indeed, starting from your computation we know that
$$ \int \sqrt{1+\sin x} \, dx = \int \frac{\left|\cos x\right|}{\sqrt{1-\sin x}} \, dx $$
Now let $I$ be an interval on which $\cos x$ has the constant sign $\epsilon \in \{1, -1\}$. That is, assume that $\left| \cos x \right| = \epsilon \cos x$ for all $x \in I$. Then
\begin{align*}
\text{on } I \ : \qquad
\int \sqrt{1+\sin x} \, dx
&= \epsilon \int \frac{\cos x}{\sqrt{1-\sin x}} \, dx \\
&= -2\epsilon \sqrt{1-\sin x} + C \\
&= - \frac{2\cos x}{\sqrt{1+\sin x}} + C
\end{align*}
In the last line, we utilized the equality $\cos x = \epsilon \left|\cos x\right| = \epsilon \sqrt{1-\sin^2 x}$.
Notice that maximal choices of $I$ are of the form $I_k := [(k-\frac{1}{2})\pi, (k+\frac{1}{2})\pi]$. So if you want a solution which works on a larger interval, you have to stitch solutions on $I_k$ for different $k$'s together in continuous way. This causes values of $C$ change for different intervals $I_k$. But from the periodicity, it is not terribly hard to describe a global solution and indeed it can be written as
$$
\int \sqrt{1+\sin x} \, dx
= - \frac{2\cos x}{\sqrt{1+\sin x}} + 2\sqrt{2} \left( \left\lceil \frac{x+\frac{\pi}{2}}{2\pi} \right\rceil+ \left\lfloor \frac{x+\frac{\pi}{2}}{2\pi} \right\rfloor \right) + C
$$
The extra term of floor/ceiling function is introduces to compensate jumps of $y=-2\frac{\cos x}{\sqrt{1+\sin x}}$:
$\hspace{2em}$ 
A: Rewrite the given integral using trigonometric/hyperbolic substitutions :
$$\int \sqrt{1+\sin x} dx  ={\displaystyle\int}\sqrt{2}\cos\left(\dfrac{2x-{\pi}}{4}\right)\,\mathrm{d}x$$
Apply the substitution : 
$$u=\dfrac{2x-{\pi}}{4} \to dx = 2du$$
which means the integral becomes equal to :
$$=\class{steps-node}{\cssId{steps-node-1}{2^\frac{3}{2}}}{\displaystyle\int}\cos\left(u\right)\,\mathrm{d}u =2^\frac{3}{2}\sin\left(u\right)$$
Undo now the substitution for $u$ and get :
$$=2^\frac{3}{2}\sin\left(\dfrac{2x-{\pi}}{4}\right)$$
which means that : 
$$\int \sqrt{1+\sin x} dx =2^\frac{3}{2}\sin\left(\dfrac{2x-{\pi}}{4}\right) + C =2\sin\left(\dfrac{x}{2}\right)-2\cos\left(\dfrac{x}{2}\right)+C$$
A: You have $$\begin{equation*}\int \sqrt{1+\sin x}\, dx=\int \sqrt{\frac{(1+\sin x)(1-\sin x)}{1-\sin x}}\, dx=\int \sqrt{\frac{1-\sin^2 x}{1-\sin x}}\, dx=\int \sqrt{\frac{\cos^2x}{1-\sin x}}\, dx=\int \frac{\cos x}{\sqrt{1-\sin x}}\, dx\end{equation*}$$ which is true up to your last equality where you forgot your $\sqrt {cos^2x}=|cos(x)|$ and replaced it with  $\sqrt {cos^2x}=cos(x)$
