- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page