[ub] Signed shifting

John Spicer jhs at edg.com
Mon Nov 17 22:58:31 CET 2014


On Nov 17, 2014, at 4:31 PM, Jens Maurer <Jens.Maurer at gmx.net> wrote:

> On 11/17/2014 10:03 PM, John Spicer wrote:
>> 
>> On Nov 17, 2014, at 3:57 PM, Gabriel Dos Reis <gdr at microsoft.com <mailto:gdr at microsoft.com>> wrote:
>> 
>>> Agreed, and that is the easier part :-)
>>> 
>>> I’m trying to find a middle-ground for people to get certainty (the implementation will tell you programmatically what the encoding is), while removing or reducing the surface area of undefined behavior.  My suspicion is that we will end up with 2’s complement for most cases.  But that is not based on a scientific study.
> 
>> We could define shifting of signed values to work as-if on a twos-complement system.
> 
> There are related core issues 1857, 1861, 1943.
> 
> In order to resolve some of these, I'm on the verge of specifying that
> shifts do multiplication / division by  2^N.
> 
> Assuming we make shifts for signed numbers well-defined, is the 2^N
> approach any different from specifying as-if two's complement?

I think they are equivalent for positive values.

For negative values, we can either keep it implementation-defined, or specify a behavior.

If we want to specify a behavior, the as-if twos-complement might be easier than the 2^N.

John.

> 
> (Yes, N < bit-width of type is a requirement.)
> 
> Jens
> _______________________________________________
> ub mailing list
> ub at isocpp.open-std.org
> http://www.open-std.org/mailman/listinfo/ub



More information about the ub mailing list