1program sample
2 implicit none
3
4 integer :: i, n
5 real(8) :: x, y
6
7 x = 1.0e-15_8
8
9 ! 桁落ちの例
10 write(*, *) 'Cancellation of significant digits'
11 write(*, '("correct result : ", e22.15)') x / (sqrt(1 + x) + 1)
12 write(*, '("incorrect result : ", e22.15)') sqrt(1 + x) - 1
13
14 ! 情報落ちの例
15 n = 10000000
16 y = 1.0_8
17 do i = 1, n
18 y = y + x
19 enddo
20
21 write(*, *) 'Loss of trailing digits'
22 write(*, '("correct result : ", e22.15)') 1.0_8 + x * n
23 write(*, '("incorrect result : ", e22.15)') y
24
25endprogram sample