- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
source code
=========================
PROGRAM TEST
IMPLICIT NONE
REAL(kind=8) :: x,y
INTEGER :: i
DO i=1,100
x=REAL(i,8)
y=x*1.D-3
write (*,*) x,y
END DO
END PROGRAM
===========================
result
==========================
....
8.00000000000000 8.000000000000000E-003
9.00000000000000 9.000000000000001E-003
10.0000000000000 1.000000000000000E-002
....
69.0000000000000 6.900000000000001E-002
70.0000000000000 7.000000000000001E-002
71.0000000000000 7.100000000000001E-002
72.0000000000000 7.200000000000001E-002
73.0000000000000 7.300000000000000E-002
....
83.0000000000000 8.300000000000000E-002
84.0000000000000 8.400000000000001E-002
85.0000000000000 8.500000000000001E-002
86.0000000000000 8.600000000000001E-002
87.0000000000000 8.700000000000001E-002
88.0000000000000 8.799999999999999E-002
89.0000000000000 8.900000000000000E-002
.....
===============================================
xeon 2.4Ghz , .l_fc_p_8.1.019, redhat 9.0, kernel 2.4.28
do i miss something ?
i am sorry for my poor English, i can't make a long sentence..
please let me know why the result is like this.
do i make a something wrong? or a bug?
=========================
PROGRAM TEST
IMPLICIT NONE
REAL(kind=8) :: x,y
INTEGER :: i
DO i=1,100
x=REAL(i,8)
y=x*1.D-3
write (*,*) x,y
END DO
END PROGRAM
===========================
result
==========================
....
8.00000000000000 8.000000000000000E-003
9.00000000000000 9.000000000000001E-003
10.0000000000000 1.000000000000000E-002
....
69.0000000000000 6.900000000000001E-002
70.0000000000000 7.000000000000001E-002
71.0000000000000 7.100000000000001E-002
72.0000000000000 7.200000000000001E-002
73.0000000000000 7.300000000000000E-002
....
83.0000000000000 8.300000000000000E-002
84.0000000000000 8.400000000000001E-002
85.0000000000000 8.500000000000001E-002
86.0000000000000 8.600000000000001E-002
87.0000000000000 8.700000000000001E-002
88.0000000000000 8.799999999999999E-002
89.0000000000000 8.900000000000000E-002
.....
===============================================
xeon 2.4Ghz , .l_fc_p_8.1.019, redhat 9.0, kernel 2.4.28
do i miss something ?
i am sorry for my poor English, i can't make a long sentence..
please let me know why the result is like this.
do i make a something wrong? or a bug?
Message Edited by blackash on 12-02-2004 09:11 AM
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The value 1.D-3 is not exactly representable in binary floating point, so the result of the multiplication will not be exact in decimal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
1.D-3 gives you the closest representation in 53 bits binary precision. As you have shown, that is slightly less than 16 decimal digits precision.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The result is correct, for binary floating point arithmetic. You may want to display the value to fewer digits so that it rounds to a decimal number you like.

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