def mpc_floor(z, prec, rnd=round_fast): a, b = z return mpf_floor(a, prec, rnd), mpf_floor(b, prec, rnd)
return mpf_shift(a, n), mpf_shift(b, n) def mpc_abs((a, b), prec, rnd=round_fast): """Absolute value of a complex number, |a+bi|. Returns an mpf value.""" return mpf_hypot(a, b, prec, rnd) def mpc_arg((a, b), prec, rnd=round_fast): """Argument of a complex number. Returns an mpf value.""" return mpf_atan2(b, a, prec, rnd) def mpc_floor((a, b), prec, rnd=round_fast): return mpf_floor(a, prec, rnd), mpf_floor(b, prec, rnd) def mpc_ceil((a, b), prec, rnd=round_fast): return mpf_ceil(a, prec, rnd), mpf_ceil(b, prec, rnd) def mpc_mul((a, b), (c, d), prec, rnd=round_fast): """Complex multiplication. Returns the real and imaginary part of (a+bi)*(c+di), rounded to the specified precision. The rounding mode applies to the real and imaginary parts separately.""" asign, aman, aexp, abc = a bsign, bman, bexp, bbc = b
return mpf_neg(a, prec, rnd), mpf_neg(b, prec, rnd) def mpc_shift((a, b), n): return mpf_shift(a, n), mpf_shift(b, n) def mpc_abs((a, b), prec, rnd=round_fast): """Absolute value of a complex number, |a+bi|. Returns an mpf value.""" return mpf_hypot(a, b, prec, rnd) def mpc_arg((a, b), prec, rnd=round_fast): """Argument of a complex number. Returns an mpf value.""" return mpf_atan2(b, a, prec, rnd) def mpc_floor((a, b), prec, rnd=round_fast): return mpf_floor(a, prec, rnd), mpf_floor(b, prec, rnd) def mpc_ceil((a, b), prec, rnd=round_fast): return mpf_ceil(a, prec, rnd), mpf_ceil(b, prec, rnd) def mpc_mul((a, b), (c, d), prec, rnd=round_fast): """Complex multiplication. Returns the real and imaginary part of (a+bi)*(c+di), rounded to the specified precision. The rounding mode applies to the real and imaginary parts separately.""" asign, aman, aexp, abc = a bsign, bman, bexp, bbc = b csign, cman, cexp, cbc = c dsign, dman, dexp, dbc = d