public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Michele Portolan <michele.portolan@imag.fr>
To: ecos-discuss@ecos.sourceware.org
Subject: Re: [ECOS] One question.
Date: Wed, 31 May 2006 07:58:00 -0000	[thread overview]
Message-ID: <447D4B35.30408@imag.fr> (raw)
In-Reply-To: <F7DDB0A5340F2D47966F7AD8DF5447E301342850@INC-MX8.inc.iac>

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

  reply	other threads:[~2006-05-31  7:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-31  6:50 Zhao.Green
2006-05-31  7:58 ` Michele Portolan [this message]
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=447D4B35.30408@imag.fr \
    --to=michele.portolan@imag.fr \
    --cc=ecos-discuss@ecos.sourceware.org \
    /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).