Yes, the f77 standard dictated left to right application of the promotion
rules. I used to use f66 compilers which didn't stick to left to right, so
that x*(k-1)/(k+1) didn't promote the divisition to the type of x.
----- Original Message -----
From: <[log in to unmask]>
To: <[log in to unmask]>
Sent: Monday, October 02, 2000 12:45 PM
Subject: Re: Writing arithmetic expressions with mixed types
> Juergen VonHagen wrote (little bits snipped for brevity)::
>
> >robin wrote:
> >>
> >> > From: Aleksandar Donev <[log in to unmask]>
> >>
> >> > I have a pedagological question for the Fortran teachers out there.
>
> Variants of this are not only useful for teachers, but also practitioners.
>
> >> > How does one write "best" an expression with mixed types, say:
> >> >
> >> > complex(kind=sp) :: x,y
> >> > integer :: k
> >> >
> >> > y=(k-1)/(k+1)*x
>
> If k is positive, the first part (integer arithmetic) is always 0, so y is
0
> If k is zero, y = -x
> If k is negative (except -1), y = 2.*x
>
> This assumes left to right evaluation, so (k+1)/(k-1) is integer
arithmetic. I
> believe this is part of the standard, but would bow to RM's better
knowledge.
> If it is not, I have screwed up big time over many years, but my vendors
seem to
> believe what I do.
>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|