|
Boost : |
Subject: Re: [boost] Is there interest in portable integer overflow detection, with policy based handling?
From: Robert Ramey (ramey_at_[hidden])
Date: 2012-02-22 14:37:23
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.
I am aware of this. but what is the result of this operation? To be
correct it would have to be negative. But the numerator is unsigned.
How is this resolved? To take a pathological case:
unsigned int x = std::numeric_limits<unsigned int>::max();
x = x / (-1);
Will this throw? or fail at compile time, or what?
Robert Ramey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk