Micro-GMP
Vincent Lefevre
vincent at vinc17.net
Fri Nov 30 11:43:27 UTC 2018
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);
--
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
More information about the gmp-devel
mailing list