Software Archive
Read-only legacy content
17061 Discussions

Floating point accuracy

Intel_C_Intel
Employee
622 Views
I defined a variable of data type REAL(8), say R8. Assign an arithmetic expression to it (R8 = 1.1 * 11.0). The result I got was 12.1000002622604370 not 12.1000000000000000. Is there any option can be set for compiling.
0 Kudos
3 Replies
sabalan
New Contributor I
622 Views
Project / Settings... / Fortran / Fortran Data -- Change "Default Real Kind" to "8", OR simply write R8 = 1.1D0 * 11.0D0 instead.

Sabalan.
0 Kudos
Intel_C_Intel
Employee
622 Views
I try that, but it gives me 12.1000000000000014. Is there any way that can gives actually 12.1000000000000000 or 12.1?
0 Kudos
Steven_L_Intel1
Employee
622 Views
Be sure to read our next newsletter issue, which should be out soon - sent to registered users. It has an article that covers this topic.

First of all, when you say 1.1*11.0, that's a single-precision expression. You should say 1.1D0*11.0D0 instead. Single precision is typically good to 6-7 significant decimal digits - you got 8.

Double precision (REAL*8) is good to about 15 decimal digits, you got 16. The value 12.1 is not exactly representable in binary floating point.

You should display your results to fewer significant digits, which will tend to give you results that look closer to what you want.

Steve
0 Kudos
Reply