Documentation of mpn_gcd and overlap

Marc Glisse marc.glisse at
Sun Jan 13 16:04:15 CET 2013

On Sun, 13 Jan 2013, Niels Möller wrote:

> Marc Glisse <marc.glisse at> writes:
>> I am surprised at such a no-overlap requirement between the inputs. Is
>> it meant to forbid overlaps with {rp, *} instead? Or am I missing a
>> reason why overlap of inputs can cause problems?
> You're aware that the input areas are destroyed? They're used as working
> storage during the algorithm, and things will most likely get confused
> if the areas are not distinct.

Oups, no, I wasn't, I managed to miss that sentence right in the middle, 
now I am glad I asked :-)

I did notice the lack of "const" on the arguments, but my brain didn't go 
as far as deducing that they were written to.

> I don't remember off the top of my head if overlap with rp is intended
> to work, but I think it does; that area is not written to until the
> algorithm terminates.
> And I'm puzzled about when overlap between inputs could be useful. Do
> you have an example?

I had forgotten to insert a check whether the inputs were the same, and I 
expected that to be just a missed optimization.

Thank you for the explanation,

Marc Glisse

More information about the gmp-bugs mailing list