[Python-Dev] Changes to decimal.py

Nick Maclaren nmm1 at cus.cam.ac.uk
Sat Apr 14 09:25:28 CEST 2007


"Tim Peters" <tim.peters at gmail.com> wrote:
>
> One low-effort approach is to use a general root-finding algorithm and
> build ln(x) on top of exp() via (numerically) solving the equation
> exp(ln(x)) == x for ln(x).  ...

Not a general one, please!  At least use one that assumes the continuity
of second derivatives :-)

> However, the IBM spec requires < 1 ULP worst-case error, and that may
> be unreasonably hard to meet with a root-finding approach.  ...

It's a doddle in a software implementation for civilised functions
like log.  All you do is to do the calculation in a sufficiently
extended precision - and you can work that out in advance for very
little extra effort.  Then you round to the result - and, hey! Bob's
your uncle!  0.501 ULPs is as easy as 1, if a bit slower.

Now, doing that for the power function is a right royal pain in the
neck, and you really DON'T want to even contemplate a generic gamma
function, let alone one of the beta functions :-(  But none of this
is specific to a decimal base, of course.


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1 at cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679


More information about the Python-Dev mailing list