I have a problem comparing the NAN value in C ++, Visualstudio. I need to process a section under Zero in my code. if I get division by zero, I want to assign a NAN for the result. Check at a later point in time if the result has a NAN. But NAN comparisons fail at a later point in time, although I assign quiet_Nan () as shown below.
double d = std::numeric_limits<double>::quiet_NaN();
if( d == std::numeric_limits<double>::quiet_NaN())
{
cout<<" NAN ";
}
else
{
cout<<" Number";
}
I know that floating values cannot be compared for equality. I tried using diff between d and quiet_Nan () and tried to compare it with a floating-point number with the <operator. I saw a few posts, but couldn't figure out how to compare the double value.
How to find out about the existence of a NAN value in a double variable?