mpz_gcd_ext(NULL, ...)

Marco Bodrato bodrato at mail.dm.unipi.it
Tue Jan 10 21:18:05 UTC 2017


Ciao.

Il Dom, 1 Gennaio 2017 7:30 pm, Niels Möller ha scritto:
> "Marco Bodrato" <bodrato at mail.dm.unipi.it> writes:

>> While we are looking at gcdext, I propose a small change to save an
>> allocation when t must be computed. Can you review it, to check if the
>> size assumptions are safe?

> I guess it still allocates an extra limb for some arguments, which no
> longer is required by mpn_gcdext.

The code I pushed saves one more limb wrt the code I sent to the list. And
it should keep on respecting the requirement documented for mpn_gcdext. I
hope :-)

> You did one more thing in the committed change 84ce52f0d360:

> @@ -64,7 +64,7 @@ mpz_gcdext (mpz_ptr g, mpz_ptr s, mpz_pt
>
>        if (g != NULL)
>  	{
> -	  gp = MPZ_REALLOC (g, asize);
> +	  gp = MPZ_NEWALLOC (g, asize);
>  	  MPN_COPY (gp, PTR (a), asize);
>  	  SIZ (g) = asize;
>  	}

> That will break in case g == a, right?

No, it will not. If g == a, ALLOC (g) is not smaller than asize, so that
MPZ_*ALLOC will leave it untouched.

Best regards,
m

-- 
http://bodrato.it/papers/



More information about the gmp-devel mailing list