From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3639 invoked by alias); 31 May 2006 06:50:06 -0000 Received: (qmail 3626 invoked by uid 22791); 31 May 2006 06:50:06 -0000 X-Spam-Flag: YES X-Spam-Check-By: sourceware.org Received: from Unknown (HELO dns3.inventec-inc.com) (218.2.115.174) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 31 May 2006 06:50:01 +0000 Received: from inc-mx6.inc.iac ([10.170.254.86]) by dns3.inventec-inc.com with InterScan Message Security Suite; Wed, 31 May 2006 14:50:39 +0800 Received: from INC-MX8.inc.iac ([10.170.254.181]) by inc-mx6.inc.iac with Microsoft SMTPSVC(6.0.3790.1830); Wed, 31 May 2006 14:49:56 +0800 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset=big5 Content-Transfer-Encoding: quoted-printable Date: Wed, 31 May 2006 06:50:00 -0000 Message-ID: From: To: , X-imss-version: 2.040 X-imss-result: Passed X-imss-scanInfo: M:P L:N SM:0 X-imss-tmaseResult: TT:0 TS:0.0000 TC:00 TRN:0 TV:3.52.1006(14478.001) X-imss-scores: Clean:99.90000 C:2 M:4 S:5 R:5 X-imss-settings: Baseline:2 C:1 M:1 S:1 R:1 (0.1500 0.1500) X-IsSubscribed: yes Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Subject: RE: [ECOS] One question. X-SW-Source: 2006-05/txt/msg00264.txt.bz2 Dear Sir: Sure, if I try to less precision in output. The result can be round back t= o 0.1. But if the dnum1 =3D 0.00000000001 , dnum2 =3D dnum1. Result =3D dnum1+dnum2=20 The result is 0.00000000002 This amaze me. When dnum1 =3D 0.00000000001, the register show this value is 9.9999999999= 999994e-12. BR Green -----Original Message----- From: ecos-discuss-owner@ecos.sourceware.org [mailto:ecos-discuss-owner@eco= s.sourceware.org] On Behalf Of Paul D. DeRocco Sent: Wednesday, May 31, 2006 2:29 PM To: eCos Discuss Subject: RE: [ECOS] One question. > From: Zhao.Green@inventec-inc.com > > I use the ecos package , and I found the double type question Double=20 > dnum1 =3D 1234567.1 Double dnum2 =3D 1234567 Double result =3D 0 ; > > Result =3D 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 roundo= ff error. Sometimes these errors are hidden by the implementation of the bi= nary to decimal conversion used in printing out the answer, but sometimes n= ot. I don't know if you're using printf in C, or << in C++, but you might t= ry requesting less precision in the output, to see if that rounds the resul= t back to 0.1. -- Ciao, Paul D. DeRocco Paul mailto:pderocco@ix.netcom.com -- 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