5.2 Assignment Functions

These functions assign new values to already initialized integers (see Initialization Functions).

Function: void mpz_set (mpz_t rop, const mpz_t op)
Function: void mpz_set_ui (mpz_t rop, unsigned long int op)
Function: void mpz_set_si (mpz_t rop, signed long int op)
Function: void mpz_set_d (mpz_t rop, double op)
Function: void mpz_set_q (mpz_t rop, const mpq_t op)
Function: void mpz_set_f (mpz_t rop, const mpf_t op)

Set the value of rop from op.

mpz_set_d, mpz_set_q and mpz_set_f truncate op to make it an integer.

Function: int mpz_set_str (mpz_t rop, const char *str, int base)

Set the value of rop from str, a null-terminated C string in base base. White space is allowed in the string, and is simply ignored.

The base may vary from 2 to 62, or if base is 0, then the leading characters are used: 0x and 0X for hexadecimal, 0b and 0B for binary, 0 for octal, or decimal otherwise.

For bases up to 36, case is ignored; upper-case and lower-case letters have the same value. For bases 37 to 62, upper-case letters represent the usual 10..35 while lower-case letters represent 36..61.

This function returns 0 if the entire string is a valid number in base base. Otherwise it returns −1.

Function: void mpz_swap (mpz_t rop1, mpz_t rop2)

Swap the values rop1 and rop2 efficiently.