Nomenclature and Types (GNU MP 6.3.0)
Description: How to install and use the GNU multiple precision arithmetic library, version 6.3.0.

### 3.2 Nomenclature and Types

In this manual, integer usually means a multiple precision integer, as defined by the GMP library. The C data type for such integers is `mpz_t`. Here are some examples of how to declare such integers:

    mpz_t sum;

    struct foo { mpz_t x, y; };

    mpz_t vec[20];

Rational number means a multiple precision fraction. The C data type for these fractions is `mpq_t`. For example:

    mpq_t quotient;

Floating point number or Float for short, is an arbitrary precision mantissa with a limited precision exponent. The C data type for such objects is `mpf_t`. For example:

    mpf_t fp;

The floating point functions accept and return exponents in the C type `mp_exp_t`. Currently this is usually a `long`, but on some systems it’s an `int` for efficiency.

A limb means the part of a multi-precision number that fits in a single machine word. (We chose this word because a limb of the human body is analogous to a digit, only larger, and containing several digits.) Normally a limb is 32 or 64 bits. The C data type for a limb is `mp_limb_t`.

Counts of limbs of a multi-precision number represented in the C type `mp_size_t`. Currently this is normally a `long`, but on some systems it’s an `int` for efficiency, and on some systems it will be `long long` in the future.

Counts of bits of a multi-precision number are represented in the C type `mp_bitcnt_t`. Currently this is always an `unsigned long`, but on some systems it will be an `unsigned long long` in the future.

Random state means an algorithm selection and current state data. The C data type for such objects is `gmp_randstate_t`. For example:

    gmp_randstate_t rstate;

Also, in general `mp_bitcnt_t` is used for bit counts and ranges, and `size_t` is used for byte or character counts.

Internally, GMP data types such as `mpz_t` are defined as one-element arrays, whose element type is part of the GMP internals (see Internals).

When an array is used as a function argument in C, it is not passed by value, instead its value is a pointer to the first element. In C jargon, this is sometimes referred to as the array "decaying" to a pointer. For GMP types like `mpz_t`, that means that the function called gets a pointer to the caller’s `mpz_t` value, which is why no explicit `&` operator is needed when passing output arguments (see Parameter Conventions).

GMP defines names for these pointer types, e.g., `mpz_ptr` corresponding to `mpz_t`, and `mpz_srcptr` corresponding to `const mpz_t`. Most functions don’t need to use these pointer types directly; it works fine to declare a function using the `mpz_t` or `const mpz_t` as the argument types, the same "pointer decay" happens in the background regardless.

Occasionally, it is useful to manipulate pointers directly, e.g., to conditionally swap references to a function’s inputs without changing the values as seen by the caller, or returning a pointer to an `mpz_t` which is part of a larger structure. For these cases, the pointer types are necessary. And a `mpz_ptr` can be passed as argument to any GMP function declared to take an `mpz_t` argument.

Their definition is equivalent to the following code, which is given for illustratory purposes only:

        typedef foo_internal foo_t[1];
        typedef foo_internal * foo_ptr;
        typedef const foo_internal * foo_srcptr;

The following pointer types are defined by GMP:

- `mpz_ptr` for pointers to the element type in `mpz_t`
- `mpz_srcptr` for `const` pointers to the element type in `mpz_t`
- `mpq_ptr` for pointers to the element type in `mpq_t`
- `mpq_srcptr` for `const` pointers to the element type in `mpq_t`
- `mpf_ptr` for pointers to the element type in `mpf_t`
- `mpf_srcptr` for `const` pointers to the element type in `mpf_t`
- `gmp_randstate_ptr` for pointers to the element type in `gmp_randstate_t`
- `gmp_randstate_srcptr` for `const` pointers to the element type in `gmp_randstate_t`