In gcc library, there is a NaN defined in math library to be used for cases like initialize an undefined double variable. However, this NaN is not defined in win32 math lib, I was wondering if there’s any way to make this portable? Basically, I just wanted to give a default value to “double” type variables.
Share
C++ guarantees that
0.0/0.0isNaN, so this is the easiest way to express it.Remember that
NaN != NaN, so(0.0/0.0) == (0.0/0.0)is actually false. To test for NaN-ness, if you don’t have a libraryis_nansomewhere, just check forx != xfor some candidatedouble x.