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]

Re: portable signed right shift


On Tue, 27 Mar 2001 dewar@gnat.com wrote:

> <<Sorry, I meant right shift of 2's complement signed number.
> >>
> 
> I know, and that was my example
> 
> -5 = 11111111111111011
> 
> -2 = 11111111111111110
> 
> Most people would expect either
>      11111111111111101 (if sign extension)
>      01111111111111101 (if no sign extension)
> 
> and the divide will typically give
> 
>      11111111111111110
> 

Ah... I wasn't thinking of this... I guess it's sorta of an issue as to
what you intend when dividing? Round-to-negative, or round-to-zero.

If you use division, you get the effect of round-to-zero.

Your other example of a sign-extending shift to the right is an example of
round-to-negative.

I guess it depends on what semantics you want.

Scott.



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