Darwinbots Forum

Code center => Bugs and fixes => Bug reports => Topic started by: Sprotiel on January 27, 2007, 03:21:58 PM

Title: Bitwise shift operators are incorrect
Post by: Sprotiel on January 27, 2007, 03:21:58 PM
The way bitwise shift operators are implemented doesn't make any sense whenever one or both the operands are negative. There are several different ways of defining bit-shift operators, but I'll assume the one we want is the arithmetic shift (http://en.wikipedia.org/wiki/Arithmetic_shift). Shifts with negative offsets are usually errors, but we should probably take it to mean a shift in the reverse direction, with an offset equal to the absolute value of the offset specified.

Now, here are the results of some bitshift operations in 2.43:
-4 1 >> is 0, but should be -2
-4 1 << is 2, but should be -8
-4 -1 >> is -1, but should probably be -8
-4 -1 << is -2, but should probably be -2