Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: How to avoid wrong answers in simple arithmetic expressions.
Replies: 13   Last Post: Jan 20, 2013 7:18 AM

 Messages: [ Previous | Next ]
 S.K.Mody Posts: 31 Registered: 12/13/04
Re: How to avoid wrong answers in simple arithmetic expressions.
Posted: Jan 20, 2013 3:49 AM

"James Tursa" wrote in message <kdfc0c\$v7\$1@newscl01ah.mathworks.com>...

> False. 9 has an exact IEEE double representation. 0.09 does not ... the closest is:
>
> 0.0899999999999999966693309261245303787291049957275390625
>

> > More generally, most integers do not have an exact representation in this format.
>
> False. All of the integers in the range of your particular problem can be represented exactly in IEEE double. All integers from 0 up to 2^53 have exact IEEE double representations.

OK. I got it (after some embarrassment). The IEEE 754 format description on Wikipedia was a bit confusing - all those negative powers of 2! It really boils down to - if a number can be represented as a sum of powers of 2, then it has an exact representation - so all integers (within some range) will have an exact representation.

Nevertheless, it does appear that exact calculations even with integers has to be thought through on a case by case basis.

Best Regards.

> > So, does Matlab treat small integers in a special way?
>
> No. They are treated just like all other IEEE double numbers.
>
>
> James Tursa

Date Subject Author
1/19/13 S.K.Mody
1/19/13 dpb
1/19/13 dpb
1/19/13 S.K.Mody
1/19/13 James Tursa
1/20/13 S.K.Mody
1/20/13 S.K.Mody
1/20/13 Bruno Luong
1/20/13 S.K.Mody
1/20/13 Bruno Luong
1/20/13 S.K.Mody
1/20/13 Bruno Luong
1/20/13 S.K.Mody