Dear Sir:
        Sure, if I try to less precision in output. The result can be round 
back to 0.1.
But if  the dnum1 = 0.00000000001 , dnum2 = dnum1.
Result = dnum1+dnum2 
The result is 0.00000000002
This amaze me.

When dnum1  = 0.00000000001, the register show this value is 
9.9999999999999994e-12.



BR
Green



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paul D. DeRocco
Sent: Wednesday, May 31, 2006 2:29 PM
To: eCos Discuss
Subject: RE: [ECOS] One question.

> From: [EMAIL PROTECTED]
>
>       I use the ecos package , and I found the double type question Double 
> dnum1 = 1234567.1 Double dnum2 = 1234567 Double result = 0 ;
>
> Result = dnum1-dnum2 ;
>
> The result is 0.10000000009
>
> Anybody know how to solve this question?

0.1 can't be represented exactly in binary, so there's an inevitable roundoff 
error. Sometimes these errors are hidden by the implementation of the binary to 
decimal conversion used in printing out the answer, but sometimes not. I don't 
know if you're using printf in C, or << in C++, but you might try requesting 
less precision in the output, to see if that rounds the result back to 0.1.

--

Ciao,               Paul D. DeRocco
Paul                mailto:[EMAIL PROTECTED]


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply via email to