danb_83 at yahoo.com
Thu Jul 29 09:37:13 CEST 2004
Michael Hudson <mwh at python.net> wrote in message news:<m3k6wpk2i9.fsf at pc150.maths.bris.ac.uk>...
> janeaustine50 at hotmail.com (Jane Austine) writes:
> > >>> from math import e
> > >>> e**709
> > >>> e**710
> > Traceback (most recent call last):
> > File "<pyshell#15>", line 1, in -toplevel-
> > e**710
> > OverflowError: (34, 'Result too large')
> > What should I do to calculate e**710?
> Well, it's too big for your platform's C double, so you need a
> different representation. I don't know if there are big float
> packages out there that handle such things (likely, though) or if
> there are Python interfaces to the same (less likely).
You can also do it with rationals:
>>> def unboundedRange(start=0):
... n = start
... while True:
... yield n
... n += 1
>>> def exp(x, tolerance=rational(1, 10**8)):
... total = term = 1
... for n in unboundedRange(1):
... term *= rational(x, n)
... total += term
... if abs(term) < tolerance:
... return total
However, I don't recommend this, because it's *very* slow.
More information about the Python-list