Float** internal representation (Numeric module)

Alexander Sourjikov spb526 at rol.ru
Wed Oct 22 14:59:42 EDT 2003


Thanks  for the usefull link, but in that example
0.1 is represented as 0.10000000000000001.
So the precision is 16 digits, and it is good enough for almost anything.
however, in my case 0.1 equals 0.10000000149011612
and the precision is only 8 digits.
the range of loop in my program reaches 10**8 and for iterative algorithm
where next step is based on the data from the previous one the error is
accomulated and for this number of iterations can become significant.
How can i raise the level of precision to that mentioned in the example ?

Thanks in advance.


> Alexander Sourjikov wrote:
> > Hi pals,
> > i am using python for numerical simulations and noticed that
> > when i assign a Float variable say 0.1 python sees it like
> > 0.10000000149011612.
> > I have also checked if python really takes these digits into account and
> > it turned out to be truth, because variable * 2 gives
> > 0.20000000298023224
> > Does anyone have an idea where these weird digits come from and
> > how to avoid this strange effect ?
>
> Common problem: floats aren't 100% accurate. See question 4.98 of the
> FAQ or http://www.python.org/doc/current/tut/node14.html.
>
> --
> Yours,
>
> Andrei
>
> =====
> Mail address in header catches spam. Real contact info (decode with
rot13):
> cebwrpg5 at bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V
> ernq gur yvfg, fb gurer'f ab arrq gb PP.
>
>
>






More information about the Python-list mailing list