What is the safest way to set a variable to +Infinity in Fortran? At the moment I am using:
program test
implicit none
print *,infinity()
contains
real function infinity()
implicit none
real :: x
x = huge(1.)
infinity = x + x
end function infinity
end program test
but I am wondering if there is a better way?
real*8
anddouble precision
(1.d0
) are not necesarilly the same real kind. And of course, whether to use single or double precision is not a question of personal preference, but of mathematical arguments and tests. – Mercenary