Binary output of mpf_get_str() has too many bits?
Rick Regan
exploringbinary at gmail.com
Thu May 20 15:10:15 CEST 2010
On Wed, May 19, 2010 at 6:49 PM, Case Vanhorsen <casevh at gmail.com> wrote:
> On Wed, May 19, 2010 at 12:17 PM, John Westwood
> <john at westwoodsolutions.com> wrote:
> > Sorry, I don't know.
> >
> > Maybe one of the developers can answer?
>
> (I'm not a developer, but I think this is the behavior.)
>
> GMP actually uses the limb-size as the radix for storing an mpf.
> Assuming you're on a system that uses 32-bit limbs, when you ask for
> 64 bits of precision, GMP actually 4 limbs: the most-significant limb
> will contain between 1 and 32 of the mantissa, the next two limbs
> contain the 64 bits that are guaranteed, and the next limb may or may
> not be used. This approach is faster since it eliminates the shifting
> needed to normalize the mantissa but results may not be what you
> expect.
>
> If you want precise control over the precision, you should use MPFR.
>
In this case, I don't need precise control -- I just wanted to understand
the precision behind a decimal to mpf conversion.
So what is the take home message? Is it that 'precision' number of bits are
accurate, and that possibly a few bits beyond are as well, but not
guaranteed?
Thanks for your answer.
Rick
--
Check out my blog: http://www.exploringbinary.com
More information about the gmp-discuss
mailing list