[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |

## 5.16 Special Functions

The functions in this section are for various special purposes. Most applications will not need them.

- Function:
*void***mpz_array_init***(mpz_t*`integer_array`, mp_size_t`array_size`, mp_size_t`fixed_num_bits`) This is a special type of initialization.

**Fixed**space of`fixed_num_bits`is allocated to each of the`array_size`integers in`integer_array`. There is no way to free the storage allocated by this function. Don’t call`mpz_clear`

!The

`integer_array`parameter is the first`mpz_t`

in the array. For example,mpz_t arr[20000]; mpz_array_init (arr[0], 20000, 512);

This function is only intended for programs that create a large number of integers and need to reduce memory usage by avoiding the overheads of allocating and reallocating lots of small blocks. In normal programs this function is not recommended.

The space allocated to each integer by this function will not be automatically increased, unlike the normal

`mpz_init`

, so an application must ensure it is sufficient for any value stored. The following space requirements apply to various routines,-
`mpz_abs`

,`mpz_neg`

,`mpz_set`

,`mpz_set_si`

and`mpz_set_ui`

need room for the value they store. -
`mpz_add`

,`mpz_add_ui`

,`mpz_sub`

and`mpz_sub_ui`

need room for the larger of the two operands, plus an extra`mp_bits_per_limb`

. -
`mpz_mul`

,`mpz_mul_ui`

and`mpz_mul_si`

need room for the sum of the number of bits in their operands, but each rounded up to a multiple of`mp_bits_per_limb`

. -
`mpz_swap`

can be used between two array variables, but not between an array and a normal variable.

For other functions, or if in doubt, the suggestion is to calculate in a regular

`mpz_init`

variable and copy the result to an array variable with`mpz_set`

.-

- Function:
*void ****_mpz_realloc***(mpz_t*`integer`, mp_size_t`new_alloc`) Change the space for

`integer`to`new_alloc`limbs. The value in`integer`is preserved if it fits, or is set to 0 if not. The return value is not useful to applications and should be ignored.`mpz_realloc2`

is the preferred way to accomplish allocation changes like this.`mpz_realloc2`

and`_mpz_realloc`

are the same except that`_mpz_realloc`

takes its size in limbs.

- Function:
*mp_limb_t***mpz_getlimbn***(mpz_t*`op`, mp_size_t`n`) Return limb number

`n`from`op`. The sign of`op`is ignored, just the absolute value is used. The least significant limb is number 0.`mpz_size`

can be used to find how many limbs make up`op`.`mpz_getlimbn`

returns zero if`n`is outside the range 0 to`mpz_size(`

.`op`)-1

- Function:
*size_t***mpz_size***(mpz_t*`op`) Return the size of

`op`measured in number of limbs. If`op`is zero, the returned value will be zero.

[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |

This document was generated on *February 16, 2012* using *texi2html 5.0*.