isnan返回一个int ... nonzero value if arg is NaN, 0 otherwise
。为什么不回归布尔?这不是一些传统的东西,它是C ++ 11的新功能。
这是传统的东西,这些都可以在<cmath>
中找到,这是将<math.h>
放入std
命名空间的C标准库。 C没有原生的bool
类型
虽然这些都是C ++ 11的添加,但它们实际上是在C99中添加到<math.h>
中的东西。
bool
is actually a macro. There is a _Bool
, but I guess the C99 authors chose not to use it for isnan
et al. in order to retain consistency with other stuff in <math.h>
.
为了澄清,isnan,isinf作为宏在C99中作为int表达式添加。因此,对于C兼容性,将它们添加为返回int的函数是有意义的。
http://www.cplusplus.com/reference/cmath/isnan/
C99 C ++ 11
在C中,这是作为返回int值的宏实现的。 x的类型应为float,double或long double