The fastest way to get current quadrant of an angle

You can use the modulo operation:

angle %= 360.0; // [0..360) if angle is positive, (-360..0] if negative
if (angle < 0) angle += 360.0; // Back to [0..360)
quadrant = (angle/90) % 4 + 1; // Quadrant

Take advantage of integer arithmetics:

angle = angle - (angle/360)*360;
if (angle < 0) angle = angle + 360;

The idea is, since angle/360 is rounded down (floor()), (angle/360) gives you the k you need to do alpha = beta + 360k.

The second line is normalizing from [-359,-1] back to [1,359] if needed.


(angle/90)%4+1

Assumptions:

  1. angle is an integer
  2. angle is positive
  3. / is integer division

For negative angles you'll need some additional handling.