gfortran and g77 gives different output for same program

Steve Kargl sgk@troutmask.apl.washington.edu
Tue Mar 14 14:53:00 GMT 2006


On Tue, Mar 14, 2006 at 07:58:41PM +0530, prakash Taksali wrote:
> I wrote a sample fortran program for this problem -
> 
> Fortran program test.f --
> 
> 
> IMPLICIT NONE
> REAL*8 X1, Y1, X2, Y2, LENGHT
> X1 = '3FEF6EFA44990F7F'Z
> Y1 = '3FEF6EFA44990F7F'Z
> X2 = '3FEF6EFA44990F7F'Z
> Y2 = '3FEF6EFA44990F7F'Z
> WRITE (*,71) , 'LENGHT is ', X1
> LENGHT=SQRT((X2-X1)**2 + (Y2-Y1)**2)
> PRINT *, 'LENGHT is ', LENGHT
> LENGHT=X1 * X2
> WRITE (*, 71) , 'LENGHT is ', LENGHT
> 71 format(1x,a10,2x,z16)
> END
> 
> Compiled it on ltbbuild (This machine has SUSE linux distribution)
> machine like this : g77 test.f
> 
> ptaksali@ltsbuild:~> ./a.out
> LENGHT is 3FEF6EFA44990F7F
> LENGHT is 0.
> LENGHT is 3FEEE085C5257ABB
> 
> Compiled it on cpbwbuild (This machine has FC5) machine like this:
> gfortran -ff2c test.f
> [ptaksali@cpbwbuild for_prog]$ ./a.out
> LENGHT is 43CFF7B77D224C88
> LENGHT is 0.00000000000000
> LENGHT is 47AFEF711F2A56E7
> 
> We can see from above output that same program gives two different
> output on different machine.
> 

Both results are correct (or incorrect if you interpret the
Standard strictly).  The assignment of a BOZ literal constant
to a REAL variable is not standard conforming.

> Pls note that compiler option "-ff2c" does not affect the output.

-ff2c only effects calling convention.

> Can some one from community explain me the reason behind two different
> output and how to fix this problem.

I don't know the internals of g77, but I'd guess that g77 is
converting the BOZ constant directly to a REAL*8 number. 
gfortran will convert the BOZ an INTEGER with the large range.
The assignment to a REAL*8 will then convert the INTEGER to a
a REAL*8 value.

If you want a specific floating point bit pattern, then use
TRANSFER.

-- 
Steve



More information about the Fortran mailing list