What is the minimum precision allowed for floats.
Paul.Zimmermann at loria.fr
Mon Sep 29 15:33:28 CEST 2008
> Date: Sun, 28 Sep 2008 22:47:50 +0200
> From: "Joel Kronander" <joekr552 at student.liu.se>
> I have a question regading the possible minimun precision for floats.
> For example is it possible to use a precision between native c float and
> ie precision digits between 6-15 for exmample.
> /best regards Joel Kronander
I guess your question is related to the mpf class. The manual says:
The precision selected for a variable is a minimum value, GMP may
increase it a little to facilitate efficient calculation. Currently
this means rounding up to a whole limb, and then sometimes having a
further partial limb, depending on the high limb of the mantissa. But
applications shouldn't be concerned by such details.
If you look in the internal file gmp-impl.h you will see:
/* __GMPF_BITS_TO_PREC applies a minimum 53 bits, rounds upwards to a whole
limb and adds an extra limb. __GMPF_PREC_TO_BITS drops that extra limb,
hence giving back the user's size in bits rounded up. Notice that
converting prec->bits->prec gives an unchanged value. */
#define __GMPF_BITS_TO_PREC(n) \
((mp_size_t) ((__GMP_MAX (53, n) + 2 * GMP_NUMB_BITS - 1) / GMP_NUMB_BITS))
thus you *can* ask for a precision of 6 or 15 bits, but then GMP will allocate
3 words on a 32-bit computer, and 2 words on a 64-bit computer, and it will
have the same effect as if you had asked for 53 or 64 bits.
If you want to have a precision of *exactly* 6 bits, I suggest you try MPFR
(see mpfr.org). It also works for 15 bits.
More information about the gmp-discuss