Nan indicates not a number.
After Division by zero, the floating point will become Nan (INF ).
You can use the following functions to determine whether the value is Nan (INF ).
Library Function: int _ isnan (double );
Int _ finite (double); // use this function in VC
// If the input double value is invalid, the function returns 0. You need to include the library file <float. h>
You can also write user-defined functions for judgment (not in VC)
1 bool is_nan(double dVal)
2 {
3 if (dVal==dVal)
4 return false;
5
6 return true;
7 }
The invalid value in vc6 is1. # inf000000000
This value varies with compilers.
This difference can be shielded using the C ++ standard library. The following code:
#include <limits>
bool is_nan(double dVal)
{
double dNan = std::numeric_limits<double>::quiet_NaN();
if (dVal==dNan)
return true;
return false;
}
The following functions can be used in boost to determine
#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);