Node:Converting Floats, Next:, Previous:Simultaneous Float Init & Assign, Up:Floating-point Functions



Conversion Functions

double mpf_get_d (mpf_t op) Function
Convert op to a double.

double mpf_get_d_2exp (signed long int exp, mpf_t op) Function
Find d and exp such that d times 2 raised to exp, with 0.5<=abs(d)<1, is a good approximation to op. This is similar to the standard C function frexp.

long mpf_get_si (mpf_t op) Function
unsigned long mpf_get_ui (mpf_t op) Function
Convert op to a long or unsigned long, truncating any fraction part. If op is too big for the return type, the result is undefined.

See also mpf_fits_slong_p and mpf_fits_ulong_p (see Miscellaneous Float Functions).

char * mpf_get_str (char *str, mp_exp_t *expptr, int base, size_t n_digits, mpf_t op) Function
Convert op to a string of digits in base base. base can be 2 to 36. Up to n_digits digits will be generated. Trailing zeros are not returned. No more digits than can be accurately represented by op are ever generated. If n_digits is 0 then that accurate maximum number of digits are generated.

If str is NULL, the result string is allocated using the current allocation function (see Custom Allocation). The block will be strlen(str)+1 bytes, that being exactly enough for the string and null-terminator.

If str is not NULL, it should point to a block of n\_digits + 2 bytes, that being enough for the mantissa, a possible minus sign, and a null-terminator. When n_digits is 0 to get all significant digits, an application won't be able to know the space required, and str should be NULL in that case.

The generated string is a fraction, with an implicit radix point immediately to the left of the first digit. The applicable exponent is written through the expptr pointer. For example, the number 3.1416 would be returned as string "31416" and exponent 1.

When op is zero, an empty string is produced and the exponent returned is 0.

A pointer to the result string is returned, being either the allocated block or the given str.