what's the precision of fractions.Fraction?

Ian Kelly ian.g.kelly at gmail.com
Thu Nov 18 12:13:25 EST 2010


On Thu, Nov 18, 2010 at 9:27 AM, Daniel Fetchinson <
fetchinson at googlemail.com> wrote:

> I do a recursive evaluation of an expression involving fractions and
> unsurprisingly the numerator and denominator grows pretty quickly.
> After 10-20 iterations the number of digits in the numerator and
> denominator (as integers) reaches 80-100. And I'm wondering until what
> point I can trust the result since I'm using fractions.Fraction for
> the whole procedure. Are Fraction's infinite precision? Or will I get
> some sort of an exception if python is not able to represent the
> numerator and/or denominator as integers?
>

Since fractions are represented as a pair of integers, and since python
integers have unlimited precision, I would guess that fractions also have
unlimited precision.  You could check the code if you want to be absolutely
sure.

Cheers,
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101118/e2a20d4a/attachment-0001.html>


More information about the Python-list mailing list