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;
}
c语言 判断float无穷大 C++ 浮点数(double float)如何定义NaN 正无穷 负无穷 以及如何判断是否是NaN...