From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12707 invoked by alias); 31 May 2006 07:58:45 -0000 Received: (qmail 11623 invoked by uid 22791); 31 May 2006 07:53:51 -0000 X-Spam-Check-By: sourceware.org Received: from imag.imag.fr (HELO imag.imag.fr) (129.88.30.1) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 31 May 2006 07:52:40 +0000 Received: from rhin.imag.fr (rhin-bis.imag.fr [147.171.129.1]) by imag.imag.fr (8.13.6/8.13.6) with ESMTP id k4V7qXMZ014580 for ; Wed, 31 May 2006 09:52:33 +0200 (CEST) Received: from [147.171.129.95] ([147.171.129.95]) by rhin.imag.fr (8.13.6+Sun/jtpda-5.4) with ESMTP id k4V7qLI4005399 for ; Wed, 31 May 2006 09:52:21 +0200 (CEST) Message-ID: <447D4B35.30408@imag.fr> Date: Wed, 31 May 2006 07:58:00 -0000 From: Michele Portolan User-Agent: Thunderbird 1.5.0.2 (Windows/20060308) MIME-Version: 1.0 To: ecos-discuss@ecos.sourceware.org References: In-Reply-To: Content-Type: text/plain; charset=Big5 Content-Transfer-Encoding: 7bit X-TIMA-MailScanner-Information: Please contact the ISP for more information X-TIMA-MailScanner: Found to be clean X-TIMA-MailScanner-SpamCheck: not spam (whitelisted), SpamAssassin (score=2.298, required 4, BAYES_44 -0.00, DEAR_SOMETHING 2.30) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.6 (imag.imag.fr [129.88.30.1]); Wed, 31 May 2006 09:52:33 +0200 (CEST) X-IMAG-MailScanner-Information: Please contact IMAG DMI for more information X-IMAG-MailScanner: Found to be clean 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/msg00266.txt.bz2 Zhao.Green@inventec-inc.com wrote: > 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. > This is quite normal: floating point use relative precision (depends on the size of the mantissa. When you write 0.00000000001 all zero are normalized, but when you use 1234567 0.1 must be too little if compared to 1234567 in your representation. > When dnum1 = 0.00000000001, the register show this value is 9.9999999999999994e-12. You should try to see the binary representation, once more there must is too much precision in the visualisation primitive. hoping to have helped you, Michele > > > > BR > Green > > > > -----Original Message----- > From: ecos-discuss-owner@ecos.sourceware.org [mailto:ecos-discuss-owner@ecos.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 >> 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: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