Extended double precision

Is it possible to get more than 16 digits with double precision without using quadruple ? If possible, does it depend on the compiler or something else? Because I know that someone said that it works with double precision and has 22-digit precision.

+6
source share
2 answers

The double precision data type comes from Fortran 77, and the only requirement for this type is that it has higher precision than real . You should no longer use this.

Fortran 90/95 and above support at least two sizes of real numbers. The accuracy is determined by the kind parameter, the value of which depends on the compiler.

 real(kind=8) :: a, b 

To have a portable way of determining accuracy, you can get a kind value that allows for a certain accuracy using:

 integer, parameter :: long_double = SELECTED_REAL_KIND(22) 

then you can declare your variables as

 real(kind=long_double) :: a, b 

but not sure if your compiler will maintain this precision, in which case the SELECTED_REAL_KIND function will return a negative number.

see also this post

+6
source

As stated in the first answer, the most portable way is to determine the accuracy of a number - using internal functions. The concept of language design is that you determine what accuracy is required for your calculation and requests it, and the compiler provides that accuracy or better. For example, if you calculate that your solution to a differential equation is stable with 11 decimal digits, you ask for that value, and the compiler provides the best type that suits your requirements. This is a foreign approach to most programmers who are used to thinking that there are several hardware options, not what they need, and maybe not so simple, since few of us are numerical analysts.

If you want to use the built-in SELECTED_REAL_KIND and optimize for your specific compiler and hardware, you can experiment. Some combinations will provide quadrupole accuracy in software, which will be slow. A double precision compiler with 10-byte extended precision will provide a longer type with selected_real_kind (17). The compiler with double precision and precise accuracy, but not with 10-fold enhanced accuracy, will ensure quadrupole accuracy through selected_real_kind (17) or selected_real_kind (32). (I do not know a single compiler that supports both 10-byte extended and quadrupole ones.) A compiler that lacks quadrupole precision will return -1 for selected_real_kind (32).

+5
source

Source: https://habr.com/ru/post/908038/


All Articles