Is there a direct formula to transform a set of angles to $-180$ through $180$ deg? For instance, $181$ deg and $541$ deg should be translated to $-179$, while $-182$ deg and $-542$ deg should be translated to $178$. I know that for an angle $X$ which is not on any axis ($0, 90, 270, 360, ...$), when $\text{mod}(a,b)$ is the remainder of division of $a$ by $b$, we can write use $k = \lfloor(\frac{\text{mod}(X,360)}{90})\rfloor$ to determine the quadrant where angle $X$ resides since $k = 0, 1, 2, 3$ corresponds to quadrants $1, 2, 3, 4$ respectively. So for angle $X$:
$k = 0$ or $1$: $\text{mod}(X,360)$ gives the $0$ through $180$ range.
$k = 2$ or $3$: $\text{mod}(X,360)-360$ gives $-180$ through $0$ range.
Is there a way to make this simpler?