[SciPy-user] Can SciPy compute ln(640320**3 + 744)/163**.5 to 30 places?
fperez.net at gmail.com
Mon Jan 15 14:03:05 CST 2007
On 1/15/07, Dick Moores <rdm at rcblue.com> wrote:
> Of, course! I forgot about integer division. Thanks, Vincent and Darren.
> But I still don't get the precision:
> # clnumTest3-c.py
> from __future__ import division
> import clnum as n
> print repr(n.exp(n.log(5/23)*2/7))
> gets mpf('0.6466073240654112295',17)
> How come?
Because you shoulnd't use
from __future__ import division
in this case, since that will turn 5/23 into a plain float, with
64-bit accuracy (well, 53 bits for the mantissa, really).
In : n.set_default_precision(50)
In : n.exp(n.log(n.mpq(5,23)*n.mpq(2,7)))
In : n.exp(n.log(n.mpq('5/23')*n.mpq('2/7')))
clnum exposes true rationals, so you can use them for a computation
such as this one.
In this regard SAGE has the convenience that it preparses your input
to apply on-the-fly conversions so that all objects are treated either
as rationals or as extended-precision floats. This has a performance
impact so it's not a good choice for everyday numerics, but it does
save a lot of typing and makes it a bit more convenient for this kind
Which of the two approaches (full SAGE or clnum/mpfr inside regular
python) suits your needs best is a question only you can answer.
ps - due to security problems, the public SAGE notebook is
unfortunately down at the moment.
More information about the SciPy-user