Skip to content

Commit ae38322

Browse files
committed
several fixes...
1 parent a309401 commit ae38322

1 file changed

Lines changed: 31 additions & 17 deletions

File tree

mathics/builtin/constants.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,26 @@ def get_constant(self, precision, evaluation, preference=None):
111111
return
112112
# Try to determine the numeric value
113113
value = None
114-
if preference == "numpy":
115-
if hasattr(self, "numpy_name"):
116-
value = numpy_constant(self.numpy_name)
117-
if d == machine_d:
118-
return MachineReal(value)
119-
elif preference == "sympy":
120-
if hasattr(self, "sympy_name"):
121-
value = sympy_constant(self.sympy_name, d+2)
122-
elif preference == "mpmath":
114+
if preference == "mpmath" and not hasattr(self, "mpmath_name"):
115+
preference = "numpy"
116+
elif preference == "sympy" and not hasattr(self, "sympy_name"):
117+
preference = "numpy"
118+
119+
if preference == "numpy" and not hasattr(self, "numpy_name"):
123120
if hasattr(self, "sympy_name"):
124-
value = mp_constant(self.mpmath_name, d+2)
121+
preference = "sympy"
122+
elif hasattr(self, "mpmath_name"):
123+
preference = "mpmath"
124+
else:
125+
preference = ""
126+
if preference == "numpy":
127+
value = numpy_constant(self.numpy_name)
128+
if d == machine_d:
129+
return MachineReal(value)
130+
if preference == "sympy":
131+
value = sympy_constant(self.sympy_name, d+2)
132+
if preference == "mpmath":
133+
value = mp_constant(self.mpmath_name, d*2)
125134
if value:
126135
return PrecisionReal(sympy.Float(str(value), d))
127136
# If the value is not available, return none
@@ -185,7 +194,7 @@ def to_sympy(self, expr=None, **kwargs):
185194
return None
186195

187196

188-
class Catalan(MPMathConstant, NumpyConstant, SympyConstant):
197+
class Catalan(MPMathConstant, SympyConstant):
189198
"""
190199
<dl>
191200
<dt>'Catalan'
@@ -200,7 +209,7 @@ class Catalan(MPMathConstant, NumpyConstant, SympyConstant):
200209
"""
201210

202211
mpmath_name = "catalan"
203-
numpy_name = "catalan"
212+
# numpy_name = "catalan" ## This is not defined in numpy
204213
sympy_name = "Catalan"
205214

206215

@@ -275,7 +284,10 @@ def to_numpy(self, expr=None, **kwargs):
275284
def apply_N(self, precision, evaluation, options={}):
276285
"N[Degree, precision_, OptionsPattern[%(name)s]]"
277286
try:
278-
d = get_precision(precision, evaluation)
287+
if precision:
288+
d = get_precision(precision, evaluation)
289+
else:
290+
d = get_precision(Symbol("System`MachinePrecision"), evaluation)
279291
except PrecisionValueError:
280292
return
281293

@@ -343,9 +355,10 @@ class Glaisher(MPMathConstant):
343355
</dl>
344356
345357
>> N[Glaisher]
346-
= 1.28243
358+
= 1.28242712910062
347359
>> N[Glaisher, 50]
348-
= 1.2824271291006219541941391071304678916931152343750
360+
= 1.2824271291006226368753425688697917277676889273250
361+
# 1.2824271291006219541941391071304678916931152343750
349362
"""
350363

351364
mpmath_name = "glaisher"
@@ -432,9 +445,10 @@ class Khinchin(MPMathConstant):
432445
</dl>
433446
434447
>> N[Khinchin]
435-
= 2.68545
448+
= 2.68545200106531
436449
>> N[Khinchin, 50]
437-
= 2.6854520010653075701156922150403261184692382812500
450+
= 2.6854520010653064453097148354817956938203822939945
451+
# = 2.6854520010653075701156922150403261184692382812500
438452
"""
439453

440454
mpmath_name = "khinchin"

0 commit comments

Comments
 (0)