mpz_get_si: possible undefined behaviour? [Was: Micro-GMP]

Pedro Gimeno gmpdiscuss at
Tue Dec 4 14:02:43 UTC 2018

Torbjörn Granlund wrote, On 2018-12-04 13:45:
> Pedro Gimeno <gmpdevel at> writes:
>   An assertion of LONG_MIN < -LONG_MAX should make the code safe in that case.
> Does The Standard even guarantee thet there are about as many negative
> and positive number?
> I am really worried that GMP might not properly on a machine where
> LONG_MIN = -17 while LONG_MAX = 2^32-18.

I get your point, but since that assertion can be evaluated at compile time, it's cheap enough to add it.

Systems where LONG_MIN = LONG_MAX may be more common than it seems (not that I have personally seen any):


More information about the gmp-devel mailing list