根据最后得到的实数Kind。
[Fortran] 纯文本查看 复制代码 program test_precision
use, intrinsic :: iso_fortran_env
implicit none
integer, parameter :: sp = REAL32
integer, parameter :: dp = REAL64
integer, parameter :: qp = REAL128
real(kind = sp) :: x1 = 0.0
real(kind = dp) :: x2 = 0.0
real(kind = qp) :: x3 = 0.0
write(*,'(A,I4,A,G0,A,I6)') "Max number in ", sp*8, " bits = ", huge(x1), " Max power to e= ", floor(log(huge(x1)))
write(*,'(A,I4,A,G0,A,I6)') "Max number in ", dp*8, " bits = ", huge(x2), " Max power to e= ", floor(log(huge(x2)))
write(*,'(A,I4,A,G0,A,I6)') "Max number in ", qp*8, " bits = ", huge(x3), " Max power to e= ", floor(log(huge(x3)))
end program test_precision
结果:
Max number in 32 bits = 0.340282347E+39 Max power to e= 88
Max number in 64 bits = 0.17976931348623157E+309 Max power to e= 709
Max number in 128 bits = 0.118973149535723176508575932662800702E+4933 Max power to e= 11356 |