Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Bug with Intel Fortran

acobulareddy
Beginner
730 Views

IF(TCP(L).EQ.NaN) THEN
GOTO 85
END IF

When I used the above code in my program though the value of TCP(L) is NaN and Debugger is showing
TCP(L).EQ.NaN as .TRUE.
it is not getting into the loop Please suggest is there any other way to handle...

0 Kudos
1 Solution
TimP
Honored Contributor III
730 Views
Quoting - Jugoslav Dujic

By definition, you cannot reliably test NaNs for equality (or for anything else, for that point). IEEE 754 definition even says that NaN.NE.NaN (although many compilers don't bother to special-case it).

Instead, use ISNAN() function.

With ifort, you must set /fp:precise in order to have any chance of preserving IEEE behavior with NaN. You also must pay attention to the way NaN works. ISNAN(x) would be implemented like ISNAN = (x /= x). With aggressive optimization enabled, a compiler replaces (x /= x) with .false. at compile time. The Fortran standard name of the function is ieee_is_nan() (not yet implemented in ifort).

View solution in original post

0 Kudos
4 Replies
Ilie__Daniel
Beginner
730 Views

Please read the following article "The Perils of Real Numbers (Part 2)" located here:

http://software.intel.com/en-us/forums/showthread.php?t=41911

Daniel.

0 Kudos
Jugoslav_Dujic
Valued Contributor II
730 Views
Quoting - acobulareddy
IF(TCP(L).EQ.NaN) THEN

GOTO 85
END IF

When I used the above code in my program though the value of TCP(L) is NaN and Debugger is showing
TCP(L).EQ.NaN as .TRUE.
it is not getting into the loop Please suggest is there any other way to handle...


By definition, you cannot reliably test NaNs for equality (or for anything else, for that point). IEEE 754 definition even says that NaN.NE.NaN (although many compilers don't bother to special-case it).

Instead, use ISNAN() function.

0 Kudos
TimP
Honored Contributor III
731 Views
Quoting - Jugoslav Dujic

By definition, you cannot reliably test NaNs for equality (or for anything else, for that point). IEEE 754 definition even says that NaN.NE.NaN (although many compilers don't bother to special-case it).

Instead, use ISNAN() function.

With ifort, you must set /fp:precise in order to have any chance of preserving IEEE behavior with NaN. You also must pay attention to the way NaN works. ISNAN(x) would be implemented like ISNAN = (x /= x). With aggressive optimization enabled, a compiler replaces (x /= x) with .false. at compile time. The Fortran standard name of the function is ieee_is_nan() (not yet implemented in ifort).

0 Kudos
Steven_L_Intel1
Employee
730 Views

IEEE_IS_NAN is implemented in version 11 as part of the IEEE intrinsic modules. I would expect ISNAN to work as well, but Tim is correct that /fp:precise is required if you want to take advantage of full IEEE semantics.

0 Kudos
Reply