Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix converting doubles #399

Merged
merged 3 commits into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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