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

marco.bodrato at tutanota.com marco.bodrato at tutanota.com
Sun Feb 18 00:11:19 CET 2024


Ciao Niels,

17 feb 2024, 21:26 da nisse at lysator.liu.se:

> marco.bodrato at tutanota.com writes:
>
>> Maybe we should also add the test:
>>
>>   /* Require that s==0 iff g==abs(b) */
>>   if (!mpz_sgn (s) ^ !mpz_cmpabs (g, b))
>>       goto fail;
>>
>
> Good point, that's better than only checking the special case |a| ==
> |b|. (But maybe more readable with != instead of ^).
>

Yes, with != it's more readable!


> To get mini-gmp to conform, I find no simpler way than special casing s
> == 0, like
>
s==0 is not a special case, it's one of the cases with smaller |s|.

What about;

/* Arrange so that |s| < |u| / 2g */
  mpz_add (s1, s0, s1);
  {
    int cmp = mpz_cmpabs (s0, s1);
    if (cmp >= 0)
      {
        mpz_swap (s0, s1);
        mpz_sub (t1, t0, t1);
        if (cmp != 0 || mpz_cmpabs (t0, t1) > 0)
          mpz_swap (t0, t1);
      }
  }

Ĝis,
m


More information about the gmp-bugs mailing list