Velocity Reviews > Integer Overflow

# Integer Overflow

Michael Press
Guest
Posts: n/a

 01-05-2011
In article <(E-Mail Removed)>,
Keith Thompson <(E-Mail Removed)> wrote:

> Right. We've argued that because it happens to be true. See C99
> 6.2.5p9:
>
> A computation involving unsigned operands can never overflow,
> because a result that cannot be represented by the resulting
> unsigned integer type is reduced modulo the number that is one
> greater than the largest value that can be represented by the
> resulting type.
>
> Informally, it's reasonable to refer to what happens when the result
> of an unsigned operation won't fit in the target type as "overflow".
> The point is that the standard very specifically *doesn't* refer
> to it as "overflow".
>
> If you don't like the way the standard uses, or doesn't use,
> the term "overflow", that's fine. I'm not sure I like it myself.
> All I'm doing is pointing out what the standard actually says.

There is little to like or dislike. The usage and
definitions are well established and effective.
Overflow only matters for 2's complement arithmetic.

C is carry out of the high bit of a word.
R is carry into the high bit of a word.
O is overflow.
O = C ^ R

Consider four bit words.
_
ADD 1000 1111 -> 0111 C R V
_
ADD 0100 0100 -> 1000 C R V
_ _ _
ADD 0100 0011 -> 0111 C R V
_
ADD 1100 1100 -> 1000 C R V
_
NEG 1000 -> 1000 C R V

When the bit patterns are interpreted as unsigned integers
only carry matters.

--
Michael Press

gepe
Guest
Posts: n/a

 01-05-2011
On 28 Dez. 2010, 13:12, Malcolm McLean
<(E-Mail Removed)> wrote:
> On Dec 28, 10:13*am, arnuld <(E-Mail Removed)> wrote:> WANTED: How to handle integer overflows (and overflows in general)
>
> > NOTE: Came to think of this exercise because of this article that claims
> > "Nearly all binary searches and mergesorts are broken".

>
> Normally it's inappropriate for general-purpose logic code to have to
>
> The real answer is to join the campaign for 64 bit ints. Searchable
> arrays of real data aren't going to go above 64 bits any time soon, so
> the problem is eliminated.

Computations with 64 bit ints can overflow as computations
with 32 bit ints.

Georg Peter