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


<<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 :-)


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