0

I have a large old code I am cleaning up and updating. Comparing my new version to the old version I have noticed that the final result, given as a double precision float, is never precisely the same, but tends to differ by a small amount nearing floating point precision. Now, in the original code double precision variables were, seemingly at random, initiated using either real*8 :: variable or double precision :: variable. In the new version of the code I want to be more consistent, and ideally I would like to use the more widely recommended KIND system. However for debugging purposes the current version has all variables initiated as real*8 :: variable.

My question is, is there a guarantee that variables initiated as double precision or real*8 are treated in exactly the same way. In other words, assuming all other things are equal, should I expect my new code to give the exact same output as the old code? Or is it to be expected that changing all declarations to real*8 changes the rounding error on the level of floating point precision.

Thanks!

Jasper
  • 87
  • 7
  • `double precision` declares a real variable as one kind, `real*8` declares a real variable as one kind. These may be the same, they may not. If they're the same for one declaration odds are good they're the same for all (with the same compiler, compile-time options, compiler version, phase of the moon, etc.). We can't be any more precise without knowing what your system is. – francescalus Aug 31 '22 at 15:20
  • The linked question is about integers. This means the subtle aspect of `double precision` isn't explicitly addressed, but if you consider `double precision :: x` to mean the same as `real(kind=KIND(0d0)) :: x` then the same lessons follow translating from integer to real. – francescalus Aug 31 '22 at 15:52

0 Answers0