Esempio n. 1
0
 def __truediv__(self, other):
     res = _new_mpc()  # TODO use context precision
     if isinstance(other, mpc):
         gmp.mpc_div(res, self._mpc, other._mpc, gmp.MPC_RNDNN)
     elif isinstance(other, mpfr):
         gmp.mpc_div_fr(res, self._mpc, other._mpfr, gmp.MPC_RNDNN)
     elif isinstance(other, mpq):
         gmp.mpc_set_q(res, other._mpq, gmp.MPC_RNDNN)
         gmp.mpc_div(res, self._mpc, res, gmp.MPC_RNDNN)
     elif isinstance(other, mpz):
         gmp.mpfr_div_z(gmp.mpc_realref(res), gmp.mpc_realref(self._mpc), other._mpz, gmp.MPFR_RNDN)
         gmp.mpfr_div_z(gmp.mpc_imagref(res), gmp.mpc_imagref(self._mpc), other._mpz, gmp.MPFR_RNDN)
     elif isinstance(other, complex):
         gmp.mpc_set_d_d(res, other.real, other.imag, gmp.MPC_RNDNN)
         gmp.mpc_div(res, self._mpc, res, gmp.MPC_RNDNN)
     elif isinstance(other, float):
         gmp.mpfr_div_d(gmp.mpc_realref(res), gmp.mpc_realref(self._mpc), other, gmp.MPFR_RNDN)
         gmp.mpfr_div_d(gmp.mpc_imagref(res), gmp.mpc_imagref(self._mpc), other, gmp.MPFR_RNDN)
     elif isinstance(other, (int, long)):
         if 0 <= other <= MAX_UI:
             gmp.mpc_div_ui(res, self._mpc, other, gmp.MPC_RNDNN)
         elif -sys.maxsize - 1 <= other <= sys.maxsize:
             gmp.mpfr_div_si(gmp.mpc_realref(res), gmp.mpc_realref(self._mpc), other, gmp.MPFR_RNDN)
             gmp.mpfr_div_si(gmp.mpc_imagref(res), gmp.mpc_imagref(self._mpc), other, gmp.MPFR_RNDN)
         else:
             tmp_mpz = _new_mpz()
             _pyint_to_mpz(other, tmp_mpz)
             gmp.mpfr_div_z(gmp.mpc_realref(res), gmp.mpc_realref(self._mpc), tmp_mpz, gmp.MPFR_RNDN)
             gmp.mpfr_div_z(gmp.mpc_imagref(res), gmp.mpc_imagref(self._mpc), tmp_mpz, gmp.MPFR_RNDN)
             _del_mpz(tmp_mpz)
     else:
         return NotImplemented
     return mpc._from_c_mpc(res)
Esempio n. 2
0
 def __truediv__(self, other):
     res = _new_mpc()  # TODO use context precision
     if isinstance(other, mpc):
         gmp.mpc_div(res, self._mpc, other._mpc, gmp.MPC_RNDNN)
     elif isinstance(other, mpfr):
         gmp.mpc_div_fr(res, self._mpc, other._mpfr, gmp.MPC_RNDNN)
     elif isinstance(other, mpq):
         gmp.mpc_set_q(res, other._mpq, gmp.MPC_RNDNN)
         gmp.mpc_div(res, self._mpc, res, gmp.MPC_RNDNN)
     elif isinstance(other, mpz):
         gmp.mpfr_div_z(gmp.mpc_realref(res), gmp.mpc_realref(self._mpc),
                        other._mpz, gmp.MPFR_RNDN)
         gmp.mpfr_div_z(gmp.mpc_imagref(res), gmp.mpc_imagref(self._mpc),
                        other._mpz, gmp.MPFR_RNDN)
     elif isinstance(other, complex):
         gmp.mpc_set_d_d(res, other.real, other.imag, gmp.MPC_RNDNN)
         gmp.mpc_div(res, self._mpc, res, gmp.MPC_RNDNN)
     elif isinstance(other, float):
         gmp.mpfr_div_d(gmp.mpc_realref(res), gmp.mpc_realref(self._mpc),
                        other, gmp.MPFR_RNDN)
         gmp.mpfr_div_d(gmp.mpc_imagref(res), gmp.mpc_imagref(self._mpc),
                        other, gmp.MPFR_RNDN)
     elif isinstance(other, (int, long)):
         if 0 <= other <= MAX_UI:
             gmp.mpc_div_ui(res, self._mpc, other, gmp.MPC_RNDNN)
         elif -sys.maxsize - 1 <= other <= sys.maxsize:
             gmp.mpfr_div_si(gmp.mpc_realref(res),
                             gmp.mpc_realref(self._mpc), other,
                             gmp.MPFR_RNDN)
             gmp.mpfr_div_si(gmp.mpc_imagref(res),
                             gmp.mpc_imagref(self._mpc), other,
                             gmp.MPFR_RNDN)
         else:
             tmp_mpz = _new_mpz()
             _pyint_to_mpz(other, tmp_mpz)
             gmp.mpfr_div_z(gmp.mpc_realref(res),
                            gmp.mpc_realref(self._mpc), tmp_mpz,
                            gmp.MPFR_RNDN)
             gmp.mpfr_div_z(gmp.mpc_imagref(res),
                            gmp.mpc_imagref(self._mpc), tmp_mpz,
                            gmp.MPFR_RNDN)
             _del_mpz(tmp_mpz)
     else:
         return NotImplemented
     return mpc._from_c_mpc(res)
Esempio n. 3
0
 def __truediv__(self, other):
     res = _new_mpfr()
     if isinstance(other, mpfr):
         gmp.mpfr_div(res, self._mpfr, other._mpfr, gmp.MPFR_RNDN)
     elif isinstance(other, mpq):
         gmp.mpfr_div_q(res, self._mpfr, other._mpq, gmp.MPFR_RNDN)
     elif isinstance(other, mpz):
         gmp.mpfr_div_z(res, self._mpfr, other._mpz, gmp.MPFR_RNDN)
     elif isinstance(other, float):
         gmp.mpfr_div_d(res, self._mpfr, other, gmp.MPFR_RNDN)
     elif isinstance(other, (int, long)):
         if -sys.maxsize - 1 <= other <= sys.maxsize:
             gmp.mpfr_div_si(res, self._mpfr, other, gmp.MPFR_RNDN)
         elif 0 <= other <= MAX_UI:
             gmp.mpfr_div_ui(res, self._mpfr, other, gmp.MPFR_RNDN)
         else:
             tmp_mpz = _new_mpz()
             _pylong_to_mpz(other, tmp_mpz)
             gmp.mpfr_div_z(res, self._mpfr, tmp_mpz, gmp.MPFR_RNDN)
             _del_mpz(tmp_mpz)
     else:
         return NotImplemented
     return mpfr._from_c_mpfr(res)