In your shiftRight function, you are trying to perform a right bit shift for both positive and negative integers. However, the logic used for negative numbers is mathematically incorrect.
if @x >= 0
set @y = CAST(@x / @pow AS INT)
else
set @y = CAST(~@x / @pow AS INT)
For negative numbers, you are shifting by using ~@x, which is a bitwise NOT, not a signed right shift. This does not produce the correct result that a normal arithmetic shift would produce. The right shift for negatives should preserve the sign bit, but your version instead inverts and divides, creating incorrect decoded coordinates.
In your shiftRight function, you are trying to perform a right bit shift for both positive and negative integers. However, the logic used for negative numbers is mathematically incorrect.
For negative numbers, you are shifting by using ~@x, which is a bitwise NOT, not a signed right shift. This does not produce the correct result that a normal arithmetic shift would produce. The right shift for negatives should preserve the sign bit, but your version instead inverts and divides, creating incorrect decoded coordinates.