working with VERY large 'float' and 'complex' types

Paul Rubin http
Wed Sep 14 15:30:53 EDT 2005


"Todd Steury" <sciurus1 at iwon.com> writes:
> or 1.#INDj. However I really need these numbers to be calculated (although 
> precision isn't key). Is there a way to get python to increase the size 
> limit of float and complex numbers? 

Python just uses machine doubles by default.  You might be able to edit
the source so it uses, say, 80-bit extended floats if you're on a machine
that supports them (like the x86).  Those do support larger exponents.

You could also use something like gmpy, which supports arbitrary size
and arbitrary precision numbers.  Of course it's slow by comparison.

> Since I learn best by example, how could one solve the following problem:
> 
> from math import exp
> >>>x=1000.
> >>>z=exp(x)
> 
> so that z returns an actual value

You could rearrange your formulas to not need such big numbers:

    x = 1000.
    log10_z = x / math.log(10)
    c,m = divmod(log10_z, 1.)
    print 'z = %.5fE%d' % (10.**c, m)



More information about the Python-list mailing list