From: Paul Rubin on 6 May 2010 02:55
see(a)sig.for.address (Victor Eijkhout) writes:
> 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.
The math.log function has a special hack for long ints, that might help:
Python 2.6.2 (r262:71600, Jan 25 2010, 18:46:47)
>>> from math import *
>>> a = log(3**100000)
>>> b = log(3**100001)
From: Mark Dickinson on 6 May 2010 04:22
On May 3, 9:49 pm, s...(a)sig.for.address (Victor Eijkhout) wrote:
> Jerry Hill <malaclyp...(a)gmail.com> wrote:
> > >>> from __future__ import division
> > >>> long1/long2
> > 0.5
> Beautiful. Thanks so much guys.
And if for some reason you don't want to use the 'from __future__'
import, then you can do long1.__truediv__(long2):
>>> n = 765*10**1000 + 1
If you care about speed at all, I'd avoid the Fractions solution; it
does an expensive and slow gcd computation.