Next: , Previous: Initializing Floats, Up: Floating-point Functions   [Index]


7.2 Assignment Functions

These functions assign new values to already initialized floats (see Initializing Floats).

Function: void mpf_set (mpf_t rop, const mpf_t op)
Function: void mpf_set_ui (mpf_t rop, unsigned long int op)
Function: void mpf_set_si (mpf_t rop, signed long int op)
Function: void mpf_set_d (mpf_t rop, double op)
Function: void mpf_set_z (mpf_t rop, const mpz_t op)
Function: void mpf_set_q (mpf_t rop, const mpq_t op)

Set the value of rop from op.

Function: int mpf_set_str (mpf_t rop, const char *str, int base)

Set the value of rop from the string in str. The string is of the form ‘M@N’ or, if the base is 10 or less, alternatively ‘MeN’. ‘M’ is the mantissa and ‘N’ is the exponent. The mantissa is always in the specified base. The exponent is either in the specified base or, if base is negative, in decimal. The decimal point expected is taken from the current locale, on systems providing localeconv.

The argument base may be in the ranges 2 to 62, or -62 to -2. Negative values are used to specify that the exponent is in decimal.

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 letter represent the usual 10..35 while lower-case letter represent 36..61.

Unlike the corresponding mpz function, the base will not be determined from the leading characters of the string if base is 0. This is so that numbers like ‘0.23’ are not interpreted as octal.

White space is allowed in the string, and is simply ignored. [This is not really true; white-space is ignored in the beginning of the string and within the mantissa, but not in other places, such as after a minus sign or in the exponent. 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. Please tell us your opinion about this change. Do you really want it to accept "3 14" as meaning 314 as it does now?]

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

Function: void mpf_swap (mpf_t rop1, mpf_t rop2)

Swap rop1 and rop2 efficiently. Both the values and the precisions of the two variables are swapped.


Next: , Previous: Initializing Floats, Up: Floating-point Functions   [Index]