- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Real(4) :: B
Real(8) :: C
Real(16) :: D
B=1/10.0
C=1/10.0
D=1/10.0
Result....
B=0.1000000
C=0.100000001490116
D=0.100000001490116119384765625000000
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
your statments are solved from right to left.
step one dividing a integer constant with a real constant. (both by default kind 4)
step two assigning to your variable
To get different results you have to change your constants
in line 7 to real*18
Frank
your statments are solved from right to left.
step one dividing a integer constant with a real constant. (both by default kind 4)
step two assigning to your variable
To get different results you have to change your constants
[bash]real*4 :: rb real*8 :: rc real*16:: rd rb=1/10.0 rc=1/10.0D0 rd=1/10.0Q0 write(6,'(1f40.38)')rb write(6,'(1f40.38)')rc write(6,'(1f40.38)')rd[/bash]In line 6 the constant is changed to real*8
in line 7 to real*18
Frank
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A value like 1/10 can not be represented exactly as a finite binary fraction, just like 1/3 can not
be represented as an exact finite decimal fraction.
You get the best approximation that is possible with single-precision, double- and quadruple-precision.
If you convert the number back to a decimal representation, there simply has to be a slight bias.
Regards,
Arjen
be represented as an exact finite decimal fraction.
You get the best approximation that is possible with single-precision, double- and quadruple-precision.
If you convert the number back to a decimal representation, there simply has to be a slight bias.
Regards,
Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
your statments are solved from right to left.
step one dividing a integer constant with a real constant. (both by default kind 4)
step two assigning to your variable
To get different results you have to change your constants
in line 7 to real*18
Frank
your statments are solved from right to left.
step one dividing a integer constant with a real constant. (both by default kind 4)
step two assigning to your variable
To get different results you have to change your constants
[bash]real*4 :: rb real*8 :: rc real*16:: rd rb=1/10.0 rc=1/10.0D0 rd=1/10.0Q0 write(6,'(1f40.38)')rb write(6,'(1f40.38)')rc write(6,'(1f40.38)')rd[/bash]In line 6 the constant is changed to real*8
in line 7 to real*18
Frank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Argh, missed that "obvious" bit. Actually, it is not from right to left, but the right-hand side is
evaluated without regard to the left-hand side. So, indeed: 1/10.0 is evaluated using single-precision
as that is the highest precision in the two operands and then it is converted to the precision of the
left-hand side.
Regards,
Arjen
evaluated without regard to the left-hand side. So, indeed: 1/10.0 is evaluated using single-precision
as that is the highest precision in the two operands and then it is converted to the precision of the
left-hand side.
Regards,
Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Repeat using 8.0 or 16.0 in place of 10.0 and you will probably find the answer yourself.

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