Thread Subject: Very simple number equation does not equate.

Subject: Very simple number equation does not equate.

From: sun

Date: 5 Jul, 2009 15:54:52

Message: 1 of 3

Dear matlab gurus,

I encountered a very puzzling problem. 0.2+0.2+0.2+0.15+0.05 clearly adds up
to 0.8. But on matlab R2007b, it does not equate. Why? I have been tearing
my hair apart as this problem looks so simple and yet elusive. Could some
matlab guru enlighten a newbie like me?

Below are what appears on my matlab screen;

>> 0.2+0.2+0.2+0.15+0.05==0.8

ans =

     0

>> 0.2+0.2+0.2+0.14+0.06==0.8

ans =

     1


>> 0.2+0.2+0.2+0.2==0.8

ans =

     1

Subject: Very simple number equation does not equate.

From: us

Date: 5 Jul, 2009 15:59:02

Message: 2 of 3

"sun" <sun@gmail.com> wrote in message <h2qav3$7um$1@reader01.singnet.com.sg>...
> Dear matlab gurus,
>
> I encountered a very puzzling problem. 0.2+0.2+0.2+0.15+0.05 clearly adds up
> to 0.8. But on matlab R2007b, it does not equate. Why? I have been tearing
> my hair apart as this problem looks so simple and yet elusive. Could some
> matlab guru enlighten a newbie like me?
>
> Below are what appears on my matlab screen;
>
> >> 0.2+0.2+0.2+0.15+0.05==0.8
>
> ans =
>
> 0
>
> >> 0.2+0.2+0.2+0.14+0.06==0.8
>
> ans =
>
> 1
>
>
> >> 0.2+0.2+0.2+0.2==0.8
>
> ans =
>
> 1
>

a hint:

http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-0.1_not_equal_to_zero_.28or_similar.29.3F

us

Subject: Very simple number equation does not equate.

From: Matt Fig

Date: 5 Jul, 2009 15:59:03

Message: 3 of 3

Congratulations! You are the 1 millionth user to find this same floating point "bug" in MATLAB. See the link below.

http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-0.1_not_equal_to_zero_.28or_similar.29.3F

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
evergreen us 5 Jul, 2009 12:04:04
faq us 5 Jul, 2009 12:04:04
reference us 5 Jul, 2009 12:04:03
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com