Subject: Re: detect arithmetic overflow
To: None <>
From: Christos Zoulas <>
List: current-users
Date: 08/06/2003 14:27:39
In article <Pine.LNX.4.21.0308061116010.7039-100000@Tempo.Update.UU.SE>,
Johnny Billquist <> wrote:
>On Wed, 6 Aug 2003, David Laight wrote:
>> > It's even easier than that. For signed addition, just check if the result
>> > is negative. If so, then you have overflow. For unsigned addition, you'll
>> > have to test it as you described, though.
>> errmm  -1 + -1 = -2 but hasn't overflowed
>Argh. My brain is positive. :-)
>However, the result is also less than both operands... So you just flunked
>yourself too. :-)
>Actually, you need the opposite test for negative operands, and if the
>operands have different sign, you will not get overflow.

Isn't the two's complement arithmetic rule for overflow that the carry bit
into the signed bit must equal to the carry bit out of the signed bit?