narelle
07-02-2007, 11:11 AM
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