Can an integer be NaN in C++?

MBZ picture MBZ · Oct 16, 2010 · Viewed 28.1k times · Source

Can I set an int to NaN? If yes, then how can I check if an int is NaN or not?

Answer

DerKuchen picture DerKuchen · Oct 16, 2010

No, NaN is a floating point value.

Every possible value of an int is a number.

Edit

The standard says:

6.2.6.2 40) Some combinations of padding bits might generate trap representations, for example, if one padding bit is a parity bit. Regardless, no arithmetic operation on valid values can generate a trap representation other than as part of an exceptional condition such as an overflow, and this cannot occur with unsigned types.

So there may be some implementation specific invalid integer values, but there is no defined way to generate them.