! This file: ! http://ftp.aset.psu.edu/pub/ger/fortran/hdk/QorDPrecision.f90 ! ! This code allows the compiler to automatically use QP Working ! Precision (wp) if quadruple precision available; or if QP is not ! available, compile using DP Working Precision. ! ! Public domain 2004 by James Van Buskirk ! module mykinds implicit none integer, parameter :: dp = selected_real_kind(15,300) integer, parameter :: qp_preferred = selected_real_kind(30,1000) integer, parameter :: wp = (1+sign(1,qp_preferred))/2*qp_preferred+ & (1-sign(1,qp_preferred))/2*dp end module mykinds program testq use mykinds real(wp) pi pi = 4*atan(1.0_wp) print *, "pi = ",pi print *,"wp =",wp ! ! Output: ! ! CVF (Windows) ! pi = 3.14159265358979 ! wp = 8 ! ! Intel Fortran (32- and 64-bit Linux) ! pi= 3.14159265358979323846264338327950 ! wp= 16 ! ! Lahey Fortran (Windows, 32-bit Linux) ! pi= 3.1415926535897932384626433832795028 ! wp= 16 ! ! PathScale Fortran (64-bit Linux) ! pi= 3.1415926535897931 ! wp= 8 ! ! Absoft Fortran (32-bit Linux) ! pi= 3.14159265358979 ! wp= 8 ! ! Portland Fortran (32-bit Linux) ! pi= 3.141592653589793 ! wp= 8 end program testq