Esempio n. 1
0
 def __rfloordiv__(self, other):
     if isinstance(other, (int, long)):
         if self == 0:
             raise ZeroDivisionError("mpz division by zero")
         res = _new_mpz()
         _pylong_to_mpz(other, res)
         gmp.mpz_fdiv_q(res, res, self._mpz)
         return mpz._from_c_mpz(res)
     else:
         return NotImplemented
Esempio n. 2
0
 def __rfloordiv__(self, other):
     if isinstance(other, (int, long)):
         if self == 0:
             raise ZeroDivisionError('mpz division by zero')
         res = _new_mpz()
         _pylong_to_mpz(other, res)
         gmp.mpz_fdiv_q(res, res, self._mpz)
         return mpz._from_c_mpz(res)
     else:
         return NotImplemented
Esempio n. 3
0
 def __floordiv__(self, other):
     if isinstance(other, (int, long)):
         if other == 0:
             raise ZeroDivisionError("mpz division by zero")
         res = _new_mpz()
         if 0 < other <= MAX_UI:
             gmp.mpz_fdiv_q_ui(res, self._mpz, other)
         else:
             _pylong_to_mpz(other, res)
             gmp.mpz_fdiv_q(res, self._mpz, res)
         return mpz._from_c_mpz(res)
     elif isinstance(other, mpz):
         if other == 0:
             raise ZeroDivisionError("mpz division by zero")
         res = _new_mpz()
         gmp.mpz_fdiv_q(res, self._mpz, other._mpz)
         return mpz._from_c_mpz(res)
     else:
         return NotImplemented
Esempio n. 4
0
 def __floordiv__(self, other):
     if isinstance(other, (int, long)):
         if other == 0:
             raise ZeroDivisionError('mpz division by zero')
         res = _new_mpz()
         if 0 < other <= MAX_UI:
             gmp.mpz_fdiv_q_ui(res, self._mpz, other)
         else:
             _pylong_to_mpz(other, res)
             gmp.mpz_fdiv_q(res, self._mpz, res)
         return mpz._from_c_mpz(res)
     elif isinstance(other, mpz):
         if other == 0:
             raise ZeroDivisionError('mpz division by zero')
         res = _new_mpz()
         gmp.mpz_fdiv_q(res, self._mpz, other._mpz)
         return mpz._from_c_mpz(res)
     else:
         return NotImplemented
Esempio n. 5
0
 def __floor__(self):
     res = _new_mpz()
     gmp.mpz_fdiv_q(res, gmp.mpq_numref(self._mpq), gmp.mpq_denref(self._mpq))
     return mpz._from_c_mpz(res)