Page 2 of 2

Re: Checking for NaN

Posted: August 28th, 2020, 7:30 pm
by albinopapa
Again, thanks for taking a look and helping me correct it, sorry I get a little dense sometimes.

Re: Checking for NaN

Posted: August 29th, 2020, 7:06 am
by Slidy
albinopapa wrote:
August 28th, 2020, 7:00 pm
Aside from std::nan() and the std::numeric_limits functions, how would you even getting a nan as a result? I tried dividing by 0.0 and end up getting inf.
Doing 0/0 should work.

Code: Select all

double zero = 0.0f;
x.f = zero / zero;
Tried it out and it gave me "-NaN" as a result. Since it's negative it has sign bit set, it also failed to be detected by your initial code, but the new version you posted that does masking seems to work.

Glad you got it working in the end :)