Path: news.mathworks.com!not-for-mail
From: "tudor dima" <tudima.nospam@zahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: What happened to so simple Matlab code?
Date: Thu, 10 Jan 2008 14:52:02 +0000 (UTC)
Organization: uv.es
Lines: 32
Message-ID: <fm5bei$cee$1@fred.mathworks.com>
References: <8220611.1195636303283.JavaMail.jakarta@nitrogen.mathforum.org>
Reply-To: "tudor dima" <tudima.nospam@zahoo.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1199976722 12750 172.30.248.37 (10 Jan 2008 14:52:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 10 Jan 2008 14:52:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869938
Xref: news.mathworks.com comp.soft-sys.matlab:445207



you can see this by simply comparing the outputs of these
two commands :

 >>0.3 + 0.1 == 0.4
 >>0.2 + 0.1 == 0.3

or directly

0.2 + 0.1 - 0.3

there is a paper on floating point representation, it might
have been cited before here :
http://docs.sun.com/source/806-3568/ncg_goldberg.html

crammer008 <luochao2000@hotmail.com> wrote in message
<8220611.1195636303283.JavaMail.jakarta@nitrogen.mathforum.org>...
> Dear all, I have the following code and the corresponding
results:
> +++++++++++++++++++++++++++++++
> >> aa = 0.005:0.01:0.025
> aa =
>     0.0050    0.0150    0.0250
> >> daa = diff(aa)
> daa =
>     0.0100    0.0100
> >> daa(1)-daa(2)
> ans =
>   1.7347e-018
> ++++++++++++++++++++++++++++++++++
> Obviously, we should have daa(1)-daa(2) = 0. Who can tell
me why Matlab can not give the correct result? Thanks!