Node:Assigning Integers, Next:, Previous:Initializing Integers, Up:Integer Functions



Assignment Functions

These functions assign new values to already initialized integers (see Initializing Integers).

void mpz_set (mpz_t rop, 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, mpq_t op) Function
void mpz_set_f (mpz_t rop, mpf_t op) Function
Set the value of rop from op.

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

int mpz_set_str (mpz_t rop, char *str, int base) Function
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 36. If base is 0, the actual base is determined from the leading characters: if the first two characters are "0x" or "0X", hexadecimal is assumed, otherwise if the first character is "0", octal is assumed, otherwise decimal is assumed.

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

[It turns out that it is not entirely true that this function ignores white-space. It does ignore it between digits, but not after a minus sign or within or after "0x". We are considering changing the definition of this function, making it fail when there is any white-space in the input, since that makes a lot of sense. Send your opinion of this change to bug-gmp@gnu.org. Do you really want it to accept "3 14" as meaning 314 as it does now?]

void mpz_swap (mpz_t rop1, mpz_t rop2) Function
Swap the values rop1 and rop2 efficiently.