From 091abcea8cbe42d0e3082d276b8ffae99c745e24 Mon Sep 17 00:00:00 2001 From: Harikrishnan Mulackal Date: Mon, 11 May 2020 16:19:55 +0530 Subject: [PATCH] Updated docs for type(X).min and type(X).max --- docs/cheatsheet.rst | 2 ++ docs/types/value-types.rst | 3 +++ docs/units-and-global-variables.rst | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/cheatsheet.rst b/docs/cheatsheet.rst index 5d6169a48..e8ecb0af6 100644 --- a/docs/cheatsheet.rst +++ b/docs/cheatsheet.rst @@ -122,6 +122,8 @@ Global Variables - ``type(C).creationCode`` (``bytes memory``): creation bytecode of the given contract, see :ref:`Type Information`. - ``type(C).runtimeCode`` (``bytes memory``): runtime bytecode of the given contract, see :ref:`Type Information`. - ``type(I).interfaceId`` (``bytes4``): value containing the EIP-165 interface identifier of the given interface, see :ref:`Type Information`. +- ``type(X).min`` (``X``): the minimum value representable by the integer type ``X``, see :ref:`Type Information`. +- ``type(X).max`` (``X``): the maximum value representable by the integer type ``X``, see :ref:`Type Information`. .. note:: Do not rely on ``block.timestamp``, ``now`` and ``blockhash`` as a source of randomness, diff --git a/docs/types/value-types.rst b/docs/types/value-types.rst index 0301a8ad5..65cbd5504 100644 --- a/docs/types/value-types.rst +++ b/docs/types/value-types.rst @@ -40,6 +40,9 @@ Operators: * Shift operators: ``<<`` (left shift), ``>>`` (right shift) * Arithmetic operators: ``+``, ``-``, unary ``-``, ``*``, ``/``, ``%`` (modulo), ``**`` (exponentiation) +For an integer type ``X``, you can use ``type(X).min`` and ``type(X).max`` to +access the minimum and maximum value representable by the type. + .. warning:: Integers in Solidity are restricted to a certain range. For example, with ``uint32``, this is ``0`` up to ``2**32 - 1``. diff --git a/docs/units-and-global-variables.rst b/docs/units-and-global-variables.rst index 54eed07a9..22c6fc12d 100644 --- a/docs/units-and-global-variables.rst +++ b/docs/units-and-global-variables.rst @@ -294,10 +294,11 @@ Furthermore, all functions of the current contract are callable directly includi Type Information ---------------- -The expression ``type(X)`` can be used to retrieve information about the -type ``X``. Currently, there is limited support for this feature, but -it might be expanded in the future. The following properties are -available for a contract type ``C``: +The expression ``type(X)`` can be used to retrieve information about the type +``X``. Currently, there is limited support for this feature (``X`` can be either +a contract or an integer type) but it might be expanded in the future. + +The following properties are available for a contract type ``C``: ``type(C).name`` The name of the contract. @@ -328,3 +329,10 @@ for an interface type ``I``: interface identifier of the given interface ``I``. This identifier is defined as the ``XOR`` of all function selectors defined within the interface itself - excluding all inherited functions. +The following properties are available for an integer type ``I``: + +``type(I).min`` + The smallest value representable by type ``I``. + +``type(I).max`` + The largest value representable by type ``I``.