[SciPy-user] Can SciPy compute ln(640320**3 + 744)/163**.5 to 30 places?
Dick Moores
rdm at rcblue.com
Mon Jan 15 15:18:20 CST 2007
At 12:03 PM 1/15/2007, Fernando Perez wrote:
>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
> > n.set_default_precision(40)
> > 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 [3]: n.set_default_precision(50)
>
>In [4]: n.exp(n.log(n.mpq(5,23)*n.mpq(2,7)))
>Out[4]:
>mpf('0.06211180124223602484472049689440993788819875776397515527949',55)
>
>or alternatively:
>
>In [7]: n.exp(n.log(n.mpq('5/23')*n.mpq('2/7')))
>Out[7]:
>mpf('0.06211180124223602484472049689440993788819875776397515527949',55)
That's terrific!
=======================
# clnumTest3-c.py
import clnum as n
n.set_default_precision(50)
a = repr(n.exp(n.log(n.mpq(5,23)*n.mpq(2,7))))
print a
print str(a)[5:-5]
"""
results
mpf('0.06211180124223602484472049689440993788819875776397515527949',55)
0.06211180124223602484472049689440993788819875776397515527949
"""
=========================================
Is there a better way to print the result without the leading "mpf('"
and the trailing "',55)"?
The only clnum manual I found was
<http://calcrpnpy.sourceforge.net/clnumManual.html>, which is
obviously incomplete. How does anyone learn as much about it as you do?
And finally (I think), could you show me how to do division and
multiplication with precision? Say 7596.52/632517 and
123.45678987654321 times 298374.287364827364287346?
>clnum exposes true rationals, so you can use them for a computation
>such as this one.
I do want to use clnum, so I can use it to make some useful functions
to to keep around for use within Python scripts.
Thanks very much,
Dick
More information about the SciPy-user
mailing list