bug-gmp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: unexpected rounding behaviour of mpf_add(). bug?


From: Frederik Schaffalitzky
Subject: Re: unexpected rounding behaviour of mpf_add(). bug?
Date: Thu, 3 May 2001 09:05:21 +0100 (BST)

On 3 May 2001, Kevin Ryde wrote:

> Yes, if you ask for 64-bits on a 32-bit limb, then 3 limbs are used
> (because the high limb is only a non-zero value).

I assumed a limb on my machine was 16 bits (because of the 3+1=4 limbs
allocated) but on closer inspection you are right.


> Yes, it uses the full prec+1 space, but just 3 limbs would have
> sufficed.  Hmm.  Maybe it should only generate 3 limbs, since the 4th
> is not needed for the requested precision.

No that is fine; if GMP isn't trying to make guarantees about rounding
then it shouldn't, errhm, be trying. :) It might make the square root
function slightly slower than it needs to be, though.


> No, I believe 3 limbs make up 64 bits.

You're right. Sorry, my fault.


> If you're adding 3 limbs to 3 limbs (same exponent), then there can be
> a carry, so you need a 4th limb to store it in.  The alternative would
> be, on finding a carry, to move the high 2 of the sum down to make
> room, but it's more efficient to not do that, rather store 4 limbs and
> let the next routine using that value take just 3 if that's all it
> wants.

Yes, that would be more efficient. It means bumping the exponent down
quite a bit, though. If I understand correctly, for a requested precision
of 32*m bits, the number of 32-bit words allocated is m+2: one extra in
case of carries and another extra one because the most significant word
might be mostly zeros.


> Yes, that should work, and never lose any bits needed for the desired
> precision.  Bear in mind that this is outside the documented features
> and hence not guaranteed to be compatible with future releases, etc,
> etc.  (Though in reality big changes in that area are unlikely.)

In the end I decided to use mpfr, though the one distributed with GMP is
out of date and is missing several of the features described in current
documentation. It wasn't hard to hack the Makefile*s to use the most
recent release, though.

Is it true that mpfr will be fully integrated in future releases of GMP?

Thanks again,

Frederik




reply via email to

[Prev in Thread] Current Thread [Next in Thread]