Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!news.glorb.com!news-in-01.newsfeed.easynews.com!core-easynews!easynews.com!easynews!en-nntp-09.am2.easynews.com.POSTED!not-for-mail
From: Jean-Marc Gulliet <jeanmarc.gulliet@gmail.com>
Organization: The Open University, Milton Keynes, UK
User-Agent: Thunderbird 2.0.0.18 (Macintosh/20081105)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: I don't even know what subject this lies under. Simple question:
References: <gj77s6$hc9$1@fred.mathworks.com> <gj793k$t4p$1@fred.mathworks.com>
In-Reply-To: <gj793k$t4p$1@fred.mathworks.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 37
Message-ID: <y5G5l.5731$iR2.3801@en-nntp-09.am2.easynews.com>
X-Complaints-To: abuse@easynews.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sun, 28 Dec 2008 08:42:22 +0100
Xref: news.mathworks.com comp.soft-sys.matlab:508947


Jiro Doke wrote:
> "Kian " <kian.torab@utah.edu> wrote in message <gj77s6$hc9$1@fred.mathworks.com>...
>>>> 9*0.0006 - 0.0054
>> ans =
>>
>> -8.6736e-019
>>
>> MathWorks is closed until Monday. It's driving me insane. Does anyone know what's going on? The answer should be 0.
>>
>> This works:
>>
>> K>> (0.0006 + 9*6/10000) - 0.006
>>
>> ans =
>>
>> 0
>>
>> Any idea what's going on?
> 
> Read about floating point arithmetic:
> 
> http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f2-12135.html#f2-98645
> Especially,
> http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f2-12135.html#bqxyrhp
> 
> Here's also some technical notes on the website:
> 
> http://www.mathworks.com/support/tech-notes/1100/1108.html

In addition, the article "What Every Computer Scientist Should Know 
About Floating-Point Arithmetic", by David Goldberg, may be worth 
reading or, at least, browsing.

http://docs.sun.com/source/806-3568/ncg_goldberg.html

Regards,
-- Jean-Marc