This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: portable signed right shift
- To: crosby at qwes dot math dot cmu dot edu, tm2 at best dot com
- Subject: Re: portable signed right shift
- From: dewar at gnat dot com
- Date: Tue, 27 Mar 2001 21:51:31 -0500 (EST)
- Cc: gcc at gcc dot gnu dot org, nbecker at fred dot net
<<y = x / (1<< N)
And trust the compiler to optimize it into a right-shift if that's
appropriate for the architecture?
>>
Well in twos complement, that is not most peoples definition of a shift right
for example,
Consider that -5 = 11111111111111011
And -4 = 11111111111111100
and -2 = 11111111111111110
the result to most people of -5/2 = -2 would not seem like a shift :-)
Of course there is no clear definition of what a right shift of a signed
quantity means in the first place, and the original author did not give
us a definition, so in a sense your definition is as good as another :-)