Документ взят из кэша поисковой машины. Адрес оригинального документа : http://crydee.sai.msu.ru/f90/c13.html
Дата изменения: Sat Feb 10 20:31:34 1996
Дата индексирования: Mon Oct 1 19:46:50 2012
Кодировка:
The new precision concept

13. The new precision concept

The problem with the older versions of Fortran was that simple precision on one computer could correspond to a higher precision or DOUBLE precision on another computer and that the data type DOUBLE PRECISION COMPLEX or COMPLEX*16 was not available in all systems (and of course not in the standard).

In Fortran 90 there are standard functions to check the precision of variables (see Appendix 5, section 8, where for example PRECISION(X) gives the number of significant digits in numbers of the same kind as the variable X). In Fortran 90 there are also possibilities to specify for each variable how many significant digits can be used with the floating-point numbers of this kind. The two common precisions single precision (SP) and double precision (DP) on a system based on IEEE 754 can specified with

  INTEGER, PARAMETER     :: SP = SELECTED_ REAL_ KIND(6,37)
  INTEGER, PARAMETER     :: DP = SELECTED_REAL_KIND(15,307)

  REAL(KIND=SP)          ::  single_precision_variables
  REAL(KIND=DP)          ::  double_precision_variables
If we wish to work with at least 14 decimal digits accuracy and at least decimal exponents between - 300 and + 300 we can choose the following integer parameters
  INTEGER, PARAMETER     :: WP = SELECTED_REAL_KIND(14,300)

  REAL(KIND=WP)          :: working_precision_variables
Regrettably now we have to give all floating point constants with the additional suffix _WP, for example
  REAL(KIND=WP)   :: PI
  PI = 3.141592653589793_WP
while since the intrinsic functions are generic, they will automatically use the correct data type and kind, which means that the argument determines which kind the result should have (usually the same as the argument).

With this method you will in practice obtain double precision on systems based on IEEE 754 and single precision on computers like Cray or computers based based on the Digital Equipment Alpha-processor, which in all cases means a precision of about 15 significant digits.


Last modified: 16 November 1995
boein@nsc.liu.se