Binary output of mpf_get_str() has too many bits?

Case Vanhorsen casevh at gmail.com
Thu May 20 00:49:51 CEST 2010


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.

casevh
>
>
> On Wednesday 19 May 2010 17:38:42 Rick Regan wrote:
>> On Wed, May 19, 2010 at 12:06 PM, John Westwood
>>
>> <john at westwoodsolutions.com>wrote:
>> > The description of mpf_get_str in the manual states:
>> >
>> > "If n_digits is 0 then that accurate maximum number of digits are
>> > generated."
>> >
>> > So you could try specifying n_digits as 64, 96 and 128 and you should
>> > receive
>> > the correct number of bits when using a base of two.
>> >
>> > John
>>
>> I know that if I specify the number of digits I'll get that amount, but
>> since I have n_digits = 0, I'm expecting the "accurate maximum number of
>> digits." Why is it greater than the precision reported by get_prec()?
>>
>> Stepping through the program I see the following values for f internally:
>>
>> 64: mp = 0x0012ff3c {_mp_prec=3 _mp_size=4 _mp_exp=0 ...}
>> 96: mp = 0x0012ff3c {_mp_prec=4 _mp_size=5 _mp_exp=0 ...}
>> 128: mp = 0x0012ff3c {_mp_prec=5 _mp_size=6 _mp_exp=0 ...}
>>
>> So does that mean what get_prec() is reporting is actually 1 limb (32 bits)
>> less than what's actually used?
>> _______________________________________________
>> gmp-discuss mailing list
>> gmp-discuss at gmplib.org
>> https://gmplib.org/mailman/listinfo/gmp-discuss
>>
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at gmplib.org
> https://gmplib.org/mailman/listinfo/gmp-discuss
>


More information about the gmp-discuss mailing list