コード例 #1
0
 def from_sympy(self, a):
     """Convert SymPy's Integer to `dtype`. """
     if a.is_Rational:
         return GMPYRational(a.p, a.q)
     elif a.is_Float:
         from sympy.polys.domains import RR
         return GMPYRational(*map(int, RR.to_rational(a)))
     else:
         raise CoercionFailed("expected `Rational` object, got %s" % a)
コード例 #2
0
 def factorial(self, a):
     """Returns factorial of `a`. """
     return GMPYRational(gmpy_factorial(int(a)))
コード例 #3
0
 def div(self, a, b):
     """Division of `a` and `b`, implies `__div__`. """
     return GMPYRational(gmpy_qdiv(a, b)), self.zero
コード例 #4
0
 def quo(self, a, b):
     """Quotient of `a` and `b`, implies `__div__`. """
     return GMPYRational(gmpy_qdiv(GMPYRational(a), GMPYRational(b)))
コード例 #5
0
 def exquo(self, a, b):
     """Exact quotient of `a` and `b`, implies `__div__`.  """
     return GMPYRational(gmpy_qdiv(a, b))
コード例 #6
0
 def from_RealField(K1, a, K0):
     """Convert a mpmath `mpf` object to `dtype`. """
     return GMPYRational(*K0.to_rational(a))
コード例 #7
0
 def from_ZZ_gmpy(K1, a, K0):
     """Convert a GMPY `mpz` object to `dtype`. """
     return GMPYRational(a)
コード例 #8
0
 def from_QQ_python(K1, a, K0):
     """Convert a Python `Fraction` object to `dtype`. """
     return GMPYRational(a.numerator, a.denominator)
コード例 #9
0
 def from_ZZ_python(K1, a, K0):
     """Convert a Python `int` object to `dtype`. """
     return GMPYRational(a)
コード例 #10
0
 def div(self, a, b):
     """Division of ``a`` and ``b``, implies ``__truediv__``. """
     return GMPYRational(a) / GMPYRational(b), self.zero
コード例 #11
0
 def quo(self, a, b):
     """Quotient of ``a`` and ``b``, implies ``__truediv__``. """
     return GMPYRational(a) / GMPYRational(b)
コード例 #12
0
 def from_RealField(K1, a, K0):
     """Convert a mpmath ``mpf`` object to ``dtype``. """
     return GMPYRational(*map(int, K0.to_rational(a)))
コード例 #13
0
 def from_GaussianRationalField(K1, a, K0):
     """Convert a ``GaussianElement`` object to ``dtype``. """
     if a.y == 0:
         return GMPYRational(a.x)
コード例 #14
0
 def exquo(self, a, b):
     """Exact quotient of `a` and `b`, implies `__truediv__`.  """
     return GMPYRational(a) / GMPYRational(b)
コード例 #15
0
ファイル: gmpyrationalfield.py プロジェクト: vchekan/sympy
 def from_RR_mpmath(K1, a, K0):
     """Convert a mpmath `mpf` object to `dtype`. """
     return GMPYRational(*K0.as_integer_ratio(a))