isnan, _isnan, _isnanf

测试浮点值是否非数值 (NAN)。

语法

int isnan(
   /* floating-point */ x
); /* C-only macro */

int _isnan(
   double x
);

int _isnanf(
   float x
); /* x64 only */

template <class T>
bool isnan(
   T x
) throw(); /* C++ only */

参数

x
要测试的浮点值。

返回值

在 C 中,如果该自变量 x 是 NAN,则 isnan 宏和 _isnan_isnanf 函数将返回一个非零值;否则它们会返回 0。

在 C++ 中,如果自变量 x 是 NAN,则 isnan 模板函数将返回 true;否则会返回 false

备注

由于 NAN 值不会与自身或任何其他 NAN 值进行比较,因此要检测 NAN 值,必须使用其中一个函数或宏。 如果无法为指定类型以 IEEE 754 浮点格式表示浮点运算的结果,则会生成 NaN。 有关如何表示用于输出的 NAN 的信息,请参阅 printf

作为 C++ 编译时,不会定义 isnan 宏,而是定义 isnan 模板函数。 它的行为方式与宏相同,但返回 bool 类型的值,而不是整数。

_isnan_isnanf 函数是 Microsoft 特定函数。 _isnanf 函数仅在编译 x64 时可用。

要求

例程 必需的标头 (C) 必需的标头 (C++)
isnan_isnanf <math.h> <math.h> 或 <cmath>
_isnan <float.h> <float.h> 或 <cfloat>

有关兼容性的详细信息,请参阅 兼容性

另请参阅

数学和浮点支持
fpclassify
_fpclass_fpclassf
isfinite_finite_finitef
isinf
isnormal