PATCH: Bad signed int to long long conversion

Torbjorn Granlund tg at
Thu Feb 9 17:01:45 CET 2012

Marc Glisse <marc.glisse at> writes:

  On Thu, 1 Dec 2011, Torbjorn Granlund wrote:
  > I don't mind that somebody patches up all occurences of signed negation
  > where the smallest negative value could hypothetically appear.
  I don't know about "all occurences", but if there aren't any
  objections I plan to commit the patch attached.
  (I checked and gcc produces the same code for -1-(long)l as for
  (long)~l, even at -O0)

Strictly speaking, I don't think things like (unsigned long)(MIN_LONG)
is well-defined C.  This might happen in your macro:

+#define ABS_CAST(T,x) ((x) >= 0 ? (T)(x) : -(T)(x))

Perhaps the : part ought to be written -(T)((x) + 1) - 1 to really solve
the problem.


More information about the gmp-bugs mailing list