- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Project / Settings... / Fortran / Fortran Data -- Change "Default Real Kind" to "8", OR simply write R8 = 1.1D0 * 11.0D0 instead.
Sabalan.
Sabalan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I try that, but it gives me 12.1000000000000014. Is there any way that can gives actually 12.1000000000000000 or 12.1?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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

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