Skip to main content

F90 compiler

Double Precision

In F90, double precision can be handled in various ways.

Using Fortran KIND command

One of them is using the KIND command in F90.

Example Program:

A simple example is given below:
PROGRAM TEST_DOUBLE
IMPLICIT NONE
!
INTEGER, PARAMETER :: num = KIND(1.E0)
INTEGER, PARAMETER :: dbl = KIND(1.D0)
!
REAL(num), PARAMETER :: pi1=0.12345678901234567890_num
REAL(dbl), PARAMETER :: pi2=0.12345678901234567890_dbl
REAL(num), PARAMETER :: pi3=0.12345678901234567890
REAL(dbl), PARAMETER :: pi4=0.12345678901234567890
REAL*8, PARAMETER :: pi5=0.12345678901234567890
REAL*4, PARAMETER :: pi6=0.12345678901234567890
!
write(*,*)'num = KIND(1.E0)',num
write(*,*)'dbl = KIND(1.D0)',dbl
write(*,*)'REAL(num) :: pi=0.12345678901234567890_num',pi1
write(*,*)'REAL(dbl) :: pi=0.12345678901234567890_dbl',pi2
write(*,*)'REAL(num) :: pi=0.12345678901234567890',pi3
write(*,*)'REAL(dbl) :: pi=0.12345678901234567890',pi4
write(*,*)'REAL :: pi5=0.12345678901234567890',pi5
write(*,*)'REAL :: pi6=0.12345678901234567890',pi6
!
STOP
END PROGRAM TEST_DOUBLE
You can compile the program wthout any compiler options.
pgf90 program.f90

Then the output is:

Sample Output:

A sample output is given below:
  num = KIND(1.E0)
  dbl = KIND(1.D0)
  REAL(num) :: pi=0.12345678901234567890_num  0.1234568
  REAL(dbl) :: pi=0.12345678901234567890_dbl  0.123456789012346
  REAL(num) :: pi=0.12345678901234567890  0.1234568
  REAL(dbl) :: pi=0.12345678901234567890  0.123456791043282
  REAL*8 :: pi5=0.12345678901234567890  0.123456791043282
  REAL :: pi6=0.12345678901234567890  0.1234568

Using compile option

Perhaps easier way is using the -r8 compiler option. pgf90 -r8 program.f90

Example Program:

A simple example is given below:
PROGRAM TEST_DOUBLE
IMPLICIT NONE
!
INTEGER, PARAMETER :: num = KIND(1.E0)
INTEGER, PARAMETER :: dbl = KIND(1.D0)
!
REAL(num), PARAMETER :: pi1=0.12345678901234567890_num
REAL(dbl), PARAMETER :: pi2=0.12345678901234567890_dbl
REAL(num), PARAMETER :: pi3=0.12345678901234567890
REAL(dbl), PARAMETER :: pi4=0.12345678901234567890
REAL*8, PARAMETER :: pi5=0.12345678901234567890
REAL*4, PARAMETER :: pi6=0.12345678901234567890
!
write(*,*)'num = KIND(1.E0)',num
write(*,*)'dbl = KIND(1.D0)',dbl
write(*,*)'REAL(num) :: pi=0.12345678901234567890_num',pi1
write(*,*)'REAL(dbl) :: pi=0.12345678901234567890_dbl',pi2
write(*,*)'REAL(num) :: pi=0.12345678901234567890',pi3
write(*,*)'REAL(dbl) :: pi=0.12345678901234567890',pi4
write(*,*)'REAL :: pi5=0.12345678901234567890',pi5
write(*,*)'REAL :: pi6=0.12345678901234567890',pi6
!
STOP
END PROGRAM TEST_DOUBLE
You can compile the program wthout any compiler options.
pgf90 -r8 program.f90

Then the output is:

Sample Output:

A sample output is given below:
 num = KIND(1.E0)           8
 dbl = KIND(1.D0)           8
 REAL(num) :: pi=0.12345678901234567890_num  0.123456789012346
 REAL(dbl) :: pi=0.12345678901234567890_dbl  0.123456789012346
 REAL(num) :: pi=0.12345678901234567890  0.123456789012346
 REAL(dbl) :: pi=0.12345678901234567890  0.123456789012346
 REAL*8 :: pi5=0.12345678901234567890  0.123456789012346
 REAL :: pi6=0.12345678901234567890  0.123456789012346