Node:Initializing Floats, Next:Assigning Floats, Previous:Floating-point Functions, Up:Floating-point Functions
void mpf_set_default_prec (unsigned long int prec) | Function |
Set the default precision to be at least prec bits. All
subsequent calls to mpf_init will use this precision, but previously
initialized variables are unaffected.
|
unsigned long int mpf_get_default_prec (void) | Function |
Return the default default precision actually used. |
An mpf_t
object must be initialized before storing the first value in
it. The functions mpf_init
and mpf_init2
are used for that
purpose.
void mpf_init (mpf_t x) | Function |
Initialize x to 0. Normally, a variable should be initialized once only
or at least be cleared, using mpf_clear , between initializations. The
precision of x is undefined unless a default precision has already been
established by a call to mpf_set_default_prec .
|
void mpf_init2 (mpf_t x, unsigned long int prec) | Function |
Initialize x to 0 and set its precision to be at least
prec bits. Normally, a variable should be initialized once only or at
least be cleared, using mpf_clear , between initializations.
|
void mpf_clear (mpf_t x) | Function |
Free the space occupied by x. Make sure to call this function for all
mpf_t variables when you are done with them.
|
Here is an example on how to initialize floating-point variables:
{ mpf_t x, y; mpf_init (x); /* use default precision */ mpf_init2 (y, 256); /* precision at least 256 bits */ ... /* Unless the program is about to exit, do ... */ mpf_clear (x); mpf_clear (y); }
The following three 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.
unsigned long int mpf_get_prec (mpf_t op) | Function |
Return the current precision of op, in bits. |
void mpf_set_prec (mpf_t rop, unsigned long int prec) | Function |
Set the precision of rop to be at least prec bits. The
value in rop will be truncated to the new precision.
This function requires a call to |
void mpf_set_prec_raw (mpf_t rop, unsigned long int prec) | Function |
Set the precision of rop to be at least prec bits,
without changing the memory allocated.
prec must be no more than the allocated precision for rop, that
being the precision when rop was initialized, or in the most recent
The value in rop is unchanged, and in particular if it had a higher precision than prec it will retain that higher precision. New values written to rop will use the new prec. Before calling
|