This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Option to make unsigned->signed conversion always well-defined?


Pedro Pedruzzi <pedro.pedruzzi@gmail.com> writes:
> On Thu, Oct 6, 2011 at 11:04 AM, Miles Bader <miles@gnu.org> wrote:
>> How about:
>>
>>   bool overflowbit2(unsigned int a, unsigned int b)
>>   {
>>       const unsigned int sum = a + b;
>>       return ~(a ^ b) & sum & 0x80;
>>   }
>
> Miles, it is not the same. Take for example (0xff, 0xff). In 8-bit
> 2's complement, this is (-1, -1) and does not overflow. Your
> function says it does.

Negative overflow isn't considered overflow...?  wacky...

-miles

-- 
=====
(^o^;
(()))
*This is the cute octopus virus, please copy it into your sig so it can spread.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]