mini-gmp "bug" missing mpz_fits_sint_p / mpz_fits_uint_p

Niels Möller nisse at lysator.liu.se
Sun Apr 19 08:44:22 UTC 2020


Marco Bodrato <bodrato at mail.dm.unipi.it> writes:

> +int
> +mpz_fits_sint_p (const mpz_t u)
> +{
> +  return (INT_MAX + INT_MIN == 0 || mpz_cmp_ui (u, INT_MAX) <= 0) &&
> +    mpz_cmpabs_ui (u, GMP_NEG_CAST (unsigned long int, INT_MIN)) <= 0;
> +}

I think this and mpz_fits_sshort_p would be simpler using mpz_cmp_si,

int
mpz_fits_sint_p (const mpz_t u)
{
  return mpz_cmp_si (u, INT_MAX) <= 0 && mpz_cmp_si (i, INT_MIN) >= 0;
}

BTW, do we have any C implementation where INT_MAX + INT_MIN == 0, i.e.,
not using two's complement?

Regards,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.


More information about the gmp-devel mailing list