Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
 def from_QQ_gmpy(K1, a, K0):
     """Convert GMPY's `mpq` to Python's `int`. """
     if a.denom() == 1:
         return PythonIntegerType(a.numer())
Exemplo n.º 5
0
 def from_ZZ_gmpy(K1, a, K0):
     """Convert GMPY's `mpz` to Python's `int`. """
     return PythonIntegerType(a)
Exemplo n.º 6
0
 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))