On Mon, 03 May 2010 17:30:03 +0200, Peter Otten <__pete...@web.de> wrote: > Victor Eijkhout wrote: > >> I have two long ints, both too long to convert to float, but their ratio >> is something reasonable. How can I compute that? The obvious "(1.*x)/y" >> does not work. > >>>> import fractions >>>> x = 12345 * 10**1000 >>>> y = 765 * 10**1000 >>>> float(x) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > OverflowError: long int too large to convert to float >>>> fractions.Fraction(x, y) > Fraction(823, 51) >>>> float(_) > 16.137254901960784
Does this still work if y = 765 * 10**1000 + 1 ? It looks as if it might rely on x and y having a large common divisor. (I blush to confess that my Python has no fractions module, and it's too early in the morning to risk trying to update anything.) -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list