I've been trying to find a standards-compliant way to check for Infinite and NaN values in Fortran 90/95 but it proved harder than I thought.
- I tried to manually create Inf and NaN variables using the binary representation described in IEEE 754, but I found no such functionality.
- I am aware of the intrinsic
ieee_arithmetic
module in Fortran 2003 with theieee_is_nan()
andieee_is_finite()
intrinsic functions. However it's not supported by all the compilers (notably gfortran as of version 4.9).
Defining infinity and NaN at the beginning like pinf = 1. / 0
and nan = 0. / 0
seems hackish to me and IMHO can raise some building problems - for example if some compilers check this in compile time one would have to provide a special flag.
Is there a way I can implement in standard Fortran 90/95?
function isinf(x)
! Returns .true. if x is infinity, .false. otherwise
...
end function isinf
and isnan()
?
IEEE_ARITHMETIC
, but support of older versions is still an issue and will continue to be for a long time. – Encrimson