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

Fernando Perez fperez.net at gmail.com
Mon Jan 15 10:27:42 EST 2007


On 1/14/07, Dick Moores <rdmoores at gmail.com> wrote:
> On 1/13/07, Fernando Perez <fperez.net at gmail.com> wrote:
>
> > 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)
> >
>
> I assumed you did that in Python. So I tried it with this script,
> adding a print statement:
> ===================================
> # clnumTest1-a.py
>
> import clnum as n
>
> n.set_default_precision(50)
>
> print "%.50f" % (n.log(640320**3 + 744)/n.sqrt(163))
> ======================================
> result: 3.141592653589793100000000000000
>
> So clarify, if you would, please.


In [8]: print "%.50f" % (n.log(640320**3 + 744)/n.sqrt(163))
3.14159265358979311599796346854418516159057617187500

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

In [10]: print n.log(640320**3 + 744)/n.sqrt(163)
3.1415926535897932385


There's a difference between:

a) '%Xf' formatting, which is done by Python by converting your object
into a regular float (64-bit) and then generating a string
representation for it, seen in [8]

b) the __repr__ of an mpf object, seen in [9]

c) the __str__ of an mpf object, seen in [10]

Same object (the mpf number), three different mechanisms for getting a
string form out of it, three different results (as a /string/).

Cheers,

f



More information about the SciPy-User mailing list