aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-09-27 05:29:11 +0800
committerGitHub <noreply@github.com>2018-09-27 05:29:11 +0800
commit9508406984c1e83e6ce571af4af593c33aed52e6 (patch)
tree30dcdc60ebe64b80f73311c724191969c0d532f2 /docs
parentd51d4def9e53422cc8ed08bc3fb01c3a4ab82ab9 (diff)
parent7d1c428838baf47540b87f2e2259012fe1321f23 (diff)
downloaddexon-solidity-9508406984c1e83e6ce571af4af593c33aed52e6.tar.gz
dexon-solidity-9508406984c1e83e6ce571af4af593c33aed52e6.tar.zst
dexon-solidity-9508406984c1e83e6ce571af4af593c33aed52e6.zip
Merge pull request #5087 from ethereum/semantics4
[DOCS] Semantics of negation.
Diffstat (limited to 'docs')
-rw-r--r--docs/types.rst15
1 files changed, 14 insertions, 1 deletions
diff --git a/docs/types.rst b/docs/types.rst
index 43291af8..03896a96 100644
--- a/docs/types.rst
+++ b/docs/types.rst
@@ -82,10 +82,23 @@ Addition, Subtraction and Multiplication
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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
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
^^^^^^^^