Skip to content

Commit

Permalink
Move around mpc() methods...
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Jun 5, 2024
1 parent bfa51f7 commit b180c95
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions mpmath/ctx_mp_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ def __add__(s, t):
v = new(cls)
v._mpc_ = mpc_add(s._mpc_, t._mpc_, prec, rounding)
return v
__radd__ = __add__

def __sub__(s, t):
cls, new, (prec, rounding) = s._ctxdata
Expand All @@ -521,6 +522,12 @@ def __sub__(s, t):
v._mpc_ = mpc_sub(s._mpc_, t._mpc_, prec, rounding)
return v

def __rsub__(s, t):
t = s.mpc_convert_lhs(t)
if t is NotImplemented:
return t
return t - s

def __mul__(s, t):
cls, new, (prec, rounding) = s._ctxdata
if not hasattr(t, '_mpc_'):
Expand All @@ -540,6 +547,17 @@ def __mul__(s, t):
v._mpc_ = mpc_mul(s._mpc_, t._mpc_, prec, rounding)
return v

def __rmul__(s, t):
cls, new, (prec, rounding) = s._ctxdata
if isinstance(t, int_types):
v = new(cls)
v._mpc_ = mpc_mul_int(s._mpc_, t, prec, rounding)
return v
t = s.mpc_convert_lhs(t)
if t is NotImplemented:
return t
return t * s

def __truediv__(s, t):
cls, new, (prec, rounding) = s._ctxdata
if not hasattr(t, '_mpc_'):
Expand All @@ -554,6 +572,12 @@ def __truediv__(s, t):
v._mpc_ = mpc_div(s._mpc_, t._mpc_, prec, rounding)
return v

def __rtruediv__(s, t):
t = s.mpc_convert_lhs(t)
if t is NotImplemented:
return t
return t / s

def __pow__(s, t):
cls, new, (prec, rounding) = s._ctxdata
if isinstance(t, int_types):
Expand All @@ -570,31 +594,6 @@ def __pow__(s, t):
v._mpc_ = mpc_pow(s._mpc_, t._mpc_, prec, rounding)
return v

__radd__ = __add__

def __rsub__(s, t):
t = s.mpc_convert_lhs(t)
if t is NotImplemented:
return t
return t - s

def __rmul__(s, t):
cls, new, (prec, rounding) = s._ctxdata
if isinstance(t, int_types):
v = new(cls)
v._mpc_ = mpc_mul_int(s._mpc_, t, prec, rounding)
return v
t = s.mpc_convert_lhs(t)
if t is NotImplemented:
return t
return t * s

def __rtruediv__(s, t):
t = s.mpc_convert_lhs(t)
if t is NotImplemented:
return t
return t / s

def __rpow__(s, t):
t = s.mpc_convert_lhs(t)
if t is NotImplemented:
Expand Down

0 comments on commit b180c95

Please sign in to comment.