Roland Schilling wrote:
> 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.)'.
What has happened is the default real is 8 bytes and you have declared a
'half-length' variable r4. Adding the statement
write(*,*) r4, huge(1.), huge(r4)
gives the output
INF 1.7976931348623157E+308 3.4028235E+38
from the Nag compiler, which seems entirely reasonable to me.
And the gnu compiler says:
r4 = huge(1.)
1
Warning (128): Arithmetic overflow at (1)
Cheers,
John Reid.
|