Consider the following program:
debian-gfortran:~/test> cat maxval.f90
integer(1) :: i(3)
logical :: msk(3)
i = -huge(i)
i = i - 1
write(*,*) i
write(*,*) maxval(i)
msk = .false.
i = 1
write(*,*) i
write(*,*) -huge(i), maxval(i, msk)
end
In both of these cases, the result of the MAXVAL call should be -huge(i)-1.
(For the latter case, see the standard on the definition of the intrinsic,
which says that the result is the negative number with the largest magnitude
possible within the representation). However, the actual result is this:
debian-gfortran:~/test> ../bin-trunk/bin/gfortran maxval.f90 -o maxval
debian-gfortran:~/test> ./maxval
-128 -128 -128
-127
1 1 1
-127 -127
This error holds for larger integer kinds, as well.
The error seems to stem from the libgfortran implementation, in which the
initial search value is initialized as -GFC_INTEGER_<n>_HUGE, where it should
be one less than that.
--
Summary: MAXVAL() incorrect for zero-size int arrays, and for -
HUGE-1 maximum values.
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: brooks at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30512