docs: Mention explicitly that bitwise operators do not perform overflow/underflow checks

This commit is contained in:
Kamil Śliwak 2021-03-25 17:54:43 +01:00
parent a7e2a8acb2
commit 93bfc76216

View File

@ -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 It is not possible to disable the check for division by zero
or modulo by zero using the ``unchecked`` block. 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:: .. note::
The second statement in ``int x = type(int).min; -x;`` will result in an overflow 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. because the negative range can hold one more value than the positive range.