What is the minimum precision allowed for floats.
Joel Kronander
joekr552 at student.liu.se
Mon Sep 29 17:01:37 CEST 2008
Hi, thank you for a good answer!
But when you point me to the mpfr library I am a bit confused.
I don't see how mpfr should work for "exactly" 6 bits etc. are you sure it
works?
I thought that double precision is minimum there?
/best regards Joel kronander
On Mon, Sep 29, 2008 at 3:33 PM, Paul Zimmermann
<Paul.Zimmermann at loria.fr>wrote:
> > Date: Sun, 28 Sep 2008 22:47:50 +0200
> > From: "Joel Kronander" <joekr552 at student.liu.se>
> >
> > Hi
> >
> > 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
> > double
> > 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.
>
> Paul Zimmermann
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gmplib.org/list-archives/gmp-discuss/attachments/20080929/e20e838b/attachment.html
More information about the gmp-discuss
mailing list