precision of real variable

前端 未结 1 1580
感动是毒
感动是毒 2021-01-26 11:45

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 wo

相关标签:
1条回答
  • 2021-01-26 12:18

    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?

    0 讨论(0)
提交回复
热议问题