Dear Fortran experts,
My programs are generally compiled for double-precision reals,
e.g. using the compiler option -r8 for many compilers. But
sometimes I use single-precision reals in such programs, for
the sake of saving memory space (in case of huge arrays).
Please consider the following simple program
Program TEST_HUGE
!
integer, parameter :: kpr4=selected_real_kind(6) ! 4-byte reals
real(kpr4) :: r4
!
r4 = huge(1.)
if (r4 < huge(1.)) write(*,*) 'less'
if (r4 == huge(1.)) write(*,*) 'equal'
if (r4 > huge(1.)) write(*,*) 'greater'
end
and assume it to be compiled for double-precision reals. What,
do you think, will be the result? Is the statement 'r4 = huge(1.)'
standard conforming? I think so. Keep in mind that there is no
way to get a single-precision value for 'huge(1.)'.
The somewhat surprising result is that 'r4' appears greater then
'huge(1.)' for many compilers, as can be seen when running the
above program. I tried 7 different compilers: GNU g95, Sun (8.1),
NAG f95 (4.2), Intel 8.1 and 9.0, IBM xlf90, Lahey-Fujitsu (6.2d).
Only GNU g95 and Sun gave a warning, all others gave no warning.
The result was 'greater' for all tested compilers, except for the
Lahey-Fujitsu which resulted in 'equal'.
What do the experts think about this problem?
Thanks in advance for any enlightening comments.
Roland
+----------------------------------------------------------------------+
| Roland Schilling Home-Office: +49(89)32929-670 |
| Max-Planck-Institut für Gravitationsphysik |
| -- Albert-Einstein-Institut -- |
| D-85748 Garching E-mail: [log in to unmask] |
| Germany http://www.geo600.uni-hannover.de |
+----------------------------------------------------------------------+
|