Author Topic: Bitwise shift operators are incorrect  (Read 2347 times)

Offline Sprotiel

  • Bot Destroyer
  • ***
  • Posts: 135
    • View Profile
Bitwise shift operators are incorrect
« 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. 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