标签:mit eric cout blog turn csdn float double bsp
/*
* C++中非数的定义
NaN :阶码的每个二进制位全为1 并且 尾数不为0;
无穷:阶码的每个二进制位全为1 并且 尾数为0;符号位为0,是正无穷,
符号位为1是负无穷。所以NaN、正无穷、负无穷可以如此定义,
可以如此判断是否NaN:
//float
int __NaN=0xFFC00000,__Infinity=0x7F800000,__Neg_Infinity=0xFF800000;
const float NaN=*((float *)&__NaN),Infinity=*((float *)&__Infinity),Neg_Infinity=*((float *)&__Neg_Infinity);
bool IsNaN(float dat)
{
int & ref=*(int *)&dat;
return (ref&0x7F800000) == 0x7F800000 && (ref&0x7FFFFF)!=0;
}
//double
__int64 __NaN=0xFFF8000000000000,__Infinity=0x7FF0000000000000,__Neg_Infinity=0xFFF0000000000000;
const double NaN=*((double *)&__NaN),Infinity=*((double *)&__Infinity),Neg_Infinity=*((double *)&__Neg_Infinity);
bool IsNaN(double dat)
{
__int64 & ref=*(__int64 *)&dat;
return (ref&0x7FF0000000000000) == 0x7FF0000000000000 && (ref&0xfffffffffffff)!=0;
}
---------------------
版权声明:本文为CSDN博主「这个长得可爱」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/ggjttfc/article/details/84025097
//下面是非数的使用范例
float xx=std::numeric_limits<float>::quiet_NaN();
cout<<"maximum value="<<isnan(xx)<<endl;
*/
标签:mit eric cout blog turn csdn float double bsp
原文地址:https://www.cnblogs.com/phoenixdsg/p/11330697.html