Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

incorrect result..

Deleted_U_Intel
Employee
540 Views
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?

Message Edited by blackash on 12-02-2004 09:11 AM

0 Kudos
3 Replies
Steven_L_Intel1
Employee
540 Views
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.
0 Kudos
TimP
Honored Contributor III
540 Views
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.
0 Kudos
Steven_L_Intel1
Employee
540 Views
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.
0 Kudos
Reply