[Fortran] 纯文本查看 复制代码
program main
implicit none
real::x
real(8),external::real4real8
x=1.234
write(*,*)x
write(*,*)real(x,kind=8)
write(*,*)real4real8(x)
end program
function real4real8(r4)result(r8)
real,intent(in)::r4
real(8)::r8
character(len=15)::str
write(str,"(ES15.8E2)")r4
read(str,*)r8
end function real4real8
> 1.23399997
1.2339999675750732
1.2339999699999999
[Fortran] 纯文本查看 复制代码
y=real4real8(x)
write(*,*) x, y
function real4real8(r4)result(r8)
real,intent(in)::r4
real(8)::r8
character(len=15)::str
write(str,"(ES13.6E2)")r4 !此处的 es13.6 的 6 为保留有效数字-1,即7-1=6
read(str,*)r8
end function real4real8