【发布时间】:2012-07-11 15:39:59
【问题描述】:
以Divide by Zero Prevention和Check if it's a 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?
【问题讨论】:
-
您可以使用标准的
isnan()函数,在<cmath>中声明。
标签: c++