我需要检查 float 是否为 NaN。通过阅读一些链接,我发现最常见的检查方法是:Checking if a double (or float) is
nan
in C++。FLOAT32 f32_test_NaN = (some_value);
if (f32_test_NaN == f32_test_NaN)
{
//do something;
}
else
{
// do something;
}
但是这对我似乎不起作用。我的代码如下:
FLOAT32 test_NaN = 0x414570A3;//some value - is this ok?
GDB上的调试:
(gdb) p test_NaN
$1 = 1.09506982e+09
(gdb) p/x test_NaN
$2 = 0x41457080 // Hex is not same as init value - What is compiler doing?
在我的情况下,test_NaN
等于test_NaN
。
请告诉我是否需要进行任何编译器设置。我正在Solaris上运行。还有其他检查相同的方法吗?
提前致谢。
isnan()
函数?有什么特别的原因吗? - Constantin