- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a problem with the conversion from single to double precision.
With the following statements and results:
real a
real*8 b
a=3. shows in Watch: 3.000000
b=3.d0 shows 3.00000000000000
and
b=a shows 3.00000000000000 sofar so good
BUT
a=3.1 shows 3.100000
b=a shows 3.09999990463257
and
b=2.d0*b shows 6.199999980926514
so the wrong bits are kept and used.
I got the same (!) results with the CVF compiler
a reason to try the Intel compiler.
Question: what am I doing wrong or mis-understanding?
With the following statements and results:
real a
real*8 b
a=3. shows in Watch: 3.000000
b=3.d0 shows 3.00000000000000
and
b=a shows 3.00000000000000 sofar so good
BUT
a=3.1 shows 3.100000
b=a shows 3.09999990463257
and
b=2.d0*b shows 6.199999980926514
so the wrong bits are kept and used.
I got the same (!) results with the CVF compiler
a reason to try the Intel compiler.
Question: what am I doing wrong or mis-understanding?
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Read the three-part article "The Perils of Real Numbers", starting here. The correct bits are being used, but you are missing the difference between binary fractions and decimal fractions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - verboomziggo.nl
I have a problem with the conversion from single to double precision.
With the following statements and results:
real a
real*8 b
a=3. shows in Watch: 3.000000
b=3.d0 shows 3.00000000000000
and
b=a shows 3.00000000000000 sofar so good
BUT
a=3.1 shows 3.100000
b=a shows 3.09999990463257
and
b=2.d0*b shows 6.199999980926514
so the wrong bits are kept and used.
I got the same (!) results with the CVF compiler
a reason to try the Intel compiler.
Question: what am I doing wrong or mis-understanding?
With the following statements and results:
real a
real*8 b
a=3. shows in Watch: 3.000000
b=3.d0 shows 3.00000000000000
and
b=a shows 3.00000000000000 sofar so good
BUT
a=3.1 shows 3.100000
b=a shows 3.09999990463257
and
b=2.d0*b shows 6.199999980926514
so the wrong bits are kept and used.
I got the same (!) results with the CVF compiler
a reason to try the Intel compiler.
Question: what am I doing wrong or mis-understanding?
0.1 is an infinately repeating binary fraction and therefor cannot be precisely represented in neither real*4 nor real*8. Therefore 3.1 cannot be precisely represented.
b=a shows 3.09999990463257
and
b=2.d0*b shows 6.199999980926514
try
b=3.1D0
b=2.D0*b
Jim Dempsey

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