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

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


Torbjörn Granlund wrote, On 2018-12-04 13:45:
> Pedro Gimeno <gmpdevel at formauri.es> 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):

https://superuser.com/questions/1137182/is-there-any-existing-cpu-implementation-which-uses-ones-complement

-- 
Pedro


More information about the gmp-devel mailing list