diff options
author | chriseth <chris@ethereum.org> | 2018-09-26 01:54:29 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-09-27 04:35:29 +0800 |
commit | 7d1c428838baf47540b87f2e2259012fe1321f23 (patch) | |
tree | a344e1f4d3a2e769173bf8159e56b357deeff0c6 | |
parent | f81c6e6d164d282f49d0c7d44729946b7da12181 (diff) | |
download | dexon-solidity-7d1c428838baf47540b87f2e2259012fe1321f23.tar dexon-solidity-7d1c428838baf47540b87f2e2259012fe1321f23.tar.gz dexon-solidity-7d1c428838baf47540b87f2e2259012fe1321f23.tar.bz2 dexon-solidity-7d1c428838baf47540b87f2e2259012fe1321f23.tar.lz dexon-solidity-7d1c428838baf47540b87f2e2259012fe1321f23.tar.xz dexon-solidity-7d1c428838baf47540b87f2e2259012fe1321f23.tar.zst dexon-solidity-7d1c428838baf47540b87f2e2259012fe1321f23.zip |
[DOCS] Semantics of negation.
-rw-r--r-- | docs/types.rst | 15 |
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 ^^^^^^^^ |