> On 20 Oct 2019, at 21:44, Torbjörn Granlund <[email protected]> wrote: > > Hans Åberg <[email protected]> writes: > > A common programming error is assuming that signed integer types are > two’s complement, because even though all current CPUs are that, > overflows are undefined in C/C++, and an optimizer can take advantage > of that. One example from [1]: checking overflows with x > x + 1 may > work as intended with optimization turned off, but when on, the > optimizer can assume that it is always false since x + 1 is undefined > when overflowed. > > I believe we assume signed integers are in two's complement. > > We don't do a lot of arithmetic on signed integers, though.
Strictly, it is for signed overflows one cannot assume modulo 2^n, n = number of bits. For the unsigned integer types it is required, though. Here is a list for various languages: https://en.wikipedia.org/wiki/Integer_overflow _______________________________________________ gmp-bugs mailing list [email protected] https://gmplib.org/mailman/listinfo/gmp-bugs
