mpmath puzzle

mensanator at aol.com mensanator at aol.com
Wed Nov 14 13:41:35 EST 2007


On Nov 13, 11:55 pm, Dick Moores <r... at rcblue.com> wrote:
> For 1234 ** 10.9, why the wrong result from mpmath.power()?
>
> ========================================
> #!/usr/bin/env python
> #coding=utf-8
> from mpmath import *
>
> mpf.dps = 32
>
> x = mpf(1234)
> y = mpf(10.9)
>
> print power(x,y)
> print "4.9583278648155041477415234438717e+33" # from Windows calculator
>
> """
> output:
> 4.9583278648155166864966558721921e+33
> 4.9583278648155041477415234438717e+33
> """
> ========================================
> (Code is also at <http://python.pastebin.com/m72a277b8>)
>
> Thanks,
>
> Dick Moores

Check this out, better than Windows or mpmath:

>>> import gmpy
>>> a = 1234
>>> b = gmpy.f2q(10.9)
>>> print b
109/10
>>> c = a**b.numer()
>>> d = gmpy.root(c,b.denom())
>>> d
(mpz(4958327864815504147741523443871702L), 0)




More information about the Python-list mailing list