Python -- floating point arithmetic

Mark Dickinson dickinsm at gmail.com
Thu Jul 8 09:22:39 EDT 2010


On Jul 8, 2:00 pm, Adam Skutt <ask... at gmail.com> wrote:
> On Jul 8, 7:23 am, Mark Dickinson <dicki... at gmail.com> wrote:> On Jul 8, 11:58 am, Adam Skutt <ask... at gmail.com> wrote:
>
> > > accurately.  Moreover, in general, it's impossible to even round
> > > operations involving transcendental functions to an arbitrary fixed-
> > > precision, you may need effectively infinite precision in order to the
> > > computation.
>
> > Impossible?  Can you explain what you mean by this?  Doesn't the
> > decimal module do exactly that, giving correctly-rounded exp() and
> > log() results to arbitrary precision?
>
> You run into the table-maker's dilemma: there's no way to know in
> advance how many digits you need in order to have n bits of precision
> in the result.

Sure.  But it's a bit of a stretch to go from not knowing what
resources you'll need in advance to calling something 'impossible'. :)

> For some computations, the number of bits required to
> get the desired precision can quickly overwhelm the finite limitations
> of your machine (e.g., you run out of RAM first or the time to compute
> the answer is simply unacceptable).

Perhaps in theory.  In practice, though, it's very rare to need to
increase precision more than once or twice beyond an initial first
guesstimate, and the amount of extra precision needed is small.  That
increase is unlikely to cause problems unless you were operating right
up against your machine's limits in the first place.

--
Mark



More information about the Python-list mailing list