I have a variable that holds an angle, in degrees, which can be both positive and negative. I now need to make sure that this number is between 0 and 360 only. The number is a double.
What would a nice algorithm for doing that be? Simply doing angle % 360 does not work, because negative numbers end up still being negative. Bonus points to the smallest algorithm (aka, Code Golf).
EDIT
Apparently this is different in different languages. In ActionScript and JavaScript, modulo will return a number between +m and -m:
(-5) % 360 = -5