diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2018-06-12 17:01:14 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-12 17:01:14 +0800 |
commit | ae2b5898503dd744c04ab605c479e1d2aa4e4d79 (patch) | |
tree | 2419d28fe6a58722007a56612b950397b8f2d64b /docs | |
parent | 8999a2f375410a29bae46b8e87a70c62036c880d (diff) | |
parent | e84b55bd6feded46789d2d398cd1b4092ef7a1c0 (diff) | |
download | dexon-solidity-ae2b5898503dd744c04ab605c479e1d2aa4e4d79.tar dexon-solidity-ae2b5898503dd744c04ab605c479e1d2aa4e4d79.tar.gz dexon-solidity-ae2b5898503dd744c04ab605c479e1d2aa4e4d79.tar.bz2 dexon-solidity-ae2b5898503dd744c04ab605c479e1d2aa4e4d79.tar.lz dexon-solidity-ae2b5898503dd744c04ab605c479e1d2aa4e4d79.tar.xz dexon-solidity-ae2b5898503dd744c04ab605c479e1d2aa4e4d79.tar.zst dexon-solidity-ae2b5898503dd744c04ab605c479e1d2aa4e4d79.zip |
Merge pull request #4084 from ethereum/signedRightShift
[BREAKING] Use proper SAR for signed right shifts and emulate on pre-constantinople.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/types.rst | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/docs/types.rst b/docs/types.rst index 08b74241..009896d5 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -60,15 +60,14 @@ operators are :ref:`literals<rational_literals>` (or literal expressions). Division by zero and modulus with zero throws a runtime exception. The result of a shift operation is the type of the left operand. The -expression ``x << y`` is equivalent to ``x * 2**y``, and ``x >> y`` is -equivalent to ``x / 2**y``. This means that shifting negative numbers -sign extends. Shifting by a negative amount throws a runtime exception. +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. .. warning:: - The results produced by shift right of negative values of signed integer types is different from those produced - by other programming languages. In Solidity, shift right maps to division so the shifted negative values - are going to be rounded towards zero (truncated). In other programming languages the shift right of negative values - works like division with rounding down (towards negative infinity). + 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. .. index:: ! ufixed, ! fixed, ! fixed point number |