Go to the first, previous, next, last section, table of contents.


Conversion Functions

This section describes functions for converting GMP integers to standard C types. Functions for converting to GMP integers are described in section Assignment Functions and section Input and Output Functions.

Function: mp_limb_t mpz_getlimbn (mpz_t op, mp_size_t n)
Return limb #n from op. This function allows for very efficient decomposition of a number in its limbs.

The function mpz_size can be used to determine the useful range for n.

Function: unsigned long int mpz_get_ui (mpz_t op)
Return the least significant part from op. This function combined with
mpz_tdiv_q_2exp(..., op, CHAR_BIT*sizeof(unsigned long int)) can be used to decompose an integer into unsigned longs.

Function: signed long int mpz_get_si (mpz_t op)
If op fits into a signed long int return the value of op. Otherwise return the least significant part of op, with the same sign as op.

If op is too large to fit in a signed long int, the returned result is probably not very useful. To find out if the value will fit, use the function mpz_fits_slong_p.

Function: double mpz_get_d (mpz_t op)
Convert op to a double.

Function: char * mpz_get_str (char *str, int base, mpz_t op)
Convert op to a string of digits in base base. The base may vary from 2 to 36.

If str is NULL, space for the result string is allocated using the default allocation function.

If str is not NULL, it should point to a block of storage enough large for the result. To find out the right amount of space to provide for str, use mpz_sizeinbase (op, base) + 2. The two extra bytes are for a possible minus sign, and for the terminating null character.

A pointer to the result string is returned. This pointer will will either equal str, or if that is NULL, will point to the allocated storage.


Go to the first, previous, next, last section, table of contents.