C ++ Africa nan number of definitions and examples

/*
 * Definition of the C ++ Africa
NaN: each bit of the exponent 1 and mantissa are all not zero;
Infinite: Each bit exponent and the mantissa 1 are all 0; sign bit is 0, n is infinity,
1 sign bit is negative infinity. So NaN, positive infinity, negative infinity can be so defined,
So it can determine whether 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;
}
---------------------
Disclaimer: This article is CSDN blogger "This looks cute," the original article, follow the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/ggjttfc/article/details/84025097
// The following example uses several non
    float xx=std::numeric_limits<float>::quiet_NaN();
    cout<<"maximum value="<<isnan(xx)<<endl;
*/

Guess you like

Origin www.cnblogs.com/phoenixdsg/p/11330697.html