This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Minimum integer values
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: Scott Robert Ladd <coyote at coyotegulch dot com>
- Cc: fortran at gcc dot gnu dot org
- Date: Thu, 25 Dec 2003 12:42:56 -0800
- Subject: Re: Minimum integer values
- References: <3FEB3461.8070507@coyotegulch.com>
On Thu, Dec 25, 2003 at 02:02:57PM -0500, Scott Robert Ladd wrote:
> I reported the following as a bug, but after reading the gfortran source
> code, I'm not entirely certain of my diagnosis.
>
> This program compiles and exceutes with Lahey and Intel compilers, but
> *not* with gfortran:
>
> program parambug
> implicit none
> integer, parameter :: MY_KIND = SELECTED_INT_KIND(10)
> integer(MY_KIND), parameter :: X = -2147483648
integer(MY_KIND), parameter :: X = -2147483648_MY_KIND
integer(MY_KIND), parameter :: X = -HUGE(X)
>
> write (*,*) X
> end program parambug
>
> Looking at arith.c, I find this comment:
>
> mpz_init (int_info->min_int);
> mpz_neg (int_info->min_int, int_info->huge);
> /* No -1 here, because the representation is symmetric. */
>
>
> Yet I can't find anything in the Fortran 95 standard that supports the
> contention that potitive and negative values are symmetric (as suggested
> by the comment.
>
> So is this a bug or not? It certainly is different from other Fortran 95
> compilers...
>
It's different than Lahey and Intel's compilers, but NAG's compiler gives
kargl[206] f95 -o a a.f90
Error: a.f90, line 4: Integer literal 2147483648 too large for default KIND
Errors in declarations, no further processing for PARAMBUG
[f95 error termination]
The model for integers suggests that the integers are symmetric
about zero,
$i = s \times \sum_{k=1}^q w_k \times r^{k-1}$,
(hopefully, you can read (La)TeX). Here, $s$ is plus or minus 1,
and -0 = +0 = 0. I can't find in the draft of the F2003 whether
one can have more positive integers than negative integers, but
one certainly cannot have more negative integers than positive
integers because of ABS().
--
Steve