[SciPy-user] Can SciPy compute ln(640320**3 + 744)/163**.5 to 30 places?
Dick Moores
rdm at rcblue.com
Sun Jan 21 22:07:34 EST 2007
At 12:03 PM 1/15/2007, you 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)
I hadn't checked this until now, but I used the Python interactive prompt:
>>>from __future__ import division
>>>(5/23)**(2/7)
0.64660732406541122
And double checked it with the Windows calculator:
0.64660732406541123462639015242381
Why the discrepancy?
Thanks,
Dick Moores
More information about the SciPy-User
mailing list