This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/30512] New: MAXVAL() incorrect for zero-size int arrays, and for -HUGE-1 maximum values.
- From: "brooks at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 Jan 2007 00:09:53 -0000
- Subject: [Bug fortran/30512] New: MAXVAL() incorrect for zero-size int arrays, and for -HUGE-1 maximum values.
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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