I have an angle and I need to return a representative angle in the range [-180:180].
I have written a function to do this but it seems such a simple process, I was wondering if there was an operator or function that already did this:
int func(int angle){
angle %= 360;
if(angle > 180){
angle -=360;
}else if(angle < -180){
angle += 360;
}
return angle;
}
I've made a live example for testing expected functionality.
return std::remainder(angle, 180);
? – Baumanremainder(-190, 180)
is -10. – Murremainder(angle, 360.0)
is the solution. Which is available in both C++ and C, so I'm planning on leaving both tags. – Murremainder(angle, 360)
is the solution. – Mur