Checking for NaN

The Partridge Family were neither partridges nor a family. Discuss.
Posts: 4266
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Checking for NaN

Post by albinopapa » August 28th, 2020, 7:30 pm

Again, thanks for taking a look and helping me correct it, sorry I get a little dense sometimes.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. -

Posts: 79
Joined: September 9th, 2017, 1:19 pm

Re: Checking for NaN

Post by Slidy » August 29th, 2020, 7:06 am

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 :)

Post Reply