REAL()对所有实数转换使用泛型,但SNGL()也可以用于特定情况:
integer, parameter :: sp = kind(1e0), dp = kind(1d0)
real(x) !converts to the default kind, which is the single precision
!sngl(x) does the same thing
real(x, sp) ! converts to the kind sp (single precision)
real(x, dp) ! converts to the kind dp (double precision)
Run Code Online (Sandbox Code Playgroud)
与复杂它是相同的,但使用CMPLX():
cmplx(x) !converts to the default kind, which is the single precision
cmplx(x, sp) ! converts to the kind sp (single precision)
cmplx(x, dp) ! converts to the kind dp (double precision)
Run Code Online (Sandbox Code Playgroud)
在赋值时,转换是隐式的,您不必(但可以)使用这些显式转换函数.
单精度和双精度的整个概念有些过时,并被Fortran 90种取代.