0

I have the following code in FORTRAN 77:

REAL*8 :: dm dm=1.-1.E-12 write(6,*) 'dm: ', dm 

I get: dm: 1

Is this OK? I would like to get dm=0.999999999999

2
  • I don't know enough about FORTRAN to answer authoritatively, but assuming that REAL*8 represents an 8 byte float (double precision) it should have at least 15 digits of precision. Could it have something to do with the output formatting? Commented Jun 7, 2013 at 20:15
  • 3
    The trouble is your constants are single precision, try 1.D0-1.D-12. Note that notation (along with REAL*8) is obsolete in modern fortran but still works. Not clear if/why you want f77.. Commented Jun 7, 2013 at 20:21

1 Answer 1

3

As stated in a comment, you need to specify the precision of the constants. Also, real*8 is obsolete. (Was it always an extension?) Here is a modern way to write this, using the ISO Fortran Environment to obtain a 64-bit real type and using that type both in the declaration and in the constants.

use ISO_FORTRAN_ENV real (real64) :: dm dm = 1.0_real64 - 1.0E-12_real64 

For more info, see What does `real*8` mean?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.