Real kinds in Fortran
One third at 32 and 64 bits: iso_fortran_env names the precisions portably.
program real_kinds
! iso_fortran_env names the kinds portably: real32, real64.
use iso_fortran_env, only: real32, real64
implicit none
real(real32) :: single = 1.0_real32 / 3.0_real32
real(real64) :: double = 1.0_real64 / 3.0_real64
print *, "single: ", single
print *, "double: ", double
print *, "epsilon at 32 bits: ", epsilon(single)
print *, "epsilon at 64 bits: ", epsilon(double)
print *, "largest double: ", huge(double)
end program real_kinds
How it works
use iso_fortran_env, only: real32, real64imports the kind constants.1.0_real64stamps the kind on the literal, not just the variable.epsilonandhugereport each kind's precision and ceiling.
Keywords and builtins used here
endepsilonhugeimplicitnoneonlyprintprogramrealuse
The run, in numbers
- Lines
- 13
- Characters to type
- 456
- Tokens
- 75
- Three-star pace
- 60 tpm
At the three-star pace of 60 tokens a minute, this run takes about 75 seconds.
Step 1 of 3 in Kinds & modules, step 22 of 27 in Language basics.