ic Arithmetic Functions,  Prev: Combined Initialization and Assignment Functions,  Up: MPFR Interface

5.4 Conversion Functions
========================

 -- Function: double mpfr_get_d (mpfr_t OP, mp_rnd_t RND)
 -- Function: long double mpfr_get_ld (mpfr_t OP, mp_rnd_t RND)
 -- Function: _Decimal64 mpfr_get_decimal64 (mpfr_t OP, mp_rnd_t RND)
     Convert OP to a `double' (respectively `_Decimal64' or `long
     double'), using the rounding mode RND.  If OP is NaN, some fixed
     NaN (either quiet or signaling) or the result of 0.0/0.0 is
     returned. If OP is Inf, an infinity of the same sign or the
     result of 1.0/0.0 is returned. If OP is zero, these functions
     return a zero, trying to preserve its sign, if possible.  The
     `mpfr_get_decimal64' function is built only under some conditions:
     see the documentation of `mpfr_set_decimal64'.

 -- Function: double mpfr_get_d_2exp (long *EXP, mpfr_t OP, mp_rnd_t
          RND)
 -- Function: long double mpfr_get_ld_2exp (long *EXP, mpfr_t OP,
          mp_rnd_t RND)
     Return D and set EXP such that 0.5<=abs(D)<1 and D times 2 raised
     to EXP equals OP rounded to double (resp. long double) precision,
     using the given rounding mode.  If OP is zero, then a zero of the
     same sign (or an unsigned zero, if the implementation does not
     have signed zeros) is returned, and EXP is set to 0.  If OP is NaN
     or an infinity, then the corresponding double precision (resp.
     long-double precision) value is returned, and EXP is undefined.

 -- Function: long mpfr_get_si (mpfr_t OP, mp_rnd_t RND)
 -- Function: unsigned long mpfr_get_ui (mpfr_t OP, mp_rnd_t RND)
 -- Function: intmax_t mpfr_get_sj (mpfr_t OP, mp_rnd_t RND)
 -- Function: uintmax_t mpfr_get_uj (mpfr_t OP, mp_rnd_t RND)
     Convert OP to a `long', an `unsigned long', an `intmax_t' or an
     `uintmax_t' (respectively) after rounding it with respect to RND.
     If OP is NaN, the result is undefined.  If OP is too big for the
     return type, it returns the maximum or the minimum of the
     corresponding C type, depending on the direction of the overflow.
     The _erange_ flag is set too.  See also `mpfr_fits_slong_p',
     `mpfr_fits_ulong_p', `mpfr_fits_intmax_p' and
     `mpfr_fits_uintmax_p'.

 -- Function: mp_exp_t mpfr_get_z_exp (mpz_t ROP, mpfr_t OP)
     Put the scaled significand of OP (regarded as an integer, with the
     precision of OP) into ROP, and return the exponent EXP (which may
     be outside the current exponent range) such that OP exactly equals
     ROP multiplied by two exponent EXP.  If OP is zero, the minimal
     exponent `emin' is returned.  If the exponent is not representable
     in the `mp_exp_t' type, the behavior is undefined.

 -- Function: void mpfr_get_z (mpz_t ROP, mpfr_t OP, mp_rnd_t RND)
     Convert OP to a `mpz_t', after rounding it with respect to RND. If
     OP is NaN or Inf, the result is undefined.

 -- Function: int mpfr_get_f (mpf_t ROP, mpfr_t OP, mp_rnd_t RND)
     Convert OP to a `mpf_t', after rounding it with respect to RND.
     Return zero iff no error occurred, in particular a non-zero value
     is returned if OP is NaN or Inf, which do not exist in `mpf'.

 -- Function: char * mpfr_get_str (char *STR, mp_exp_t *EXPPTR, int B,
          size_t N, mpfr_t OP, mp_rnd_t RND)
     Convert OP to a string of digits in base B, with rounding in the
     direction RND, where N is either zero (see below) or the number of
     significant digits; in the latter case, N must be greater or equal
     to 2. The base may vary from 2 to 36.

     The generated string is a fraction, with an implicit radix point
     immediately to the left of the first digit.  For example, the
     number -3.1416 would be returned as "-31416" in the string and 1
     written at EXPPTR.  If RND is to nearest, and OP is exactly in the
     middle of two possible outputs, the one with an even significand
     is chosen: that significand is considered with the exponent of OP.
     Note that for an odd base, this may not correspond to an even last
     digit: for example with 2 digits in base 7, 16 and a half is
     rounded to 20 which is 14 in decimal, 36 and a half is rounded to
     40 which is 28 in decimal, and 66 and a half is rounded to 66
     which is 48 in decimal.

     If N is zero, the number of digits of the significand is chosen
     large enough so that re-reading the printed value with the same
     precision, assuming both output and input use rounding to nearest,
     will recover the original value of OP.  More precisely, in most
     cases, the chosen precision of STR is the minimal precision
     depending on P = PREC(OP) and B only that satisfies the above
     property, i.e., m = 1 + ceil(P*log(2)/log(B)), with P replaced by
     P-1 if B is a power of 2, but in some very rare cases, it might be
     m+1 (the smallest case for bases up to 62 is when P equals
     186564318007 for bases 7 and 49).

     If STR is a null pointer, space for the significand is allocated
     using the current allocation function, and a pointer to the string
     is returned.  To free the returned string, you must use
     `mpfr_free_str'.

     If STR is not a null pointer, it should point to a block of storage
     large enough for the significand, i.e., at least `max(N + 2, 7)'.
     The extra two bytes are for a possible minus sign, and for the
     terminating null character.

     If the input number is an ordinary number, the exponent is written
     through the pointer EXPPTR (the current minimal exponent for 0).

     A pointer to the string is returned, unless there is an error, in
     which case a null pointer is returned.

 -- Function: void mpfr_free_str (char *STR)
     Free a string allocated by `mpfr_get_str' using the current
     unallocation function (preliminary interface).  The block is
     assumed to be `strlen(STR)+1' bytes.  For more information about
     how it is done: *note Custom Allocation: (gmp.info)Custom
     Allocation.

 -- Function: int mpfr_fits_ulong_p (mpfr_t OP, mp_rnd_t RND)
 -- Function: int mpfr_fits_slong_p (mpfr_t OP, mp_rnd_t RND)
 -- Function: int mpfr_fits_uint_p (mpfr_t OP, mp_rnd_t RND)
 -- Function: int mpfr_fits_sint_p (mpfr_t OP, mp_rnd_t RND)
 -- Function: int mpfr_fits_ushort_p (mpfr_t OP, mp_rnd_t RND)
 -- Function: int mpfr_fits_sshort_p (mpfr_t OP, mp_rnd_t RND)
 -- Function: int mpfr_fits_intmax_p (mpfr_t OP, mp_rnd_t RND)
 -- Function: int mpfr_fits_uintmax_p (mpfr_t OP, mp_rnd_t RND)
     Return non-zero if OP would fit in the respective C data type, when
     rounded to an integer in the direction RND.

