2

I'm trying to understand the difference between these two:

REAL*8 X
X=1.5D0
WRITE(6,*) (0.6D0 + (2*x)/5.)
WRITE(6,*) (0.6 + (2*x)/5.D0)

I would expect them to give identical results, but I get instead

1.2000000000000000
1.2000000238418580

Why is 0.6 not cast to double precision in the second case even if it is supposed to be summed to a value in double precision? What is happening?

Marco
  • 79
  • 2
  • 2
    Second .06 is just a float and afterwards converted to a double. – albert Feb 06 '19 at 14:34
  • 1
    It _is_ converted to a double precision value as part of the summation, it's just that the default real approximation of 0.6 isn't the same as the double precision approximation of 0.6. – francescalus Feb 06 '19 at 14:39

0 Answers0