Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

setting a fortran variable to NaN

Scott_L_
New Contributor I
313 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
Valued Contributor III
288 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
Valued Contributor III
289 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

Scott_L_
New Contributor I
264 Views
Reply