REAL_PRECISION is a directory of FORTRAN90 programs which illustrate the procedure for choosing the precision with which real variables and constants are stored.
FORTRAN90 added a number of arithmetic inquiry functions:
The function ID = SELECTED_REAL_KIND(P,R) can be used to request a "kind" (which will be an integer) that identifies a real type with the given number of decimal digits of precision and exponent range.
Sadly, the reality is that each compiler is free to choose the values of ID that are valid, as well as the number and properties of its real data types. The only requirement is that there be at least two real types, with one more accurate than the other! Moreover, for historical reasons, any compiler may support nonstandard types, such as REAL*16. Thus, if you are used to hardcoding declarations such as "real ( kind = 8 ) x", the fact that they work on your system is no guarantee they will even compile on another compiler.
Only the use of the selected_real_kind function allows you to write code that will at least compile, if not run. (It might not run because the precision you requested might not be available. My compiler returns a -1 in that case for the identifier, and if I use that identifier as the kind value, the program aborts.)
Real variables can be declared to have a particular type using a declaration such as real ( kind = id ) r
Constants can be specified to beof the given type by appending an underscore and the kind identifier:
1.0_id 3.14159_id 1.0E+17_id
The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.
REAL_PRECISION is available in a FORTRAN90 version.
F90, FORTRAN90 programs which illustrate features of the FORTRAN90 language.
G95_QUADMATH, a FORTRAN90 program which illustrates the use of quadruple precision real arithmetic provided on some systems by the G95 compiler for FORTRAN.
GFORTRAN_QUADMATH, a FORTRAN90 program which illustrates the use of quadruple precision real arithmetic provided on some systems by the Gnu GFORTRAN compiler for FORTRAN90.
REAL_KIND16 attempts to declare single, double and quadruple precision real data using the NONSTANDARD statements REAL ( KIND = 4 ), REAL ( KIND = 8 ), and REAL ( KIND = 16 ). The G95 compiler seems to support this language, while GFORTRAN does not.
REAL_KIND_DEFAULT declares a real variable of default type and then uses inquiry functions to determine the characteristics of that type.
REAL_KIND_PRECISION6 requests a real type that guarantees a precision of 6 decimal digits, and uses inquiry functions to determine the characteristics of that type.
REAL_KIND_PRECISION12 requests a real type that guarantees a precision of 12 decimal digits, and uses inquiry functions to determine the characteristics of that type.
REAL_KIND_PRECISION18 requests a real type that guarantees a precision of 18 decimal digits, and uses inquiry functions to determine the characteristics of that type.
REAL_KIND_PRECISION24 requests a real type that guarantees a precision of 24 decimal digits, and uses inquiry functions to determine the characteristics of that type. This request FAILS with the GFORTRAN compiler, but succeeds with the G95 compiler.
You can go up one level to the FORTRAN90 source codes.