PATCH: Bad signed int to long long conversion

Vincent Lefevre vincent at
Thu Feb 9 17:47:32 CET 2012

On 2012-02-09 17:01:45 +0100, Torbjorn Granlund wrote:
> Strictly speaking, I don't think things like (unsigned long)(MIN_LONG)
> is well-defined C.

It is well-defined: Signed and unsigned integers

  1   When a value with integer type is converted to another integer
      type other than _Bool, if the value can be represented by the
      new type, it is unchanged.
  2   Otherwise, if the new type is unsigned, the value is converted
      by repeatedly adding or subtracting one more than the maximum
      value that can be represented in the new type until the value
      is in the range of the new type.60)

  60) The rules describe arithmetic on the mathematical value, not
      the value of a given type of expression. describes the usual modular arithmetic rule.

Vincent Lefèvre <vincent at> - Web: <>
100% accessible validated (X)HTML - Blog: <>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

More information about the gmp-bugs mailing list