5

I'd like to wrap radians between -pi/pi.

This is the actual code I did, which work:

radians > gPIf ? radians - g2PIf : radians < -gPIf ? radians + g2PIf : radians;

But I don't like it too much. Tried with mod, but it seems I've problem with negative values:

std::fmod(radians + gPIf, g2PIf) - gPIf

Is there any "mod" that works also with negative number?

i.e. -20 mod 360 with OS calculator return 340 :)

markzzz
  • 45,272
  • 113
  • 282
  • 475

0 Answers0