According to Google Calculator (-13) % 64 is 51.
(-13) % 64
51
According to Javascript (see this JSBin) it is -13.
-13
How do I fix this
So it seems that if you're trying to mod around degrees (so that if you have -50 degrees - 200 degrees), you'd want to use something like:
function modrad(m) { return ((((180+m) % 360) + 360) % 360)-180; }