Beispiel #1
0
 def __rdivmod__(self, other):
     if not isinstance(other, (int, long)):
         return NotImplemented
     if self == 0:
         raise ZeroDivisionError("mpz modulo by zero")
     q = _new_mpz()
     r = _new_mpz()
     oth = _new_mpz()
     _pylong_to_mpz(other, oth)
     gmp.mpz_fdiv_qr(q, r, oth, self._mpz)
     _del_mpz(oth)
     return mpz._from_c_mpz(q), mpz._from_c_mpz(r)
Beispiel #2
0
 def __rdivmod__(self, other):
     if not isinstance(other, (int, long)):
         return NotImplemented
     if self == 0:
         raise ZeroDivisionError('mpz modulo by zero')
     q = _new_mpz()
     r = _new_mpz()
     oth = _new_mpz()
     _pylong_to_mpz(other, oth)
     gmp.mpz_fdiv_qr(q, r, oth, self._mpz)
     _del_mpz(oth)
     return mpz._from_c_mpz(q), mpz._from_c_mpz(r)
Beispiel #3
0
 def __divmod__(self, other):
     if isinstance(other, (int, long)):
         if other == 0:
             raise ZeroDivisionError("mpz modulo by zero")
         q = _new_mpz()
         r = _new_mpz()
         if 0 <= other <= MAX_UI:
             gmp.mpz_fdiv_qr_ui(q, r, self._mpz, other)
         else:
             oth = _new_mpz()
             _pylong_to_mpz(other, oth)
             gmp.mpz_fdiv_qr(q, r, self._mpz, oth)
             _del_mpz(oth)
         return mpz._from_c_mpz(q), mpz._from_c_mpz(r)
     elif isinstance(other, mpz):
         if other == 0:
             raise ZeroDivisionError("mpz modulo by zero")
         q = _new_mpz()
         r = _new_mpz()
         gmp.mpz_fdiv_qr(q, r, self._mpz, other._mpz)
         return mpz._from_c_mpz(q), mpz._from_c_mpz(r)
     else:
         return NotImplemented
Beispiel #4
0
 def __divmod__(self, other):
     if isinstance(other, (int, long)):
         if other == 0:
             raise ZeroDivisionError('mpz modulo by zero')
         q = _new_mpz()
         r = _new_mpz()
         if 0 <= other <= MAX_UI:
             gmp.mpz_fdiv_qr_ui(q, r, self._mpz, other)
         else:
             oth = _new_mpz()
             _pylong_to_mpz(other, oth)
             gmp.mpz_fdiv_qr(q, r, self._mpz, oth)
             _del_mpz(oth)
         return mpz._from_c_mpz(q), mpz._from_c_mpz(r)
     elif isinstance(other, mpz):
         if other == 0:
             raise ZeroDivisionError('mpz modulo by zero')
         q = _new_mpz()
         r = _new_mpz()
         gmp.mpz_fdiv_qr(q, r, self._mpz, other._mpz)
         return mpz._from_c_mpz(q), mpz._from_c_mpz(r)
     else:
         return NotImplemented