Weird result returned from adding floats depending on order I add them
John McCallum
spammers-die at spam.microsoft.com
Tue Feb 20 07:55:36 EST 2007
Hi,
> I'm getting different results when I add up a list of floats depending
> on the order that I list the floats. For example, the following returns
>
> [snip summation]
>
> if totalProp != 1:
>From a numerical analysis point of view, never ever do this. The values
you are adding are approximations to the numbers you require, you then
test for equality (the real no no)...
There is even a section in the Python tutorial about it:
http://docs.python.org/tut/node16.html
Cheers,
John McCallum
Edinburgh
More information about the Python-list
mailing list