Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
13 Views

Set Parameter To NaN

Is there anyway to use standard fortran to initialize a double precision parameter to a IEEE NaN. The following fails because the 

MODULE NaN_Value
  USE, INTRINSIC:: IEEE_ARITHMETIC, ONLY: IEEE_VALUE, IEEE_QUIET_NAN
  !
  DOUBLE PRECISION, PARAMETER:: NaN =  IEEE_VALUE(1D0, IEEE_QUIET_NAN)
  !
END MODULE

Ideally, I could have a global parameter value NaN that represents the FORTRAN NaN. I do not want to use the TRANSFER function with the integer that represents a NaN because that is not CPU/Platform independent.

thanks for your help

0 Kudos
3 Replies
Highlighted
13 Views

You can use

You can use

binary B'd[d...]'
octal O'd[d...]'
hex Z'd[d...]'
 

You will have to select the specific SNAN or QNAN value for initialization. See: https://en.wikipedia.org/wiki/NaN#Quiet_NaN for reference information as to bit patterns. Pay attention to the Encoding section at the bottom if pertinent.

Jim Dempsey

0 Kudos
Highlighted
Valued Contributor III
13 Views

See this:

See this:

https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-and-reference-ieee-arithmetic...

IEEE_ARITHMETIC intrinsic module already includes named constants of IEEE_QUIET_NAN and IEEE_SIGNALING_NAN.

So why would you need to define new named constants?

0 Kudos
Highlighted
Black Belt
13 Views

Quote:FortranFan wrote:

FortranFan wrote:

See this:

https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-a...

IEEE_ARITHMETIC intrinsic module already includes named constants of IEEE_QUIET_NAN and IEEE_SIGNALING_NAN.

So why would you need to define new named constants?

Those named constants are not nan values, they are the arguments to use for procedures to characterise or generate nan values, as per the code in the original post.  But those procedures cannot be used in constant expressions in F2008, hence the issue.

Those procedures are permitted in constant expressions as of F2015.  In the meantime bit setting hacks are required.

0 Kudos