コード例 #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)
コード例 #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)
コード例 #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)
コード例 #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())
コード例 #5
0
 def from_ZZ_gmpy(K1, a, K0):
     """Convert GMPY's `mpz` to Python's `int`. """
     return PythonIntegerType(a)
コード例 #6
0
 def from_FF_gmpy(K1, a, K0):
     """Convert `ModularInteger(mpz)` to Python's `int`. """
     return PythonIntegerType(a.to_int())
コード例 #7
0
 def from_QQ_gmpy(K1, a, K0):
     """Convert a GMPY `mpq` object to `dtype`. """
     return PythonRationalType(PythonIntegerType(a.numer()),
                               PythonIntegerType(a.denom()))
コード例 #8
0
 def from_ZZ_gmpy(K1, a, K0):
     """Convert a GMPY `mpz` object to `dtype`. """
     return PythonRationalType(PythonIntegerType(a))