long int computations
Mark Dickinson
dickinsm at gmail.com
Thu May 6 04:22:09 EDT 2010
On May 3, 9:49 pm, s... at sig.for.address (Victor Eijkhout) wrote:
> Jerry Hill <malaclyp... at 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
>>> n.__truediv__(n+1)
1.0
If you care about speed at all, I'd avoid the Fractions solution; it
does an expensive and slow gcd computation.
--
Mark
More information about the Python-list
mailing list