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?


Ulf Magnusson <ulfalizer@gmail.com> writes:
> Might as well do
>
> bool overflowbit(unsigned int a, unsigned int b) {
>     const unsigned int sum = a + b;
>     return (a ^ b) & ~(a ^ sum) & 0x80;
> }
>
> But still not very good output compared to other approaches as expected.

How about:

   bool overflowbit2(unsigned int a, unsigned int b)
   {
       const unsigned int sum = a + b;
       return ~(a ^ b) & sum & 0x80;
   }

?

I thinnnnk it has the same results as your function...
[I just made a table of all 8 possibilities, and checked!]

-miles

-- 
Circus, n. A place where horses, ponies and elephants are permitted to see
men, women and children acting the fool.


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