public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: <Zhao.Green@inventec-inc.com>
To: <pderocco@ix.netcom.com>, 	<ecos-discuss@ecos.sourceware.org>
Subject: RE: [ECOS] One question.
Date: Wed, 31 May 2006 06:50:00 -0000	[thread overview]
Message-ID: <F7DDB0A5340F2D47966F7AD8DF5447E301342850@INC-MX8.inc.iac> (raw)

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: 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

             reply	other threads:[~2006-05-31  6:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-31  6:50 Zhao.Green [this message]
2006-05-31  7:58 ` Michele Portolan
2006-05-31 11:49   ` Edgar Grimberg
  -- strict thread matches above, loose matches on Subject: below --
2006-05-31  5:15 Zhao.Green
2006-05-31  6:12 ` Fabian Scheler
2006-05-31  6:28 ` Paul D. DeRocco
2004-06-25  8:09 anton yakovlev
2004-06-25 11:28 ` Gary Thomas
2004-06-26  8:59   ` anton yakovlev
2004-06-26 11:50     ` Gary Thomas
2004-06-26 12:26       ` anton yakovlev
2004-06-26 12:31         ` Gary Thomas
2004-06-26 15:40           ` anton yakovlev
     [not found] ` <40DBE222.8040603@codito.com>
2004-06-26  8:49   ` anton yakovlev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=F7DDB0A5340F2D47966F7AD8DF5447E301342850@INC-MX8.inc.iac \
    --to=zhao.green@inventec-inc.com \
    --cc=ecos-discuss@ecos.sourceware.org \
    --cc=pderocco@ix.netcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).