<s>[INST] Explanation of formula given on Wikipedia (for sign in half-angle formula for sine) This Wikipedia article listing trigonometric identities, states the following identity under half angles:
$$
\sin{\frac{\theta}{2}} = \text{sgn}\bigg(2\pi-\theta+4\pi\bigg\lfloor\frac{\theta}{4\pi}\bigg\rfloor \bigg)\sqrt{\frac{1-\cos{\theta}}{2}}
$$
where $\text{sgn}(x)$ is a function that returns $+1$ if $x>0$ and $-1$ if $x<0$.
I know and understand the part of the formula that says $\sqrt{\frac{1-\cos{\theta}}{2}}$ and understand the fact that the remaining part is to decide the $\pm$ sign in the formula.
From where, however, does the sign-deciding part of the expression come from? And why should it make sense?
 [/INST] It is from the process of deriving the identity itself.
First, let us use the double-angle formula $\cos2\theta = 2\cos^{2}\theta - 1$. Solving for $\cos^{2}\theta$, we get $$\cos^{2}\theta = \frac{1 + \cos 2\theta}{2}.$$
Replacing $\theta$ by $\frac{\theta}{2}$, we get \begin{align*}\cos^{2}\left(\frac{\theta}{2}\right) &= \frac{1 + \cos\theta}{2} \\ \cos\left(\frac{\theta}{2}\right) &= \pm\sqrt{\frac{1 + \cos\theta}{2}}\end{align*}
Using the identity $\sin^{2}\theta + \cos^{2}\theta = 1$ to get $\sin \frac{\theta}{2}$,
\begin{align*}\sin^{2}\left(\frac{\theta}{2}\right) + \cos^{2}\left(\frac{\theta}{2}\right) &= 1 \\ \sin^{2}\left(\frac{\theta}{2}\right) + \frac{1 + \cos\theta}{2} &= 1 \\ \sin^{2}\left(\frac{\theta}{2}\right) &= 1 - \frac{1 + \cos\theta}{2} \\ \sin^{2}\left(\frac{\theta}{2}\right) &= \frac{2 - 1 - \cos\theta}{2} \\ \sin^{2}\left(\frac{\theta}{2}\right) &= \frac{1 - \cos\theta}{2} \\ \sin\left(\frac{\theta}{2}\right) &= \pm\sqrt{\frac{1 - \cos\theta}{2}}\end{align*}
As you can see, the squares on the equation force it to take the plus-minus sign.

Edit: I don't have an idea about the $\displaystyle \mathrm{sgn}\left(2\pi - \theta + 4\pi\left\lfloor\frac{\theta}{4\pi}\right\rfloor\right)$. I just used the basic ones.
</s>