Drop ctx._mpq
This commit is contained in:
@@ -21,8 +21,6 @@ class FPContext(StandardBaseContext):
|
||||
|
||||
ctx._init_aliases()
|
||||
|
||||
_mpq = lambda cls, x, y: float(x)/y
|
||||
|
||||
NoConvergence = libmp.NoConvergence
|
||||
|
||||
def _get_prec(ctx): return 53
|
||||
|
||||
@@ -395,11 +395,6 @@ class MPIntervalContext(StandardBaseContext):
|
||||
a._mpci_ = v
|
||||
return a
|
||||
|
||||
def _mpq(ctx, p, q):
|
||||
a = libmp.from_rational(p, q, ctx.prec, round_floor)
|
||||
b = libmp.from_rational(p, q, ctx.prec, round_ceiling)
|
||||
return ctx.make_mpf((a, b))
|
||||
|
||||
def convert(ctx, x):
|
||||
if isinstance(x, (ctx.mpf, ctx.mpc)):
|
||||
return x
|
||||
|
||||
@@ -41,7 +41,6 @@ class MPContext(BaseMPContext, StandardBaseContext):
|
||||
ctx.trap_complex = False
|
||||
ctx.pretty = False
|
||||
ctx.types = [ctx.mpf, ctx.mpc, ctx.constant]
|
||||
ctx._mpq = MPQ
|
||||
ctx.default()
|
||||
StandardBaseContext.__init__(ctx)
|
||||
|
||||
|
||||
@@ -986,7 +986,7 @@ class PythonMPContext:
|
||||
if p is not None:
|
||||
if not p % q:
|
||||
return p // q, 'Z'
|
||||
return ctx._mpq(p,q), 'Q'
|
||||
return MPQ(p,q), 'Q'
|
||||
x = ctx.convert(x)
|
||||
if hasattr(x, "_mpc_"):
|
||||
v, im = x._mpc_
|
||||
@@ -1004,7 +1004,7 @@ class PythonMPContext:
|
||||
if exp >= 0:
|
||||
return int(man) << exp, 'Z'
|
||||
p, q = int(man), (1<<(-exp))
|
||||
return ctx._mpq(p,q), 'Q'
|
||||
return MPQ(p,q), 'Q'
|
||||
x = ctx.make_mpf(v)
|
||||
return x, 'R'
|
||||
if not exp:
|
||||
|
||||
@@ -19,23 +19,22 @@ class SpecialFunctions:
|
||||
f, wrap = cls.defined_functions[name]
|
||||
cls._wrap_specfun(name, f, wrap)
|
||||
|
||||
self._mpq_1 = self._mpq(1,1)
|
||||
self._mpq_0 = self._mpq(0,1)
|
||||
self._mpq_1_2 = self._mpq(1,2)
|
||||
self._mpq_3_2 = self._mpq(3,2)
|
||||
self._mpq_1_4 = self._mpq(1,4)
|
||||
self._mpq_1_16 = self._mpq(1,16)
|
||||
self._mpq_3_16 = self._mpq(3,16)
|
||||
self._mpq_5_2 = self._mpq(5,2)
|
||||
self._mpq_3_4 = self._mpq(3,4)
|
||||
self._mpq_7_4 = self._mpq(7,4)
|
||||
self._mpq_5_4 = self._mpq(5,4)
|
||||
self._mpq_1_3 = self._mpq(1,3)
|
||||
self._mpq_2_3 = self._mpq(2,3)
|
||||
self._mpq_4_3 = self._mpq(4,3)
|
||||
self._mpq_1_6 = self._mpq(1,6)
|
||||
self._mpq_5_6 = self._mpq(5,6)
|
||||
self._mpq_5_3 = self._mpq(5,3)
|
||||
from ..libmp.backend import MPQ
|
||||
|
||||
self._mpq_1 = MPQ(1,1)
|
||||
self._mpq_1_2 = MPQ(1,2)
|
||||
self._mpq_3_2 = MPQ(3,2)
|
||||
self._mpq_1_4 = MPQ(1,4)
|
||||
self._mpq_1_16 = MPQ(1,16)
|
||||
self._mpq_3_16 = MPQ(3,16)
|
||||
self._mpq_5_2 = MPQ(5,2)
|
||||
self._mpq_3_4 = MPQ(3,4)
|
||||
self._mpq_1_3 = MPQ(1,3)
|
||||
self._mpq_2_3 = MPQ(2,3)
|
||||
self._mpq_4_3 = MPQ(4,3)
|
||||
self._mpq_1_6 = MPQ(1,6)
|
||||
self._mpq_5_6 = MPQ(5,6)
|
||||
self._mpq_5_3 = MPQ(5,3)
|
||||
|
||||
self._misc_const_cache = {}
|
||||
|
||||
|
||||
@@ -179,12 +179,12 @@ def test_hash():
|
||||
# Check that overflow doesn't assign equal hashes to large numbers
|
||||
assert hash(mpf('1e1000')) != hash('1e10000')
|
||||
assert hash(mpc(100,'1e1000')) != hash(mpc(200,'1e1000'))
|
||||
assert hash(mp._mpq(1,3))
|
||||
assert hash(mp._mpq(0,1)) == 0
|
||||
assert hash(mp._mpq(-1,1)) == hash(-1)
|
||||
assert hash(mp._mpq(1,1)) == hash(1)
|
||||
assert hash(mp._mpq(5,1)) == hash(5)
|
||||
assert hash(mp._mpq(1,2)) == hash(0.5)
|
||||
assert hash(MPQ(1,3))
|
||||
assert hash(MPQ(0,1)) == 0
|
||||
assert hash(MPQ(-1,1)) == hash(-1)
|
||||
assert hash(MPQ(1,1)) == hash(1)
|
||||
assert hash(MPQ(5,1)) == hash(5)
|
||||
assert hash(MPQ(1,2)) == hash(0.5)
|
||||
assert hash(mpf(1)*2**2000) == hash(2**2000)
|
||||
assert hash(mpf(1)/2**2000) == hash(MPQ(1,2**2000))
|
||||
|
||||
@@ -465,11 +465,11 @@ def test_isnan_etc():
|
||||
assert mp.isnpint(-1) is True
|
||||
assert mp.isnpint(-1.1) is False
|
||||
assert mp.isnpint(-1.0) is True
|
||||
assert mp.isnpint(mp._mpq(1, 2)) is False
|
||||
assert mp.isnpint(mp._mpq(-1, 2)) is False
|
||||
assert mp.isnpint(mp._mpq(-3, 1)) is True
|
||||
assert mp.isnpint(mp._mpq(0, 1)) is True
|
||||
assert mp.isnpint(mp._mpq(1, 1)) is False
|
||||
assert mp.isnpint(MPQ(1, 2)) is False
|
||||
assert mp.isnpint(MPQ(-1, 2)) is False
|
||||
assert mp.isnpint(MPQ(-3, 1)) is True
|
||||
assert mp.isnpint(MPQ(0, 1)) is True
|
||||
assert mp.isnpint(MPQ(1, 1)) is False
|
||||
assert mp.isnpint(0 + 0j) is True
|
||||
assert mp.isnpint(-1 + 0j) is True
|
||||
assert mp.isnpint(-1.1 + 0j) is False
|
||||
|
||||
Reference in New Issue
Block a user