- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
6 15 33
sngl dbl extd
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 precThe printed precision values are in decimal digits, and are
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]
6 15 33
sngl dbl extd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
thanks.
david
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page