janeaustine50 at hotmail.com
Sat Jul 31 17:10:36 CEST 2004
danb_83 at yahoo.com (Dan Bishop) wrote in message news:<ad052e5c.0407282337.4cefac1e at posting.google.com>...
> 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:
> ... break
> ... return total
> >>> float(exp(1))
> >>> long(exp(710))
> However, I don't recommend this, because it's *very* slow.
Interesting. Where do I get the "rational" module?
More information about the Python-list