You don't need to invent anything when dealing with a continuous angle sensor.
It's already been invented.
The IEEEremainder function (supported in Java and C++) can take any angle and convert it to the range -180 to +180
You can also use it to find the shortest angle (magnitude
and sign) between a setpoint and a process variable.