Ciao,
Il 2020-04-20 11:08 Vincent Lefevre ha scritto:
I think that in general, you should not write code that depends on
whether INT_MAX + INT_MIN == 0 or not (the constant INT_MAX + INT_MIN
might be useful in some rare cases, but I think that testing whether
this constant is 0 or not should be forbidden). This can mean that
Forbidden? Really! :-D
Anyway, using the numerical constant INT_MAX + INT_MIN is a good idea.
What about the following version of the function? :-D
int
mpz_fits_sint_p (const mpz_t u)
{
return mpz_cmpabs_ui (u, (unsigned long) INT_MAX + (unsigned long)
(u->_mp_size < 0 ? -(INT_MAX + INT_MIN) : 0)) <= 0;
}
By the way, jokes apart, Niels is right: we do not need to optimise this
function.
Please Niels, choose the implementation you prefer and change also
mpz_fits_slong_p accordingly.
Ĝis,
m
_______________________________________________
gmp-devel mailing list
gmp-devel@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-devel