newbie: precision question
paul.hermeneutic at gmail.com
Sat Mar 21 04:31:26 CET 2009
On Sat, 2009-03-21 at 04:12 +0100, Lada Kugis wrote:
> I'm a newbie learning python, so forgive for, what may seem to some,
> like a stupid question.
> I understand the basic integer and fp type, but what I'm having a
> little trouble are the long type and infinite precision type.
> Also, when I do
> >>> math.pi - (math.sqrt(math.pi))**2.
> I get
> Please, could someone in just a few words, in newbie speak, explain
> why does that happen ? And what do the types actually mean ? What I
> mean, how can something have infinite precision but still not return
> zero as a result. (Btw, I always thought floating points had precision
> up to 8 significant digits, doubles 16).
> Nice regards
The types used here are 'float'.
Floating point is inherently imprecise. Whatever encoding is used to
represent the number will have a finite size. That finite size puts a
limit on the precision available.
Do you see how small a number the result represents
>>> print "%2.32f" % (4.4408920985006262e-016)
Have you tried this in any other programming languages?
More information about the Python-list