def from_sympy(self, a): """Convert SymPy's Integer to `dtype`. """ if a.is_Integer: return PythonIntegerType(a.p) elif a.is_Real and int(a) == a: return PythonIntegerType(int(a)) else: raise CoercionFailed("expected an integer, got %s" % 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 PythonIntegerType(p)
def from_RR_sympy(K1, a, K0): """Convert SymPy's `Real` to Python's `int`. """ p, q = K0.as_integer_ratio(a) if q == 1: return PythonIntegerType(p)
def from_QQ_gmpy(K1, a, K0): """Convert GMPY's `mpq` to Python's `int`. """ if a.denom() == 1: return PythonIntegerType(a.numer())
def from_ZZ_gmpy(K1, a, K0): """Convert GMPY's `mpz` to Python's `int`. """ return PythonIntegerType(a)
def from_FF_gmpy(K1, a, K0): """Convert `ModularInteger(mpz)` to Python's `int`. """ return PythonIntegerType(a.to_int())
def from_QQ_gmpy(K1, a, K0): """Convert a GMPY `mpq` object to `dtype`. """ return PythonRationalType(PythonIntegerType(a.numer()), PythonIntegerType(a.denom()))
def from_ZZ_gmpy(K1, a, K0): """Convert a GMPY `mpz` object to `dtype`. """ return PythonRationalType(PythonIntegerType(a))