Merge pull request #5087 from ethereum/semantics4

[DOCS] Semantics of negation.
This commit is contained in:
Alex Beregszaszi 2018-09-26 22:29:11 +01:00 committed by GitHub
commit 9508406984
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -82,10 +82,23 @@ Addition, Subtraction and Multiplication
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Addition, subtraction and multiplication have the usual semantics. Addition, subtraction and multiplication have the usual semantics.
They wrap in two's complement notation, meaning that They wrap in two's complement representation, meaning that
for example ``uint256(0) - uint256(1) == 2**256 - 1``. You have to take these overflows for example ``uint256(0) - uint256(1) == 2**256 - 1``. You have to take these overflows
into account when designing safe smart contracts. into account when designing safe smart contracts.
The expression ``-x`` is equivalent to ``(T(0) - x)`` where
``T`` is the type of ``x``. This means that ``-x`` will not be negative
if the type of ``x`` is an unsigned integer type. Also, ``-x`` can be
positive if ``x`` is negative. There is another caveat also resulting
from two's complement representation::
int x = -2**255;
assert(-x == x);
This means that even if a number is negative, you cannot assume that
its negation will be positive.
Division Division
^^^^^^^^ ^^^^^^^^