Torbjörn Granlund tg at gmplib.org
Mon Dec 3 12:04:11 UTC 2018

  > 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);

This is confusing.

1. We can never use this for signed types with negative values if T is

2. For signed source types, the + 1 - 1 trickery might help for MIN_INT
   (etc) but will cause undefined behavious for MAX_INT (etc).

For unsigned source and destination types, things are fine, but any
plain expression will work fine.

For signed source to wider signed destination types, again any plain
expression should work fine.

Please encrypt, key id 0xC8601622

More information about the gmp-devel mailing list