Convert From Mpf To Sympy Float Without Losing Precision
Is there any way to do this? For example in the code below I lose precision: >>> from sympy import * >>> from sympy.mpmath import * >>> mp.dps = 50 >&
Solution 1:
Converting to a string first seems to do the trick:
>>> from sympy import *
>>> from sympy.mpmath import *
>>> mp.dps = 50
>>> a = mpf('1.0')/mpf('3.0')
>>> a
mpf('0.33333333333333333333333333333333333333333333333333311')
>>> b = Float(a,50)
>>> b
0.33333333333333331482961625624739099293947219848633
>>> b = Float(str(a),50)
>>> b
0.33333333333333333333333333333333333333333333333333
Solution 2:
sympify(a)
does the right thing. Float(a)
ought to work too, but it seems there is a bug.
Post a Comment for "Convert From Mpf To Sympy Float Without Losing Precision"