[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
5.16 Internals
The following types and functions were mainly designed for the implementation of MPFR, but may be useful for users too. However no upward compatibility is guaranteed. You may need to include ‘mpfr-impl.h’ to use them.
The mpfr_t
type consists of four fields.
- The
_mpfr_prec
field is used to store the precision of the variable (in bits); this is not less thanMPFR_PREC_MIN
. - The
_mpfr_sign
field is used to store the sign of the variable. - The
_mpfr_exp
field stores the exponent. An exponent of 0 means a radix point just above the most significant limb. Non-zero values n are a multiplier 2^n relative to that point. A NaN, an infinity and a zero are indicated by a special value of the exponent. - Finally, the
_mpfr_d
is a pointer to the limbs, least significant limbs stored first. The number of limbs in use is controlled by_mpfr_prec
, namely ceil(_mpfr_prec
/mp_bits_per_limb
). Non-singular values always have the most significant bit of the most significant limb set to 1. When the precision does not correspond to a whole number of limbs, the excess bits at the low end of the data are zero.
- Function: int mpfr_can_round (mpfr_t b, mp_exp_t err, mp_rnd_t rnd1, mp_rnd_t rnd2, mp_prec_t prec)
Assuming b is an approximation of an unknown number x in the direction rnd1 with error at most two to the power E(b)-err where E(b) is the exponent of b, return a non-zero value if one is able to round correctly x to precision prec with the direction rnd2, and 0 otherwise (including for NaN and Inf). This function does not modify its arguments.
Note: if one wants to also determine the correct ternary value when rounding b to precision prec, a useful trick is the following:
if (mpfr_can_round (b, err, rnd1, GMP_RNDZ, prec + (rnd2 == GMP_RNDN))) ...
Indeed, if rnd2 is
GMP_RNDN
, this will check if one can round to prec+1 bits with a directed rounding: if so, one can surely round to nearest to prec bits, and in addition one can determine the correct ternary value, which would not be the case when b is near from a value exactly representable on prec bits.
- Function: double mpfr_get_d1 (mpfr_t op)
Convert op to a
double
, using the default MPFR rounding mode (see functionmpfr_set_default_rounding_mode
). This function is obsolete.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |