HP 3000 Manuals

Evaluation of Mixed Mode Expressions [ HP FORTRAN 77/iX Migration Guide ] MPE/iX 5.0 Documentation


HP FORTRAN 77/iX Migration Guide

Evaluation of Mixed Mode Expressions 

Mixed mode expressions are evaluated differently in the two compilers.
In operations of the same precedence, FORTRAN 66/V evaluates the same
types within an expression first, while HP FORTRAN 77/V evaluates
strictly from left to right.

The following example program produces different results in the two
compilers:

     INTEGER*4 j
     j = 2000000000
     WRITE(6,*) 1.0+j-j
     END

The result returned in FORTRAN 66/V is 1.0.  The result returned in HP
FORTRAN 77/V is 0.0.

In FORTRAN 66/V, the expression j-j is evaluated first.  In HP FORTRAN
77/V, the expression 1.0+j is evaluated first.  Since the constant 1.0 is
a single precision real, only six digits are available to hold the
partial result, and the last four digits of 2000000000 are not stored.

You can use parentheses to force the order of evaluation you want.  For
instance, if you want the HP FORTRAN 77/V program to yield the answer
1.0, make this change:

     WRITE(6,*) 1.0+(j-j)

Alternately, you could explicitly type the constant as double precision,
as shown:

     WRITE(6,*) 1.0D0+j-j



MPE/iX 5.0 Documentation