On Sun, 26 May 1996, Eric Smith wrote: > > numbers. To illustrate: what happens to -1 when you do this? > > It gets divided by two yielding -0.5. > In integer representation there is no 2**-1 bit, so division by right shift > truncates, effectively rounding down (toward negative infinity). > -0.5 rounds to -1. No. That is not truncation you're describing: what Clyde posted results in truncation (-1/2 truncated results in zero). > Your proposed alternate code simply biases the result for negative numbers > by 0.5, implementing round toward zero. It is not obvious to me that > round toward zero is more "correct". > > I would be inclined to prefer IEEE-style round to even. De gustibus non est disputandum, but having -1 / 2 give a result of -1 will be surprising to anyone who's accustomed to integer division as usually implented. > If you really care about what happens to the 0.5, you should probably be > using fixed-point representation. Of couse, this argues equally against either result. ;-)