[Solved] Why this piece is outputting NAN (Not a Number)?


#define SQUARE(x)  (x*x)

may results in a negative value, e.g.

cout << SQUARE(-1-2) << endl;

gets resolved in -1 - 2*-1 - 2 and produces -1.

It is much better to avoid macros, but if you use this one, make it

#define SQUARE(x)  ((x)*(x))

solved Why this piece is outputting NAN (Not a Number)?