Skip to content

Instantly share code, notes, and snippets.

@dbrockman
Created February 12, 2013 21:52
Show Gist options
  • Save dbrockman/4773781 to your computer and use it in GitHub Desktop.
Save dbrockman/4773781 to your computer and use it in GitHub Desktop.
Convert degrees <-> radians C macros
// Converts degrees to radians.
#define degreesToRadians(angleDegrees) (angleDegrees * M_PI / 180.0)
// Converts radians to degrees.
#define radiansToDegrees(angleRadians) (angleRadians * 180.0 / M_PI)
@AlexandrGraschenkov
Copy link

Will be problem if use like that:
degreesToRadians(10+5)

Suppose change to (with additional brackets):

#define degreesToRadians(angleDegrees) ((angleDegrees) * M_PI / 180.0)
#define radiansToDegrees(angleRadians) ((angleRadians) * 180.0 / M_PI)

Copy link

ghost commented Nov 21, 2018

Elegant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment