C ++中的整数是否可以是NaN? [英] Can an integer be NaN in C++?

查看:185
本文介绍了C ++中的整数是否可以是NaN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆