Multiple-precision Complex
mpc Type
- class gmpy2.mpc(c=0, /, precision=0)
- class gmpy2.mpc(c=0, /, precision, context)
- class gmpy2.mpc(real, /, imag=0, precision=0)
- class gmpy2.mpc(real, /, imag, precision, context)
- class gmpy2.mpc(s, /, precision=0, base=10)
- class gmpy2.mpc(s, /, precision, base, context)
Return a complex floating-point number constructed from a numeric value c or from a pair of two non-complex numbers real and imag or from a string s made of digits in the given base.
A string can be possibly with real-part and/or imaginary-part (that have ‘j’ as a suffix), separated by ‘+’ and parsed the same as the
mpfr
constructor does (but the base must be up to 36).The precision can be specified by either a single number that is used for both the real and imaginary components, or as a pair of different precisions for the real and imaginary components. For every component, the meaning of its precision value is the same as in the
mpfr
type constructor.- __format__(fmt) str
Return a Python string by formatting ‘x’ using the format string ‘fmt’. A valid format string consists of:
optional alignment code:
‘<’ -> left shifted in field ‘>’ -> right shifted in field ‘^’ -> centered in field
optional leading sign code
‘+’ -> always display leading sign ‘-’ -> only display minus for negative values ‘ ‘ -> minus for negative values, space for positive values
optional width.real_precision.imag_precision
optional rounding mode:
‘U’ -> round toward plus infinity ‘D’ -> round toward minus infinity ‘Z’ -> round toward zero ‘N’ -> round to nearest
optional output style:
‘P’ -> Python style, 1+2j, (default) ‘M’ -> MPC style, (1 2)
optional conversion code:
‘a’,’A’ -> hex format ‘b’ -> binary format ‘e’,’E’ -> scientific format ‘f’,’F’ -> fixed point format ‘g’,’G’ -> fixed or scientific format
The default format is ‘f’.
- digits(base=10, prec=0, /) tuple[tuple[str, int, int], tuple[str, int, int]]
Returns up to ‘prec’ digits in the given base. If ‘prec’ is 0, as many digits that are available given c’s precision are returned. ‘base’ must be between 2 and 62. The result consists of 2 three-element tuples that contain the mantissa, exponent, and number of bits of precision of the real and imaginary components.
- is_finite() bool
Return
True
if x is an actual number (i.e. non NaN or Infinity). If x is anmpc
, returnTrue
if both x.real and x.imag are finite.
- is_infinite() bool
Return
True
if x is +Infinity or -Infinity. If x is anmpc
, returnTrue
if either x.real or x.imag is infinite. Otherwise returnFalse
.
- is_zero() bool
Return
True
if x is equal to 0. If x is anmpc
, returnTrue
if both x.real and x.imag are equal to 0.
- imag
imaginary component
- precision
precision in bits
- rc
return code
- real
real component
mpc Functions
- gmpy2.is_zero(x, /) bool
Return
True
if x is equal to 0. If x is anmpc
, returnTrue
if both x.real and x.imag are equal to 0.
- gmpy2.mpc_random(random_state, /) mpc
Return uniformly distributed number in the unit square [0,1]x[0,1].
- gmpy2.norm(x, /) mpfr
Return the norm of a complex x. The norm(x) is defined as x.real**2 + x.imag**2. abs(x) is the square root of norm(x).
- gmpy2.polar(x, /) tuple[mpfr, mpfr]
Return the polar coordinate form of a complex x that is in rectangular form.
- gmpy2.rect(r, phi, /) mpc
Return the rectangular coordinate form of a complex number that is given in polar form.