Have this burning question on my mind right now: What is the "accepted" way to declare double precision real in modern Fortran? In order from oldest to newest, the story seems to go like this: DOUBLE PRECISION
, then REAL(kind=8)
, then INTEGER, PARAMETER :: dp=kind(1.d0)
with REAL(kind=dp)
--Metcalf now says dp=kind(0.d0)
--and now float32=selected_real_kind(6,37)
or float64=selected_real_kind(15,307)
. So...
kind
redundant in REAL(kind=dp)
?gfortran
or ifort
?A double-precision exponent consists of the letter D , followed by an optional plus or minus sign, followed by an integer. A double-precision exponent denotes a power of 10. The value of a double-precision constant is the product of that power of 10 and the constant that precedes the D .
The "real*4" statement specifies the variable names to be single precision 4-byte real numbers which has 7 digits of accuracy and a magnitude range of 10 from -38 to +38. The "real" statement is the same as "real*4" statement in nearly all 32-bit computers.
A REAL(8) or DOUBLE PRECISION constant has more than twice the accuracy of a REAL(4) number, and greater range. A REAL(8) or DOUBLE PRECISION constant occupies eight bytes of memory. The number of digits that precede the exponent is unlimited, but typically only the leftmost 15 digits are significant.
Personally I now write
use, intrinsic :: iso_fortran_env
which includes parameters such as int32
,real64
which have the obvious meanings, and can be used like this:
real(real64) :: a_64_bit_real_scalar
Note that kind=8
is not guaranteed, by the standard, to deliver an 8-byte kind. The values that kind parameters take are not standardised and do vary from compiler to compiler.
You could, if you want, write statements such as
use, intrinsic :: iso_fortran_env, dp=>real64
...
real(dp) :: a_64_bit_real_scalar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With