- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello!
I need to set a variable "n" which is equal to 10E21. When I declare it as a "real" number, it appears to be 9.9999998E+021, and when I declare it as a "double precision" number, it appears to be 9.999999778196308E+021.
What should I do to make n=10E21 exactly.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Double precision is good to only about 15 decimal digits. You could try quad precision (REAL(16)) which is good to 33 digits, but that will be a lot slower.
While integer values are exactly representable, assuming there are enough bits in the datatype, many decimal fractions are not.
While integer values are exactly representable, assuming there are enough bits in the datatype, many decimal fractions are not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Keremusu,
You might find this insightful
program
literals real(8) :: a, ba = 10E21
b = 10E21_8
write(*,*) a,bend
program literalsJim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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