An mpc_t object must be initialised before storing the first value in
it. The functions mpc_init2 and mpc_init3
are used for that purpose.
void mpc_init2 (mpc_t z, mpfr_prec_t prec) ¶Initialise z to precision prec bits
and set its real and imaginary parts to NaN.
Normally, a variable should be initialised once only
or at least be cleared, using mpc_clear, between initializations.
void mpc_init3 (mpc_t z, mpfr_prec_t prec_r, mpfr_prec_t prec_i) ¶Initialise z with the precision of its real part being prec_r bits and the precision of its imaginary part being prec_i bits, and set the real and imaginary parts to NaN.
void mpc_clear (mpc_t z) ¶Free the space occupied by z. Make sure to call this function for all
mpc_t variables when you are done with them.
Here is an example on how to initialise complex variables:
{
mpc_t x, y;
mpc_init2 (x, 256); /* precision exactly 256 bits */
mpc_init3 (y, 100, 50); /* 100/50 bits for the real/imaginary part */
...
mpc_clear (x);
mpc_clear (y);
}
The following function is useful for changing the precision during a calculation. A typical use would be for adjusting the precision gradually in iterative algorithms like Newton-Raphson, making the computation precision closely match the actual accurate part of the numbers.
void mpc_set_prec (mpc_t x, mpfr_prec_t prec) ¶Reset the precision of x to be exactly prec bits,
and set its real/imaginary parts to NaN.
The previous value stored in x is lost. It is equivalent to
a call to mpc_clear(x) followed by a call to
mpc_init2(x, prec), but more efficient as no allocation is done in
case the current allocated space for the mantissa of x is sufficient.
mpfr_prec_t mpc_get_prec (const mpc_t x) ¶If the real and imaginary part of x have the same precision, it is returned, otherwise, 0 is returned.
void mpc_get_prec2 (mpfr_prec_t* pr, mpfr_prec_t* pi, const mpc_t x) ¶Returns the precision of the real part of x via pr and of its imaginary part via pi.