Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

How to setup for extended precision

davidxyzhouyahoo_com
749 Views
Hi,
I am a newbie on Fortran. Please help.

I want to use extended precision. I declare double precision, and real (kind=16) for extended precision. But the write of precision(x) is always 33, which is better than single precision but worse than double precision.

I have use dflib at the beginning of the program.
Any floating operation has only 33 precision.
It seems to me the extended precision library is not used. Is it true, and how?

If the correct lib is setup, how to specify a constant that is in extended precision?

Thank you,
david
0 Kudos
4 Replies
TimP
Honored Contributor III
749 Views
33 digits precision is the most you can expect from real(kind=16), while real(kind=8) would give about 16. If you want more, there are multiple precision libraries. real(kind=16) is "worse" than kind=8 in several respects, if you would care to express your criteria.
I suppose the preferred way to specify a kind=16 constant would be with the _16 suffix or equivalent.
I'm not certain that you have thought through the assertions you have made.
0 Kudos
mecej4
Honored Contributor III
749 Views
I think that you misunderstand at least some of the conventions used.

The suffix used to denote the kind of real constants in Intel Fortran (e.g., _16) refers to the number of bytes used to store a floating point type. Since some bits are used for sign and biased exponent, the corresponding precision is less than (the number of bytes) X 8 bits, or (number of bytes) X 8 X log_2 (10) decimal digits.

I declare double precision, and real (kind=16) for extended precision. But the write of precision(x) is always 33, which is better than single precision but worse than double precision


Not true. Try this program

[fortran]program prec
real a
real*8 b
real*16 c

a=exp(1.0)
b=exp(1d0)
c=exp(1.0_16)

write(*,*)precision(a),precision(b),precision(c)
end program prec
[/fortran]
The printed precision values are in decimal digits, and are

6 15 33

sngl dbl extd
0 Kudos
davidxyzhouyahoo_com
749 Views
Hi,

thanks.

david

0 Kudos
Steven_L_Intel1
Employee
749 Views
A couple of comments. First, while MOST compilers use the size in bytes for the KIND numbers, this is not specified by the standard and some compilers have other schemes. You are better off to use the SELECTED_REAL_KIND intrinsic to determine what your compiler's KIND number is for a required precision or range. For example:

integer, parameter :: k_quad = SELECTED_REAL_KIND(20) ! Want at least 20 decimal digits
real(KIND=k_quad) :: a ! Declare variable of kind k_quad
...
a = 1.0_k_quad ! Constant of type REAL(k_quad)

Also, at least in implementations with typical IEEE float datatypes, as the precision goes up, so does the range. Single is good to about 10**37, double to 10**307 and quad t 10**4931.
0 Kudos
Reply