Subject: Re: detect arithmetic overflow
To: David Laight <>
From: Johnny Billquist <>
List: current-users
Date: 08/06/2003 11:21:07
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.


Johnny Billquist                  || "I'm on a bus
                                  ||  on a psychedelic trip
email:           ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol