Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Precision of Fortran Variables

npmb2
Beginner
734 Views
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
0 Kudos
4 Replies
TimP
Honored Contributor III
734 Views
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.
0 Kudos
npmb2
Beginner
734 Views
Many thanks for that.
N
0 Kudos
jeiglspe
Beginner
734 Views
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
0 Kudos
Steven_L_Intel1
Employee
734 Views
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.
0 Kudos
Reply