[Tutor] extreme basics
A.T.Hofkamp
a.t.hofkamp at tue.nl
Mon Jan 5 10:58:04 CET 2009
Mr Gerard Kelly wrote:
> This is extremely weird, I think.
>
> Here is a tiny program:
>
> from math import *
> from Numeric import *
>
> x=[0]*10
>
>
> for counter in rangelen((x)):
> x[counter]=counter*0.1
>
> print x
>
> Here is what I get:
>
> [0.0, 0.10000000000000001, 0.20000000000000001, 0.30000000000000004,
> 0.40000000000000002, 0.5, 0.60000000000000009, 0.70000000000000007,
> 0.80000000000000004, 0.90000000000000002]
>
> What on Earth is going on with those decimals at the end? Is this a
> floating point thing?
You can find the answer in the Python FAQ (although it is not a Python thing):
http://www.python.org/doc/faq/general/#why-are-floating-point-calculations-so-inaccurate
Sincerely,
Albert
More information about the Tutor
mailing list