Native C++ _isnan()函数的应用

当表示一个double型数值不为数字时,在.net可以这样表示

double d = double.NaN;

double.NaN的原型如下:

//
// Summary:
// Represents a value that is not a number (NaN). This field is constant.
public const double NaN = 0.0 / 0.0;

在Native C++,如果想表示一个不为数字的double,可以使用下面的函数。

double GenerateNaN()
{
unsigned long nan[2]={0xffffffff, 0x7fffffff}; // code representing a NaN
return *( double* )nan;
}

判断double类型是不是NaN,可以使用_isnan()函数:

double d = GenerateNaN();
if(_isnan(d))
{
printf("d is NaN.");
}
posted @ 2009-12-08 14:18  Jake Lin  阅读(10134)  评论(0编辑  收藏  举报