| www.delorie.com/gnu/docs/gmp/gmp_51.html | search |
![]() Buy GNU books! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
mpf_init will use this precision, but previously
initialized variables are unaffected.
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.
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.
mpf_clear, between initializations.
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.
This function requires a call to realloc, and so should not be used in
a tight loop.
prec must be no more than the allocated precision for rop, that
being the precision when rop was initialized, or in the most recent
mpf_set_prec.
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 mpf_clear or the full mpf_set_prec, another
mpf_set_prec_raw call must be made to restore rop to its original
allocated precision. Failing to do so will have unpredictable results.
mpf_get_prec can be used before mpf_set_prec_raw to get the
original allocated precision. After mpf_set_prec_raw it reflects the
prec value set.
mpf_set_prec_raw is an efficient way to use an mpf_t variable at
different precisions during a calculation, perhaps to gradually increase
precision in an iteration, or just to use various different precisions for
different purposes during a calculation.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |