manpagez: man pages & more
info mpc
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.1 Initialization Functions

An mpc_t object must be initialized before storing the first value in it. The functions mpc_init2 and mpc_init3 are used for that purpose.

Function: void mpc_init2 (mpc_t z, mpfr_prec_t prec)

Initialize z to precision prec bits and set its real and imaginary parts to NaN. Normally, a variable should be initialized once only or at least be cleared, using mpc_clear, between initializations.

Function: void mpc_init3 (mpc_t z, mpfr_prec_t prec_r, mpfr_prec_t prec_i)

Initialize 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.

Function: 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 initialize 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.

Function: 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.

Function: mpfr_prec_t mpc_get_prec (mpc_t x)

If the real and imaginary part of x have the same precision, it is returned, otherwise, 0 is returned.

Function: void mpc_get_prec2 (mpfr_prec_t* pr, mpfr_prec_t* pi, mpc_t x)

Returns the precision of the real part of x via pr and of its imaginary part via pi.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on November 27, 2011 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.