Normalize mpf in mp.npconvert() and lower precision in tests
On most systems np.float128 aren't IEEE 754 quadruples. Closes #836
This commit is contained in:
@@ -704,7 +704,7 @@ class PythonMPContext:
|
||||
import numpy as np
|
||||
if isinstance(x, np.ndarray) and x.ndim == 0: x = x.item()
|
||||
if isinstance(x, (np.integer, int)): return ctx.make_mpf(from_int(int(x)))
|
||||
if isinstance(x, (np.floating, float)): return ctx.make_mpf(from_npfloat(x))
|
||||
if isinstance(x, (np.floating, float)): return ctx.mpf(from_npfloat(x))
|
||||
if isinstance(x, (np.complexfloating, complex)):
|
||||
return ctx.make_mpc((from_npfloat(x.real), from_npfloat(x.imag)))
|
||||
raise TypeError("cannot create mpf from " + repr(x))
|
||||
|
||||
@@ -263,9 +263,9 @@ def test_compatibility():
|
||||
assert mpf(np.float64('inf')) == inf
|
||||
assert isnan(mp.npconvert(np.float64('nan')))
|
||||
if hasattr(np, "float128"):
|
||||
mp.prec = 113
|
||||
mp.prec = 64
|
||||
assert (mp.npconvert(np.float128('0.841470984807896506652502321630298954')) ==
|
||||
mpf('0.841470984807896506664590813295845351'))
|
||||
mpf('0.841470984807896506653'))
|
||||
mp.prec = 53
|
||||
# issues 382 and 539
|
||||
assert mp.sqrt(np.int64(1)) == mpf('1.0')
|
||||
|
||||
Reference in New Issue
Block a user