Micro-GMP

Marc Glisse marc.glisse at inria.fr
Fri Nov 30 12:09:25 UTC 2018


On Fri, 30 Nov 2018, Vincent Lefevre wrote:

> On 2018-11-30 07:43:40 +0100, Marco Bodrato wrote:
>> I looked at the code and I'd suggest a couple of simpler implementations:
>>
>> mpz_set_si (mpz_t r, signed long int x)
>> {
>>   if (x >= 0)
>>     mpz_set_ui (r, x);
>>   else /* (x < 0) */
>>     {
>>       mpz_set_ui (r, GMP_NEG_CAST (unsigned long int, x));
>>       mpz_neg (r, r);
>>     }
>> }
>
> What is the purpose of GMP_NEG_CAST
>
> #define GMP_NEG_CAST(T,x) (-((T)((x) + 1) - 1))
>
> instead of just a cast followed by a negation? i.e.
>
>  mpz_set_ui (r, - (unsigned long int) x);

I guess it comes from
https://gmplib.org/list-archives/gmp-bugs/2012-February/002545.html
https://gmplib.org/list-archives/gmp-devel/2012-March/002306.html
etc.

(where we were both in favor of the simpler version ;-)

-- 
Marc Glisse


More information about the gmp-devel mailing list