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

Set Parameter To NaN

ScottBoyce
Beginner
1,443 Views

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
jimdempseyatthecove
Honored Contributor III
1,443 Views

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
FortranFan
Honored Contributor II
1,443 Views

See this:

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

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
IanH
Honored Contributor II
1,443 Views

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
Reply