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?
 A: I imagine it happened this way. In the past, someone saw
$$
\sin \frac{\theta}{2} = \pm \sqrt{\frac{1-\cos{\theta}}{2}}
$$
and thought "Wait a minute, this isn't really satisfactory. There shouldn't be uncertainties here. We know what sign the expression should be for a given $\theta$". And indeed,
$$
\sin \frac{\theta}{2} \geqslant 0 \text{ for } 0 \leqslant \theta \leqslant 2\pi \\
\sin \frac{\theta}{2} \leqslant 0 \text{ for } 2\pi \leqslant \theta \leqslant 4\pi
$$
and this pattern is periodic of period $4\pi$. So that someone sat down and thought "What function can I cook up that would give me $+1$ for inputs in $[0,2\pi]$ and $-1$ for inputs in $[2\pi,4\pi]$, and would also be $4\pi$ periodic?". And he found the expression you can see on Wikipedia.
This is not the only way to achieve the same goal. This is not a forced (derived) result. This is an artificial invention, made to achieve a specific goal, and it works. But don't look for a deeper meaning behind it, there isn't any.
A: Personally, I would go with
$$
(-1)^{\left\lfloor\frac\theta{2\pi}\right\rfloor}=\left\{\begin{array}{rl}1&\text{when }\frac\theta{2\pi}\in[0,1)\pmod{2}\\-1&\text{when }\frac\theta{2\pi}\in[1,2)\pmod{2}\end{array}\right.\tag1
$$
However, what was done on Wikipedia was to create a sawtooth wave, which again, I would give as
$$
\frac12-\left\{\frac\theta{4\pi}\right\}\left\{\begin{array}{}\gt0&\text{when }\frac\theta{4\pi}\in\left(0,\frac12\right)\pmod{1}\\\lt0&\text{when }\frac\theta{4\pi}\in\left(\frac12,1\right)\pmod{1}\end{array}\right.\tag2
$$
However, since $\{x\}=x-\lfloor x\rfloor$, $(2)$ can be written as
$$
\frac12-\left\{\frac\theta{4\pi}\right\}=\frac12-\left(\frac\theta{4\pi}-\left\lfloor\frac\theta{4\pi}\right\rfloor\right)\tag3
$$

Note that all three functions have the same sign; negative in the gray regions and positive in the white regions.
The sign in $(3)$ is preserved upon multiplication by $4\pi$:
$$
2\pi-\theta+4\pi\left\lfloor\frac\theta{4\pi}\right\rfloor\tag5
$$
which has the same sign as $(2)$ and is what appears in Wikipedia.
A: The function inside the $\operatorname{sgn}$ function has zeroes only when:
$$\theta=2\pi \pm 4k\pi$$
and the sign alternates between them, which gives the same pattern as the $\sin\frac{\theta}{2}$ function.
A: 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.
