Exemplo n.º 1
0
 def __rmod__(self, other):
     if not isinstance(other, (int, long)):
         return NotImplemented
     if self == 0:
         raise ZeroDivisionError("mpz modulo by zero")
     r = _new_mpz()
     oth = _new_mpz()
     _pylong_to_mpz(other, oth)
     gmp.mpz_fdiv_r(r, oth, self._mpz)
     _del_mpz(oth)
     return mpz._from_c_mpz(r)
Exemplo n.º 2
0
 def __rmod__(self, other):
     if not isinstance(other, (int, long)):
         return NotImplemented
     if self == 0:
         raise ZeroDivisionError('mpz modulo by zero')
     r = _new_mpz()
     oth = _new_mpz()
     _pylong_to_mpz(other, oth)
     gmp.mpz_fdiv_r(r, oth, self._mpz)
     _del_mpz(oth)
     return mpz._from_c_mpz(r)
Exemplo n.º 3
0
 def __mod__(self, other):
     if isinstance(other, (int, long)):
         if other == 0:
             raise ZeroDivisionError("mpz modulo by zero")
         r = _new_mpz()
         if 0 <= other <= MAX_UI:
             gmp.mpz_fdiv_r_ui(r, self._mpz, other)
         else:
             oth = _new_mpz()
             _pylong_to_mpz(other, oth)
             gmp.mpz_fdiv_r(r, self._mpz, oth)
             _del_mpz(oth)
         return mpz._from_c_mpz(r)
     elif isinstance(other, mpz):
         if other == 0:
             raise ZeroDivisionError("mpz modulo by zero")
         r = _new_mpz()
         gmp.mpz_fdiv_r(r, self._mpz, other._mpz)
         return mpz._from_c_mpz(r)
     else:
         return NotImplemented
Exemplo n.º 4
0
 def __mod__(self, other):
     if isinstance(other, (int, long)):
         if other == 0:
             raise ZeroDivisionError('mpz modulo by zero')
         r = _new_mpz()
         if 0 <= other <= MAX_UI:
             gmp.mpz_fdiv_r_ui(r, self._mpz, other)
         else:
             oth = _new_mpz()
             _pylong_to_mpz(other, oth)
             gmp.mpz_fdiv_r(r, self._mpz, oth)
             _del_mpz(oth)
         return mpz._from_c_mpz(r)
     elif isinstance(other, mpz):
         if other == 0:
             raise ZeroDivisionError('mpz modulo by zero')
         r = _new_mpz()
         gmp.mpz_fdiv_r(r, self._mpz, other._mpz)
         return mpz._from_c_mpz(r)
     else:
         return NotImplemented