- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am relatively new at Fortran 90 and have run into a problem with some code I am writing. I have a SuSe Linux Operating System and am running Intel Fortran Compiler 9.0. What is happening is that I am getting really low precision with all the variables in my code. As an example, consider the simple code:
PROGRAM Precision
IMPLICIT NONE
INTEGER, PARAMETER :: DP = SELECTED_REAL_KIND(P=15)
REAL(KIND = DP) :: precise = 1234.5678901
WRITE(*,*) precise
END PROGRAM Precision
The result I get is: 1234.56787109375
If I change the value of precise to 123456789.01, the answer I get is 123456792.000000.
Clearly this is not correct.
I was advised that using SELECTED_REAL_KIND was the most portable approach to assigning kinds. I tried a few other variations and the precision was just as bad. I must be missing something, but I just can't see what? Any help would be much appreciated.
Narelle
PROGRAM Precision
IMPLICIT NONE
INTEGER, PARAMETER :: DP = SELECTED_REAL_KIND(P=15)
REAL(KIND = DP) :: precise = 1234.5678901
WRITE(*,*) precise
END PROGRAM Precision
The result I get is: 1234.56787109375
If I change the value of precise to 123456789.01, the answer I get is 123456792.000000.
Clearly this is not correct.
I was advised that using SELECTED_REAL_KIND was the most portable approach to assigning kinds. I tried a few other variations and the precision was just as bad. I must be missing something, but I just can't see what? Any help would be much appreciated.
Narelle
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You want consistently typed constants, such as 1234.5678901_DP where DP was declared as you stated. By the rules of Fortran, for over 40 years, a default real constant is not promoted according to context. ifort has options to change that, but you said you wanted portability.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Many thanks for that.
N
N
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
is it possible to use 80-bit real variables?
i tried with
selected_real_kind(P=19)
but all i get are 128-bit variables
i don't want to use 128-bit as it is software emulated and i need at least some performance
i tried with
selected_real_kind(P=19)
but all i get are 128-bit variables
i don't want to use 128-bit as it is software emulated and i need at least some performance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, we don't support 80-bit reals and that format is not supported by the SSE instructions.. Perhaps you can restrict the use of REAL(16) to those parts of the application that need the extra precision.

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