This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: amod/dmod and -fdefault-real-8


On 01/20/2010 11:41 AM, Janus Weil wrote:
> I just came across some peculiar behavior of gfortran.

Let's start with your last question:
> Specific names:
>
> Name       Arguments  Return type  Standard
> AMOD(A,P)  REAL(4)    REAL(4)      Fortran 95 and later
> DMOD(A,P)  REAL(8)    REAL(8)      Fortran 95 and later
>
>
> Should this be considered a bug in gfortran or in the manual?

The standard has in 13.6 the specific functions AMOD (default real) and
DMOD (double precision real).
With default options, gfortran has kind(0.0) == 4 and kind(4.0d0) == 8
and thus everything is fine.

For MOD (the generic function) one finds:
"13.7.80  MOD (A, P) [...]
A   shall be of type integer or real.
P   shall be of the same type and kind type parameter as A. P shall not
be zero"

Looking (still default options) at the program:

> real    :: r  = 13.
> real(4) :: r4 = 14.
> real(8) :: r8 = 15.
> intrinsic :: amod,dmod
>
> print *,amod(r,6.E0)   ! (1)
> print *,amod(r4,6.E0)  ! (2)
>   
Those are OK.

> print *,amod(r8,6.E0)  ! (3)
>   
This one is wrong as A and P have a different KIND-type parameter.

> print *,dmod(r,6.D0)   ! (4)
>   
> print *,dmod(r4,6.D0)  ! (5)
>   
Ditto. Wrong for the same reason.

> print *,dmod(r8,6.D0)  ! (6)
>   
This one is OK.

> "gfortran"                  errors on (3),(4),(5)
>   
Thus this looks perfectly valid.

 * * *

Now looking at -fdefault-real-8: Both "real" and "double precision" have
a kind value of 8. Going through the program again:

> print *,amod(r,6.E0) ? ! (1)
>   
OK both kind=8
> print *,amod(r4,6.E0) ?! (2)
>   
Wrong kind=4 vs kind=8
> print *,amod(r8,6.E0) ?! (3)
>   
OK

> print *,dmod(r,6.D0) ? ! (4)
>   
OK
> print *,dmod(r4,6.D0) ?! (5)
>   
Wrong kind=4 vs kind=8.

> print *,dmod(r8,6.D0) ?! (6)
>   
OK

> "gfortran -fdefault-real-8" errros on (2),(5)
>   
Thus I get the same result.

> "ifort"                     accepts all, but warns on (3)
>   
With -stand f95 it also warns for (4) and (5). NAG also rejects (!) for
(3), (4), (5).

> "ifort -r8"                 accepts all
>   
With -stand f95 it also warns about (2) and (5). Ditto NAG f95 (except
that it has errors).

The question is thus only whether one wants (like ifort) allow some of
these with warnings/-std=legacy or not.

> gfortran apparently is the most restrictive one here. All the errors
> that gfortran spits out concern the first argument of the intrinsic
> function call. Using the generic "mod" instead of amod/dmod is always
> accepted.
>   
But only with -std=gnu; with -std=f2003 you get the proper error message.

To come back to the manual:
> Specific names:
>
> Name       Arguments  Return type  Standard
> AMOD(A,P)  REAL(4)    REAL(4)      Fortran 95 and later
> DMOD(A,P)  REAL(8)    REAL(8)      Fortran 95 and later
>
> Should this be considered a bug in gfortran or in the manual?

Hmm, in a way yes. Correct would be "default real" and "double
precision" (cf. Fortran standard). If one regards -fdefault-real-8 as
abnormal special case, one can argue that the manual is still correct.

Tobias


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]