- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can do so with the function ieee_value(). Here is a small demo program:
program setnan
use, intrinsic :: ieee_arithmetic
implicit none
real :: x
x = ieee_value( x, ieee_signaling_nan )
write(*,*) x
x = ieee_value( x, ieee_quiet_nan )
write(*,*) x
end program setnan
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can do so with the function ieee_value(). Here is a small demo program:
program setnan
use, intrinsic :: ieee_arithmetic
implicit none
real :: x
x = ieee_value( x, ieee_signaling_nan )
write(*,*) x
x = ieee_value( x, ieee_quiet_nan )
write(*,*) x
end program setnan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is it possible to set a parameter to nan? Calling ieee_value as part of a parameter definition doesn't work:
use, intrinsic :: ieee_arithmetic
real(DP), parameter :: aNan = ieee_value(aNan, ieee_signaling_nan)
error #6259: This array or function or substring is invalid in constant expressions. [IEEE_VALUE]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
IEEE_VALUE is not permitted in a constant expression, per the standard. I polled a couple of the committee members about this, and it was felt it had limited usefulness. You can use a hex literal if you want, or use run-time initialization.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The usefulness of having a parameter as a signaling is rather limited.
The use on rhs of = .OR. in IF(var == aNAN) should cause a trap...
... however, if the Fortran compiler generates a integer binary compare, then you will not trap...
however, if binary (integer) compare is performed, then it will detect one of 2^22 or 2^51possible SNAN's.
From: Microsoft.com
NaN - Not a Number
It's possible to represent values that aren't real numbers, such as 0 / 0, in the IEEE floating-point format. A value of this kind is called a NaN. A NaN is represented by an exponent of all ones and a non-zero significand. There are two kinds of NaNs, quiet NaNs, or QNaNs, and signaling NaNs, or SNaNs. Quiet NaNs have a leading one in the significand, and get propagated through an expression. They represent an indeterminate value, such as the result of dividing by infinity, or multiplying an infinity by zero. Signaling NaNs have a leading zero in the significand. They're used for operations that aren't valid, to signal a floating-point hardware exception.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I use a nan parameter for debugging. I initialize components of derived types to nan so that I can tell if it gets used before initialisation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Another way is to initialize to a strange number that you will never use or is unlikely to occur, initialize at creation to that and then test for it, before you use it. You are just looking for a change are you not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There will be the strangely interesting numbers potentially in it anyway, may as well make your own strange so you know you did it.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page