double当某个值为 aNaN或 an时,我想隔离行为#INF。为了检测 a NaN,我测试
doubleVal != doubleVal
一个#INF呢?doubleVal当是时,这个测试是否正确#INF?
如果您不使用 c++11,那么您需要<boost/math/special_functions/fpclassify.hpp>代替<cmath>, 并进行相应的命名空间更改。
#include <cmath> // or <boost/math/special_functions/fpclassify.hpp>
// ...
if(isinf(num)){
// ...
}
Boost 中还有一个仅包含标头的库,它具有处理浮点数据类型的简洁工具
#include <boost/math/special_functions/fpclassify.hpp>
您将获得以下功能:
template <class T> bool isfinite(T z);
template <class T> bool isinf(T t);
template <class T> bool isnan(T t);
template <class T> bool isnormal(T t);