Ciao Marc,
Il 2022-02-08 10:05 Marc Glisse ha scritto:
Makes sense to me. I am just not sure if 3 is the right number and if
we are consistent about it. Shouldn't 2 be enough? Or is it to be safe
You are right. 2 should be enough.
I think that if a not realloc-able mpz is used as a target for a
function, it should contain at least one extra limb. But we are not
consistent about this.
If ones try
gmp$ grep MPZ_TMP_INIT -r mpz
many +1 are found...
But specifically for the gcd one can find
gmp$ grep MPZ_TMP_INIT -r mpq/aors.c
MPZ_TMP_INIT (gcd, MIN (op1_den_size, op2_den_size));
I don't think we need to set SIZ(lw) but it looks cleaner and can't be
very expensive.
I agree, not really needed, but it's probably better to always pass a
well defined mpz_t to functions.
diff -r ed0406cf3c70 mpz/gcd_ui.c
--- a/mpz/gcd_ui.c Wed Feb 02 19:16:36 2022 +0100
+++ b/mpz/gcd_ui.c Tue Feb 08 09:30:53 2022 +0100
@@ -41,7 +41,16 @@
if (v > GMP_NUMB_MAX)
{
mpz_t vz;
- mp_limb_t vlimbs[2];
+ mpz_t lw;
+ mp_limb_t vlimbs[2], wlimbs[3];
+
+ if (w == NULL)
+ {
+ PTR(lw) = wlimbs;
+ ALLOC(lw) = 3;
+ SIZ(lw) = 0;
+ w = lw;
+ }
vlimbs[0] = v & GMP_NUMB_MASK;
vlimbs[1] = v >> GMP_NUMB_BITS;
PTR(vz) = vlimbs;
Ĝis,
m
_______________________________________________
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs