mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
docs: Mention explicitly that bitwise operators do not perform overflow/underflow checks
This commit is contained in:
parent
a7e2a8acb2
commit
93bfc76216
@ -531,6 +531,12 @@ and will wrap without an error if used inside an unchecked block:
|
||||
It is not possible to disable the check for division by zero
|
||||
or modulo by zero using the ``unchecked`` block.
|
||||
|
||||
.. note::
|
||||
Bitwise operators do not perform overflow or underflow checks.
|
||||
This is particularly visible when using bitwise shifts (``<<``, ``>>``, ``<<=``, ``>>=``) in
|
||||
place of integer division and multiplication by a power of 2.
|
||||
For example ``type(uint256).max << 3`` does not revert even though ``type(uint256).max * 8`` would.
|
||||
|
||||
.. note::
|
||||
The second statement in ``int x = type(int).min; -x;`` will result in an overflow
|
||||
because the negative range can hold one more value than the positive range.
|
||||
|
Loading…
Reference in New Issue
Block a user