[G4] 2 + 2 = 4.000000001?

Doug McNutt douglist at macnauchtan.com
Thu Feb 26 19:43:47 PST 2004


At 19:56 -0600 2/26/04, Kevin Willis wrote:
>Try 521.82 plus anything.  That is just one example from tonight.  I have noticed it with a lot of other numbers.

At 17:45 -0500 2/26/04, Kevin Willis wrote:
> When I add a string of whole numbers together

You confused us all when you said "whole numbers".  Fractions typically cannot be expressed exactly in any type of "decimal" system, be it a decimal point or a binary point.  If you were adding *.625 which is one of those fractions - 5/8 -  that is exactly expressible in binary you probably would not see the error.

You show 4.000000001  which is 10 significant digits. IEEE doubles should be good to about 15 digits but someone is rounding off the answer with a format. Or perhaps you should be more careful about counting how many digits you see.

You said you were adding a list.  Were the other numbers fractions too? Were you subtracting large numbers from large numbers?

Amuse yourself by converting 0.82 (10) to binary.

Multiply .82 by 2 to get 1.64.  Write down the 1.
Next multiply 0.64 by 2 to get 1.28. Write down the 1 to show 11
Next multiply 0.28 by 2 to get 0.56, Write down the 0 to show 110
Continue until it comes out exactly. . .

Or perhaps it won't. You only have 52 bits available.

-- 
-->  There are 10 kinds of people:  those who understand binary, and those who don't <--



More information about the G4 mailing list