Software Archive
Read-only legacy content
17060 Discussions

checking for NaN

jltate
Beginner
453 Views
I have a program that sometimes generates a NaN value. I want to check for this in order to react to it, and I was trying to use the test 'if (A /= A) then' . . .
I tried this first in an interactive program that compiles as a QuickWin Application, and it worked just fine - when A = NaN the if condition evaluated to true.
But then when I switched to a batch program that compiles as a Fortran Console Application, it stopped working. No matter what the value of A, the if condition always evaluates to false.
The compiler options on the two projects should be identical, including having optimization turned off. Can anyone tell me what the difference between the two is, and why I can't use this test in the Fortran Console Application project?
0 Kudos
1 Reply
Steven_L_Intel1
Employee
453 Views
According to the IEEE spec, a NaN is supposed to compare as "not equal" to everything, including another NaN. I know we've fixed some problems in this regard in more recent versions.

You want to use the ISNAN intrinsic instead.

Steve
0 Kudos
Reply