mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use proper SAR for signed right shifts and emulate on pre-constantinople.
This commit is contained in:
committed by
Alex Beregszaszi
parent
8999a2f375
commit
f33dc92cbd
+6
-7
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user