Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confusing double precision real in Fortran

Tags:

fortran

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...

  1. How should I be declaring double precision real now?
  2. Is kind redundant in REAL(kind=dp)?
  3. Are there any special flags needed at compile time to invoke double precision real with gfortran or ifort?
like image 500
Joel DeWitt Avatar asked Mar 12 '14 19:03

Joel DeWitt


People also ask

How do you specify double precision in Fortran?

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 .

What does REAL * 4 mean in Fortran?

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.

IS REAL * 8 double precision?

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.


1 Answers

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
like image 105
High Performance Mark Avatar answered Oct 21 '22 10:10

High Performance Mark