def from_sympy(self, a): """Convert SymPy's Integer to ``dtype``. """ if a.is_Integer: return PythonInteger(a.p) elif a.is_Float and int(a) == a: return PythonInteger(int(a)) else: raise CoercionFailed("expected an integer, got %s" % a)
def from_sympy(self, a): """Convert SymPy's Integer to ``dtype``. """ if a.is_Integer: return PythonInteger(a.p) elif a.is_Float and int(a) == a: return PythonInteger(int(a)) else: from sympy.core.numbers import Infinitesimal, NegativeInfinitesimal if a.has(Infinitesimal, NegativeInfinitesimal): return a raise CoercionFailed("expected an integer, got %s" % a)
def from_RealField(K1, a, K0): """Convert mpmath's ``mpf`` to Python's ``int``. """ p, q = K0.to_rational(a) if q == 1: return PythonInteger(p)
def from_QQ_gmpy(K1, a, K0): """Convert GMPY's ``mpq`` to Python's ``int``. """ if a.denom() == 1: return PythonInteger(a.numer())
def from_ZZ_gmpy(K1, a, K0): """Convert GMPY's ``mpz`` to Python's ``int``. """ return PythonInteger(a)
def from_FF_gmpy(K1, a, K0): """Convert ``ModularInteger(mpz)`` to Python's ``int``. """ return PythonInteger(a.to_int())
def from_QQ_gmpy(K1, a, K0): """Convert a GMPY `mpq` object to `dtype`. """ return PythonRational(PythonInteger(a.numer()), PythonInteger(a.denom()))
def from_ZZ_gmpy(K1, a, K0): """Convert a GMPY `mpz` object to `dtype`. """ return PythonRational(PythonInteger(a))
def from_RR_mpmath(K1, a, K0): """Convert mpmath's ``mpf`` to Python's ``int``. """ p, q = K0.as_integer_ratio(a) if q == 1: return PythonInteger(p)