From b8e65373cd6f8844a864a71417e5b826ed57365f Mon Sep 17 00:00:00 2001 From: lena <77104725+elenakrittik@users.noreply.github.com> Date: Sat, 6 Apr 2024 20:28:25 +0300 Subject: [PATCH] docs: Clarify associativity of operators. (#9170) * docs: Clarify associativity of operators. (cherry picked from commit 2925c833906c19204aea70f91841b17cbd2f2585) --- tutorials/scripting/gdscript/gdscript_basics.rst | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index a3a911ba64e..8b1e0ab4b6a 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -224,7 +224,9 @@ in case you want to take a look under the hood. Operators ~~~~~~~~~ -The following is the list of supported operators and their precedence. +The following is the list of supported operators and their precedence. All binary operators are `left-associative `_, +including the ``**`` operator. This means that ``2 ** 2 ** 3`` is equal to ``(2 ** 2) ** 3``. Use parentheses to explicitly specify precedence you need, for +example ``2 ** (2 ** 3)``. The ternary ``if/else`` operator is right-associative. +---------------------------------------+-----------------------------------------------------------------------------+ | **Operator** | **Description** | @@ -251,10 +253,6 @@ The following is the list of supported operators and their precedence. | | | | | Multiplies ``x`` by itself ``y`` times, similar to calling | | | :ref:`pow() ` function. | -| | | -| | **Note:** In GDScript, the ``**`` operator is | -| | `left-associative `_. | -| | See a detailed note after the table. | +---------------------------------------+-----------------------------------------------------------------------------+ | ``~x`` | Bitwise NOT | +---------------------------------------+-----------------------------------------------------------------------------+ @@ -330,9 +328,7 @@ The following is the list of supported operators and their precedence. 3. For negative values, the ``%`` operator and ``fmod()`` use `truncation `_ instead of rounding towards negative infinity. This means that the remainder has a sign. If you need the remainder in a mathematical sense, use the :ref:`posmod() ` and :ref:`fposmod() ` functions instead. - 4. The ``**`` operator is `left-associative `_. This means that ``2 ** 2 ** 3`` is equal to ``(2 ** 2) ** 3``. - Use parentheses to explicitly specify precedence you need, for example ``2 ** (2 ** 3)``. - 5. The ``==`` and ``!=`` operators sometimes allow you to compare values of different types (for example, ``1 == 1.0`` is true), but in other cases it can cause + 4. The ``==`` and ``!=`` operators sometimes allow you to compare values of different types (for example, ``1 == 1.0`` is true), but in other cases it can cause a runtime error. If you're not sure about the types of the operands, you can safely use the :ref:`is_same() ` function (but note that it is more strict about types and references). To compare floats, use the :ref:`is_equal_approx() ` and :ref:`is_zero_approx() ` functions instead.