The following program should print the first five successive floating-point values obtained by starting at zero and repeatedly adding SPACING(x) to x.
program p
implicit none
real*8 :: x
integer :: i
x = 0.d0
do i = 1, 5
print'(G0,2X,G0)', i, x
x = x + spacing(x)
end do
end program p
The actual print out is not as I expected:
1 0.000000000000000
2 .2225073858507201E-307
3 -.1596672247627775E+294
4 -.1596672247627775E+294
5 -.1596672247627775E+294
X(2) is TINY(0.0), which looks correct, but X(3) = TINY(0.0) + SPACING(TINY(0.0)) is incorrect.
X(3) should be approximately 2 × TINY(0.0)
Am I misunderstanding something here (i.e. I am confused) or is this a bug?