Beispiel #1
0
 def from_sympy(self, a):
     """Convert SymPy's Rational to `dtype`. """
     if a.is_Rational:
         return PythonRational(a.p, a.q)
     elif a.is_Float:
         from sympy.polys.domains import RR
         return PythonRational(*RR.as_integer_ratio(a))
     else:
         raise CoercionFailed("expected `Rational` object, got %s" % a)
 def from_RealField(K1, a, K0):
     """Convert a mpmath `mpf` object to `dtype`. """
     p, q = K0.to_rational(a)
     return PythonRational(int(p), int(q))
 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_ZZ_python(K1, a, K0):
     """Convert a Python `int` object to `dtype`. """
     return PythonRational(a)
Beispiel #6
0
 def from_RR_mpmath(K1, a, K0):
     """Convert a mpmath `mpf` object to `dtype`. """
     return PythonRational(*K0.as_integer_ratio(a))