mini-gmp mpz_gcdext Bézout coefficients do not match documentation

Niels Möller nisse at
Sat Feb 17 20:04:50 CET 2024

marco.bodrato at writes:

> And if I correctly patched and tested your proposed code. with equal numbers I get t=0, instead of s=0.

Thanks for testing, I have to look into that case, then.

> Shat about simply changing the test from > to >= ?
>    /* Arrange so that |s| < |u| / 2g */
>    mpz_add (s1, s0, s1);
> -  if (mpz_cmpabs (s0, s1) > 0)
> +  if (mpz_cmpabs (s0, s1) >= 0)

I don't think that's right. My understanding is that if |s| = |s'|
(notation from my mail, the variables in the code are reassigned several
times, which is a bit confusing), then we ncessarily have |t| != |t'|,
and we must choose candidate to get the smaller one.


Niels Möller. PGP key CB4962D070D77D7FCB8BA36271D8F1FF368C6677.
Internet email is subject to wholesale government surveillance.

More information about the gmp-bugs mailing list