Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://crydee.sai.msu.ru/f90/c13.html
Дата изменения: Sat Feb 10 20:31:34 1996 Дата индексирования: Mon Oct 1 19:46:50 2012 Кодировка: Поисковые слова: astrophysics |
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_variablesIf 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_variablesRegrettably now we have to give all floating point constants with the additional suffix _WP, for example
REAL(KIND=WP) :: PI PI = 3.141592653589793_WPwhile 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.