鉴于以下问题除以零预防并检查它是否为 NaN作为示例,我编写了以下代码:
#include <cstdlib>
#include <iostream>
#include <map>
#include <windows.h>
using namespace std;
bool IsNonNan( float fVal )
{
return( fVal == fVal );
}
int main(int argc, char *argv[])
{
int nQuota = 0;
float fZero = 3 / (float)nQuota;
cout << fZero << endl;
cout << IsNonNan( fZero ) << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
为什么IsNonNan
返回是真的?还有为什么会int nZero = 3 / (float)nQuota;
输出:-2147483648
?