Mail Archives: djgpp/1997/07/13/02:09:58
T DOT Harte AT btinternet DOT com (Thomas Harte) writes:
>#define degtorad(x) (double)x / 180 * PI
>#define radtodeg(x) (double)x / PI * 180
> . . . although I probably need some brackets, not that I can see where,
>I'm just guessing.
You need them! Suppose you were to write "degtorad (v + 10)" in your
program. The compiler would then see "(double)v + 10 / 180 * PI" which
is not quite what you wanted.
Either use an inline function or something like
#define degtorad(x) ((x) / 180.0 * PI)
Morale, if any: always use parenthesis around macro parameters, unless
you are trying to do something you couldn't do with a function.
Morten
- Raw text -