C ++中的整数是否可以是NaN? [英] Can an integer be NaN in C++?
问题描述
我可以将 int
设为 NaN
吗?如果是,那么如何检查 int
是 NaN
还是不是?
否,NaN是浮点值。
int
是一个数字。
编辑
/ p>
填充位是奇偶校验位。
无论如何,对
没有算术运算有效值可以产生陷阱
表示而不是
的一部分例外条件如
溢出,并且
无符号类型不会出现这种情况。
实现特定的无效整数值,但没有定义的方式生成它们。
Can I set an int
to NaN
? If yes, then how can I check if an int
is NaN
or not?
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.
这篇关于C ++中的整数是否可以是NaN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!