Hi,
I stumbled upon a Fortran quirk regarding the ranges for integers. The standard
stipulates that the ranges be symmetric even though as we know two's complement
signed integers have asymmetrical ranges, e.g. int8 kind can vary between -128
and 127.
This is sure to cause confusion as for exa
On Fri, Jan 26, 2024 at 03:44:26PM +0200, Elias Toivanen wrote:
>
> I stumbled upon a Fortran quirk regarding the ranges for integers.
> The standard stipulates that the ranges be symmetric even though
> as we know two's complement signed integers have asymmetrical
> ranges, e.g. int8 kind can var
>> print *, -128_int8
>
> This is a unary minus operator with an operand of 128.
> gfortran does not have negative integers.
To be clear, it’s not gfortran, it’s the standard(s). It’s not exactly true
either, because there is a "signed-int-literal-constant” which is allowed in
some contexts:
On Fri, Jan 26, 2024 at 09:23:56PM +0100, FX Coudert wrote:
>
> This is, for example, legal code (and handled by gfortran as expected):
>
> use iso_fortran_env
> implicit none
> integer(int8) :: j
> data j /-128_int8/
> print *, j
> end
>
Interesting example.
% gfcx -o z a.f90 &&
> Interesting example.
>
> % gfcx -o z a.f90 && ./z
> -128
> % gfcx -o z -pedantic a.f90 && ./z
> a.f90:5:20:
>
>5 | data j /-128_int8/
> |1
> Error: Integer too big for its kind at (1). This check can be disabled with
> the option ‘-fno-range-check’
That qualifi
On Fri, Jan 26, 2024 at 11:38:01PM +0100, FX Coudert wrote:
> > Interesting example.
> >
> > % gfcx -o z a.f90 && ./z
> > -128
> > % gfcx -o z -pedantic a.f90 && ./z
> > a.f90:5:20:
> >
> >5 | data j /-128_int8/
> > |1
> > Error: Integer too big for its kind at (1)