(gmp.info.gz) Initializing Floats
Info Catalog
(gmp.info.gz) Floating-point Functions
(gmp.info.gz) Floating-point Functions
(gmp.info.gz) Assigning Floats
Initialization Functions
========================
- Function: void mpf_set_default_prec (unsigned long int PREC)
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.
- Function: unsigned long int mpf_get_default_prec (void)
Return the 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.
- Function: void mpf_init (mpf_t X)
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'.
- Function: void mpf_init2 (mpf_t X, unsigned long int PREC)
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.
- Function: void mpf_clear (mpf_t X)
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.
- Function: unsigned long int mpf_get_prec (mpf_t OP)
Return the current precision of OP, in bits.
- Function: void mpf_set_prec (mpf_t ROP, unsigned long int PREC)
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 `realloc', and so should not be
used in a tight loop.
- Function: void mpf_set_prec_raw (mpf_t ROP, unsigned long int PREC)
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
`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.
Info Catalog
(gmp.info.gz) Floating-point Functions
(gmp.info.gz) Floating-point Functions
(gmp.info.gz) Assigning Floats
automatically generated byinfo2html