Two Birds with One Stone

Chris Thomson cmt at myrias.UUCP
Wed Dec 25 11:22:24 AEST 1985

> >Almost but not quite true. A compiler CANNOT normally replace a divide
> >by a right-shift if it is an integer divide. This is because a right
> >shift of a negative integer is not the same as a divide.
> However most useable processors provide arithmetic shifts which will give
> the right result even if it is a signed divide.

The first is correct, the second is WRONG.  -1/2 is 0 not -1.

More information about the Comp.lang.c mailing list