Go forward to Assigning Integers.
Go up to Integer Functions.
Initialization and Assignment Functions
=======================================
The functions for integer arithmetic assume that all integer objects
are initialized. You do that by calling the function `mpz_init'.
- Function: void mpz_init (mpz_t INTEGER)
Initialize INTEGER with limb space and set the initial numeric
value to 0. Each variable should normally only be initialized
once, or at least cleared out (using `mpz_clear') between each
initialization.
Here is an example of using `mpz_init':
{
mpz_t integ;
mpz_init (integ);
...
mpz_add (integ, ...);
...
mpz_sub (integ, ...);
/* Unless the program is about to exit, do ... */
mpz_clear (integ);
}
As you can see, you can store new values any number of times, once an
object is initialized.
- Function: void mpz_clear (mpz_t INTEGER)
Free the limb space occupied by INTEGER. Make sure to call this
function for all `mpz_t' variables when you are done with them.
- Function: void * _mpz_realloc (mpz_t INTEGER, mp_size_t NEW_ALLOC)
Change the limb space allocation to NEW_ALLOC limbs. This
function is not normally called from user code, but it can be used
to give memory back to the heap, or to increase the space of a
variable to avoid repeated automatic re-allocation.
- Function: void mpz_array_init (mpz_t INTEGER_ARRAY[], size_t
ARRAY_SIZE, mp_size_t FIXED_NUM_BITS)
Allocate *fixed* limb space for all ARRAY_SIZE integers in
INTEGER_ARRAY. The fixed allocation for each integer in the array
is enough to store FIXED_NUM_BITS. If the fixed space will be
insufficient for storing the result of a subsequent calculation,
the result is unpredictable.
This function is useful for decreasing the working set for some
algorithms that use large integer arrays.
There is no way to de-allocate the storage allocated by this
function. Don't call `mpz_clear'!