Example #1
0
 def from_sympy(self, a):
     """Convert SymPy's Integer to `dtype`. """
     if a.is_Integer:
         return GMPYIntegerType(a.p)
     elif a.is_Float and int(a) == a:
         return GMPYIntegerType(int(a))
     else:
         raise CoercionFailed("expected an integer, got %s" % a)
Example #2
0
    def from_RR_mpmath(K1, a, K0):
        """Convert mpmath's `mpf` to GMPY's `mpz`. """
        p, q = K0.as_integer_ratio(a)

        if q == 1:
            return GMPYIntegerType(p)
Example #3
0
    def from_RR_sympy(K1, a, K0):
        """Convert SymPy's `Float` to GMPY's `mpz`. """
        p, q = K0.as_integer_ratio(a)

        if q == 1:
            return GMPYIntegerType(p)
Example #4
0
 def from_QQ_sympy(K1, a, K0):
     """Convert SymPy's `Rational` to GMPY's `mpz`. """
     if a.q == 1:
         return GMPYIntegerType(a.p)
Example #5
0
 def from_ZZ_sympy(K1, a, K0):
     """Convert SymPy's `Integer` to GMPY's `mpz`. """
     return GMPYIntegerType(a.p)
Example #6
0
 def from_FF_sympy(K1, a, K0):
     """Convert `ModularInteger(Integer)` to GMPY's `mpz`. """
     return GMPYIntegerType(a.to_int().p)
Example #7
0
 def from_QQ_python(K1, a, K0):
     """Convert Python's `Fraction` to GMPY's `mpz`. """
     if a.denominator == 1:
         return GMPYIntegerType(a.numerator)
Example #8
0
 def from_ZZ_python(K1, a, K0):
     """Convert Python's `int` to GMPY's `mpz`. """
     return GMPYIntegerType(a)
Example #9
0
 def from_FF_python(K1, a, K0):
     """Convert `ModularInteger(int)` to GMPY's `mpz`. """
     return GMPYIntegerType(a.to_int())