nano_exit

基礎的なことこそ、簡単な例が必要だと思うのです。

Fortranの精度変更。

Fortranの精度変更の書式が自分の知らない感じだったので、自分用にまとめる。
Fortran Best Practices — Fortran90 1.0 documentation

program test_presicion
implicit none

integer, parameter :: dp0 = kind( 0.d0 )
integer, parameter :: dp = selected_real_kind( 8 )
integer, parameter :: qp = selected_real_kind( 16 )

print *, epsilon( 1._dp0 )
print *, epsilon( 1._dp  )
print *, epsilon( 1._qp  )

print *

print *, epsilon( 1._4  )
print *, epsilon( 1._8  )
print *, epsilon( 1._10 )
print *, epsilon( 1._16 )

end test_presicion

epsilon関数は、与えた精度に対する(数値計算上)最小の正の実数を返す。
*._n (n: 4, 8, 10, 16) で精度を指定できるのは知らなかった。

追記:
精度変更に伴って、指数部分の書式において桁が長くなるので、出力する際は以下のような形で指数部分の桁を指定する必要がある。

write( *, '(e17.5e3)' ) epsilon( 1._WP )