Skip to content

Commit

Permalink
Merge pull request #399 from isuruf/double
Browse files Browse the repository at this point in the history
Fix converting doubles
  • Loading branch information
isuruf authored Apr 3, 2022
2 parents adee9c4 + d1f3aa9 commit 2ae4422
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def finalize_options(self):
url="https://github.com/symengine/symengine.py",
python_requires='>=3.7,<4',
zip_safe=False,
packages=['symengine'],
cmdclass = cmdclass,
classifiers=[
'License :: OSI Approved :: MIT License',
Expand Down
6 changes: 3 additions & 3 deletions symengine/lib/symengine_wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ def sympy2symengine(a, raise_error=False):
if a._prec > 53:
return RealMPFR(str(a), a._prec)
else:
return RealDouble(float(str(a)))
return RealDouble(float(a))
ELSE:
return RealDouble(float(str(a)))
return RealDouble(float(a))
elif a is sympy.I:
return I
elif a is sympy.E:
Expand Down Expand Up @@ -1902,7 +1902,7 @@ class RealDouble(Float):

def _sympy_(Basic self):
import sympy
return sympy.Float(deref(self.thisptr).__str__().decode("utf-8"))
return sympy.Float(float(self))

def _sage_(Basic self):
import sage.all as sage
Expand Down
14 changes: 12 additions & 2 deletions symengine/tests/test_sympy_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exp, gamma, have_mpfr, have_mpc, DenseMatrix, sin, cos, tan, cot,
csc, sec, asin, acos, atan, acot, acsc, asec, sinh, cosh, tanh, coth,
asinh, acosh, atanh, acoth, Add, Mul, Pow, diff, GoldenRatio,
Catalan, EulerGamma, UnevaluatedExpr)
Catalan, EulerGamma, UnevaluatedExpr, RealDouble)
from symengine.lib.symengine_wrapper import (Subs, Derivative, RealMPFR,
ComplexMPC, PyNumber, Function, LambertW, zeta, dirichlet_eta,
KroneckerDelta, LeviCivita, erf, erfc, lowergamma, uppergamma,
Expand Down Expand Up @@ -515,7 +515,7 @@ def test_zeta():
e1 = sympy.zeta(sympy.Symbol("x"), sympy.Symbol("y"))
e2 = zeta(x, y)
assert sympify(e1) == e2
assert e2._sympy_() == e1
assert e2._sympy_() == e1


@unittest.skipIf(not have_sympy, "SymPy not installed")
Expand Down Expand Up @@ -796,3 +796,13 @@ def test_construct_dense_matrix():
B = DenseMatrix(A)
assert B.shape == (2, 2)
assert list(B) == [1, 2, 3, 5]


@unittest.skipIf(not have_sympy, "SymPy not installed")
def test_conv_doubles():
f = 4.347249999999999
a = sympify(f)
assert isinstance(a, RealDouble)
assert sympify(a._sympy_()) == a
assert float(a) == f
assert float(a._sympy_()) == f

0 comments on commit 2ae4422

Please # to comment.