real*8 conversion errors

I have the following test program on:
Linux Red Hat 8.0 kernel 2.4.18-14
GLIBC version 2.2.93-5
PGF77 version 5.1-2

program newtest

implicit none

real*8 myreal, newreal

myreal = 25.13982364598249
newreal = 17.77777777777777

write(,) 'myreal = ',myreal
write(,) 'newreal = ',newreal


The output of this program is:
myreal = 25.13982391357422
newreal = 17.77777862548828
The output values are obviously not the same as in the code.

Has anyone else come across this problem and if so what was done to correct it? I would imagine it to be a compiler bug. Any input would be very helpful.

Hi Bland,

Actually, its not a compiler bug. In fortran, real literal constants have an implict kind just like variables. So what’s happening is at compile time your constant values are being truncated to fit the default size of a “real” which is 4 bytes.

With pgf77 and pgf90 you can add the compilation flag “-r8” to change the implicit kind for reals to be “real*8”. Also with pgf90, you can append the real literal constant with a kind parameter.


Hope this clarifies things,


Does this mean that only specify REAL*8 in the code is not enough?


REAL*8 only applies to the variable not the literal constant. Constants also have a “kind”. If you want this kind to be anything other than the default, you must specify it. See Michael Metcalf and John Reid’s Fortran 90/95 Explained discussion of types in sections 2.5 and 2.6 for further information.

  • Mat