Dealing with Angle Wrap in c++ code
===

So a question I often ask myself is:

Is there a way to safety and simply deal with angle wrap with the minimum number of case statements. 

Angle wrap occurs when using a particular representation for angle (either 0-360 deg or -180 - 180 deg (or equivalent in radians)) and you wrap over the angle. For example say you have an angle of -170, and you subtract 50 deg. You mathematically add up to -220 but should actually be +140 deg.

Obviously you can check for this using:

    if (deg < -180) { 180 - abs(deg + 180); }

or similar. But firstly you need multitudes of checks and secondly it doesn't work if you wrap twice. 

I have heard of a good way to get around this using complex number multiplication/subtraction but I have not been able to find any evidence of it. 

I would appreciate any methods that are suggested, what sort of things have people come up with to handle this very common problem?

Cheers

Ben