[SciPy-user] Can SciPy compute ln(640320**3 + 744)/163**.5 to 30 places?

Robert Kern robert.kern at gmail.com
Mon Jan 15 01:47:48 CST 2007

Dick Moores wrote:
> On 1/14/07, Robert Kern <robert.kern at gmail.com> wrote:
>> Dick Moores wrote:
>>> Please show me how to do that in just plain python. I don't have or
>>> know ipython.
>> It's the same.
> OK. Bryan Van de Ven's code lacked an import statement, a precision
> statement, and a print statement. So I tried
> =====================
> # clnumTest2-a.py
> import clnum as cl
> cl.set_default_precision(50)
> a = cl.log(640320**3 + 744)/cl.sqrt(163)
> print cl.mpq(a)
> =====================
> And got
> 181338285223186289202345004581/57721768930156197489438103340
> Doing that division at the python interactive prompt gets me
> 3.1415926535897927
> hardly the precision I'm after.
> Someone please show me a whole python script.

Fernando already gave you exactly what you needed. You just printed it wrong.
Doing the string interpolation through '%.50f' casts the number to a Python
float object (16 decimal places of precision). If you were you simply print the
object that is the result of the computation (`a` above), you will get the
answer that you are looking for. As you can see from what Fernando showed you,
there is in fact 50 digits of precision using clnum:

In [16]: import clnum as n

In [17]: n.set_default_precision(50)

In [18]: n.log(640320**3 + 744)/n.sqrt(163)
Out[18]: mpf('3.141592653589793238462643383279726619347549880883522422293',55)

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

More information about the SciPy-user mailing list