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

setting a fortran variable to NaN

Scott_L_
New Contributor I
661 Views
There is the isnan function to test a variable for a NaN value, but is there a function I can use to set a variable to NaN? I am using ifort 17.1 on windows x64 and Linux. It would be preferable to not have to alter the /fpe options to let sqrt(-1) slide but if that's the best option, which fpe value would be safest on Linux and windows visual studio? thanks scott
0 Kudos
1 Solution
Arjen_Markus
Honored Contributor I
636 Views

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         

View solution in original post

2 Replies
Arjen_Markus
Honored Contributor I
637 Views

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         
Scott_L_
New Contributor I
612 Views
Reply