diff --git a/docs/types/value-types.rst b/docs/types/value-types.rst index ac20b49a3..9c082f9b4 100644 --- a/docs/types/value-types.rst +++ b/docs/types/value-types.rst @@ -59,15 +59,16 @@ This means that, for example ``~int256(0) == int256(-1)``. Shifts ^^^^^^ -The result of a shift operation has the type of the left operand. The -expression ``x << y`` is equivalent to ``x * 2**y``, and, for positive integers, -``x >> y`` is equivalent to ``x / 2**y``. For negative ``x``, ``x >> y`` -is equivalent to dividing by a power of ``2`` while rounding down (towards negative infinity). -Shifting by a negative amount throws a runtime exception. +The result of a shift operation has the type of the left operand, truncating the result to match the type. + +- For positive and negative ``x`` values, ``x << y`` is equivalent to ``x * 2**y``. +- For positive ``x`` values, ``x >> y`` is equivalent to ``x / 2**y``. +- For negative ``x`` values, ``x >> y`` is equivalent to ``(x + 1) / 2**y - 1`` (which is the same as dividing ``x`` by ``2**y`` while rounding down towards negative infinity). +- In all cases, shifting by a negative ``y`` throws a runtime exception. .. warning:: Before version ``0.5.0`` a right shift ``x >> y`` for negative ``x`` was equivalent to ``x / 2**y``, - i.e. right shifts used rounding towards zero instead of rounding towards negative infinity. + i.e., right shifts used rounding up (towards zero) instead of rounding down (towards negative infinity). Addition, Subtraction and Multiplication ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^