Comparing for NaN
Kevin E.
Loveland, CO

Jul 28, 2010
4 Posts

Comparing for NaN

My ATEasy application uses a 3rd party DLL with functions that may return an IEEE NaN (Not a Number).  Does ATEasy have a built-in means to determine if the value (as a float or double) is a NaN?

DrATEasy (Ron Y.)
Mission Viejo,

Jul 28, 2010
235 Posts

Re: Comparing for NaN

Take a look at the following example:

ddwQNaN:DDWord
d:Double
dQNaN:Double

ddwQNaN=0xFFF8000000000000
MemoryCopy(&dQNaN, &ddwQNaN, 8)
print d  ! will print  -1.#IND
d=dQNaN
print d
if ddQNaN=d
    print "same"
endif

You can do the same for any NaN representation.

Aaron R.
Tucson, AZ

Jan 6, 2011
9 Posts

Re: Comparing for NaN

I do not have my ATEasy environment available right now.  Does the if test pass and same prints out?

DrATEasy (Ron Y.)
Mission Viejo,

Jan 7, 2011
235 Posts

Re: Comparing for NaN

Yes, it will print "same".

Aaron R.
Tucson, AZ

Jan 7, 2011
9 Posts

Re: Comparing for NaN

Ron, I would submit that is incorrect behavior. A NaN is not equal to anything, even itself. Looking at IEEE754 will confirm this behavior. The correct test for a NaN in languages like C, C++, and python is:

if x != x

python implements an isNaN() function as well.

I would suggest creatiion of an isNaN type procedure and the equality comparison be changed to false when comparing two NaNs to fall inline with IEEE754.

Wikipedia has a discussion of NaN: http://en.wikipedia.org/wiki/NaN which echoes the behavior I mentioned.

DrATEasy (Ron Y.)
Mission Viejo,

Jan 7, 2011
235 Posts

Re: Comparing for NaN

You are right, it should not print (according to IEEE754). I will add it to our suggestion list. BTW why do you need this?

Aaron R.
Tucson, AZ

Jan 11, 2011
9 Posts

Re: Comparing for NaN

Ron -

I don't have an immediate need, but was trying to be complete for when the situation comes up in the future.  Kevin's original question sounded like a perfect example of what can happen when interfacing with an external DLL.



Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]