Boost logo

Boost :

Subject: Re: [boost] Is there interest in portable integer overflow detection, with policy based handling?
From: John Bytheway (jbytheway+boost_at_[hidden])
Date: 2012-02-22 14:00:17


On 22/02/12 18:40, Ben Robinson wrote:
> On Wed, Feb 22, 2012 at 9:38 AM, Robert Ramey <ramey_at_[hidden]> wrote:
>
>> Ben Robinson wrote:
>>
>>> Overflow (positive and negative) are not possible with division and
>>> modulus.
>>
>> hmmm - what happens when an unsigned integer is divided by a
>> negative number? Doesn't this overflow or something?
>>
>> A positive whole number divided by a negative whole number is a negative
> value which is smaller in magnitude than the original numerator. With
> integers, truncation of the fractional part may be involved, but this is
> not overflow. Integers can only overflow in the positive and negative
> direction. That is not the same as underflow, which floating point numbers
> can do.

What about UINT_MAX/-1 or INT_MIN/-1. I believe they both overflow by
your definition.

John Bytheway


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk