diff options
author | chriseth <c@ethdev.com> | 2016-12-10 03:18:37 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-12-12 18:12:12 +0800 |
commit | cc117399281361124714dfd0914fa92e6aec78ef (patch) | |
tree | 95cc64e2674f10d9550220083e9f5a55ed57a1d5 /docs/types.rst | |
parent | 2fac1d23a78d898ab78f1a8e347c40ae673c039c (diff) | |
download | dexon-solidity-cc117399281361124714dfd0914fa92e6aec78ef.tar.gz dexon-solidity-cc117399281361124714dfd0914fa92e6aec78ef.tar.zst dexon-solidity-cc117399281361124714dfd0914fa92e6aec78ef.zip |
Documentation.
Diffstat (limited to 'docs/types.rst')
-rw-r--r-- | docs/types.rst | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/docs/types.rst b/docs/types.rst index 896910ff..59b9771b 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -51,7 +51,7 @@ Integers Operators: * Comparisons: ``<=``, ``<``, ``==``, ``!=``, ``>=``, ``>`` (evaluate to ``bool``) -* Bit operators: ``&``, ``|``, ``^`` (bitwise exclusive or), ``~`` (bitwise negation) +* Bit operators: ``&``, ``|``, ``^`` (bitwise exclusive or), ``~`` (bitwise negation), ``<<`` (left shift), ``>>`` (right shift) * Arithmetic operators: ``+``, ``-``, unary ``-``, unary ``+``, ``*``, ``/``, ``%`` (remainder), ``**`` (exponentiation) Division always truncates (it just maps to the DIV opcode of the EVM), but it does not truncate if both @@ -59,6 +59,11 @@ operators are :ref:`literals<rational_literals>` (or literal expressions). Division by zero and modulus with zero throws an exception. +The result of a shift operation is the type of the left operand. The +expression ``x << y`` is equivalent to ``x * 2**y`` and ``x >> y`` is +equivalent to ``x / 2**y``. This means that shifting negative numbers +sign extends. Shifting by a negative amount throws an exception. + .. index:: address, balance, send, call, callcode, delegatecall .. _address: @@ -136,9 +141,13 @@ Fixed-size byte arrays Operators: * Comparisons: ``<=``, ``<``, ``==``, ``!=``, ``>=``, ``>`` (evaluate to ``bool``) -* Bit operators: ``&``, ``|``, ``^`` (bitwise exclusive or), ``~`` (bitwise negation) +* Bit operators: ``&``, ``|``, ``^`` (bitwise exclusive or), ``~`` (bitwise negation), ``<<`` (left shift), ``>>`` (right shift) * Index access: If ``x`` is of type ``bytesI``, then ``x[k]`` for ``0 <= k < I`` returns the ``k`` th byte (read-only). +The shifting operator wors with any integer type as right operand (bit will +return the type of the left operand). Shifting by a negative amount will cause +a runtime exception. + Members: * ``.length`` yields the fixed length of the byte array (read-only). |