Skip to content

Commit 2ae4422

Browse files
authored
Merge pull request #399 from isuruf/double
Fix converting doubles
2 parents adee9c4 + d1f3aa9 commit 2ae4422

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def finalize_options(self):
226226
url="https://github.com/symengine/symengine.py",
227227
python_requires='>=3.7,<4',
228228
zip_safe=False,
229+
packages=['symengine'],
229230
cmdclass = cmdclass,
230231
classifiers=[
231232
'License :: OSI Approved :: MIT License',

symengine/lib/symengine_wrapper.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ def sympy2symengine(a, raise_error=False):
294294
if a._prec > 53:
295295
return RealMPFR(str(a), a._prec)
296296
else:
297-
return RealDouble(float(str(a)))
297+
return RealDouble(float(a))
298298
ELSE:
299-
return RealDouble(float(str(a)))
299+
return RealDouble(float(a))
300300
elif a is sympy.I:
301301
return I
302302
elif a is sympy.E:
@@ -1902,7 +1902,7 @@ class RealDouble(Float):
19021902

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

19071907
def _sage_(Basic self):
19081908
import sage.all as sage

symengine/tests/test_sympy_conv.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exp, gamma, have_mpfr, have_mpc, DenseMatrix, sin, cos, tan, cot,
44
csc, sec, asin, acos, atan, acot, acsc, asec, sinh, cosh, tanh, coth,
55
asinh, acosh, atanh, acoth, Add, Mul, Pow, diff, GoldenRatio,
6-
Catalan, EulerGamma, UnevaluatedExpr)
6+
Catalan, EulerGamma, UnevaluatedExpr, RealDouble)
77
from symengine.lib.symengine_wrapper import (Subs, Derivative, RealMPFR,
88
ComplexMPC, PyNumber, Function, LambertW, zeta, dirichlet_eta,
99
KroneckerDelta, LeviCivita, erf, erfc, lowergamma, uppergamma,
@@ -515,7 +515,7 @@ def test_zeta():
515515
e1 = sympy.zeta(sympy.Symbol("x"), sympy.Symbol("y"))
516516
e2 = zeta(x, y)
517517
assert sympify(e1) == e2
518-
assert e2._sympy_() == e1
518+
assert e2._sympy_() == e1
519519

520520

521521
@unittest.skipIf(not have_sympy, "SymPy not installed")
@@ -796,3 +796,13 @@ def test_construct_dense_matrix():
796796
B = DenseMatrix(A)
797797
assert B.shape == (2, 2)
798798
assert list(B) == [1, 2, 3, 5]
799+
800+
801+
@unittest.skipIf(not have_sympy, "SymPy not installed")
802+
def test_conv_doubles():
803+
f = 4.347249999999999
804+
a = sympify(f)
805+
assert isinstance(a, RealDouble)
806+
assert sympify(a._sympy_()) == a
807+
assert float(a) == f
808+
assert float(a._sympy_()) == f

0 commit comments

Comments
 (0)