| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] | 
5.1 Initialization Functions
An mpfr_t object must be initialized before storing the first value in
it.  The functions mpfr_init and mpfr_init2 are used for that
purpose.
- Function: void mpfr_init2 (mpfr_t x, mp_prec_t prec)
- Initialize x, set its precision to be exactly prec bits and its value to NaN. (Warning: the corresponding - mpffunctions initialize to zero instead.)- Normally, a variable should be initialized once only or at least be cleared, using - mpfr_clear, between initializations. To change the precision of a variable which has already been initialized, use- mpfr_set_prec. The precision prec must be an integer between- MPFR_PREC_MINand- MPFR_PREC_MAX(otherwise the behavior is undefined).
- Function: void mpfr_clear (mpfr_t x)
- Free the space occupied by x. Make sure to call this function for all - mpfr_tvariables when you are done with them.
- Function: void mpfr_init (mpfr_t x)
- Initialize x and set its value to NaN. - Normally, a variable should be initialized once only or at least be cleared, using - mpfr_clear, between initializations. The precision of x is the default precision, which can be changed by a call to- mpfr_set_default_prec.
- Function: void mpfr_set_default_prec (mp_prec_t prec)
- Set the default precision to be exactly prec bits. The precision of a variable means the number of bits used to store its significand. All subsequent calls to - mpfr_initwill use this precision, but previously initialized variables are unaffected. This default precision is set to 53 bits initially. The precision can be any integer between- MPFR_PREC_MINand- MPFR_PREC_MAX.
Here is an example on how to initialize floating-point variables:
| {
  mpfr_t x, y;
  mpfr_init (x);                /* use default precision */
  mpfr_init2 (y, 256);          /* precision exactly 256 bits */
  …
  /* When the program is about to exit, do ... */
  mpfr_clear (x);
  mpfr_clear (y);
  mpfr_free_cache ();
}
 | 
The following functions are 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 mpfr_set_prec (mpfr_t x, mp_prec_t prec)
- Reset the precision of x to be exactly prec bits, and set its value to NaN. The previous value stored in x is lost. It is equivalent to a call to - mpfr_clear(x)followed by a call to- mpfr_init2(x, prec), but more efficient as no allocation is done in case the current allocated space for the significand of x is enough. The precision prec can be any integer between- MPFR_PREC_MINand- MPFR_PREC_MAX.- In case you want to keep the previous value stored in x, use - mpfr_prec_roundinstead.
- Function: mp_prec_t mpfr_get_prec (mpfr_t x)
- Return the precision actually used for assignments of x, i.e. the number of bits used to store its significand. 
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] | 
