mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-04 14:11:02 +03:00
778 lines
29 KiB
ReStructuredText
778 lines
29 KiB
ReStructuredText
:github_url: hide
|
|
|
|
.. DO NOT EDIT THIS FILE!!!
|
|
.. Generated automatically from Godot engine sources.
|
|
.. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
|
|
.. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/int.xml.
|
|
|
|
.. _class_int:
|
|
|
|
int
|
|
===
|
|
|
|
Integer built-in type.
|
|
|
|
.. rst-class:: classref-introduction-group
|
|
|
|
Description
|
|
-----------
|
|
|
|
Signed 64-bit integer type.
|
|
|
|
It can take values in the interval ``[-2^63, 2^63 - 1]``, i.e. ``[-9223372036854775808, 9223372036854775807]``. Exceeding those bounds will wrap around.
|
|
|
|
\ **int** is a :ref:`Variant<class_Variant>` type, and will thus be used when assigning an integer value to a :ref:`Variant<class_Variant>`. It can also be enforced with the ``: int`` type hint.
|
|
|
|
|
|
.. tabs::
|
|
|
|
.. code-tab:: gdscript
|
|
|
|
var my_variant = 0 # int, value 0.
|
|
my_variant += 4.2 # float, value 4.2.
|
|
var my_int: int = 1 # int, value 1.
|
|
my_int = 4.2 # int, value 4, the right value is implicitly cast to int.
|
|
my_int = int("6.7") # int, value 6, the String is explicitly cast with int.
|
|
var max_int = 9223372036854775807
|
|
print(max_int) # 9223372036854775807, OK.
|
|
max_int += 1
|
|
print(max_int) # -9223372036854775808, we overflowed and wrapped around.
|
|
|
|
.. code-tab:: csharp
|
|
|
|
int myInt = (int)"6.7".ToFloat(); // int, value 6, the String is explicitly cast with int.
|
|
// We have to use `long` here, because GDSript's `int`
|
|
// is 64 bits long while C#'s `int` is only 32 bits.
|
|
long maxInt = 9223372036854775807;
|
|
GD.Print(maxInt); // 9223372036854775807, OK.
|
|
maxInt++;
|
|
GD.Print(maxInt); // -9223372036854775808, we overflowed and wrapped around.
|
|
|
|
// Alternatively, if we used C#'s 32-bit `int` type, the maximum value is much smaller:
|
|
int halfInt = 2147483647;
|
|
GD.Print(halfInt); // 2147483647, OK.
|
|
halfInt++;
|
|
GD.Print(halfInt); // -2147483648, we overflowed and wrapped around.
|
|
|
|
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
Constructors
|
|
------------
|
|
|
|
.. table::
|
|
:widths: auto
|
|
|
|
+-----------------------+------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`int<class_int_constructor_int>` **(** **)** |
|
|
+-----------------------+------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`int<class_int_constructor_int>` **(** :ref:`int<class_int>` from **)** |
|
|
+-----------------------+------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`int<class_int_constructor_int>` **(** :ref:`String<class_String>` from **)** |
|
|
+-----------------------+------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`int<class_int_constructor_int>` **(** :ref:`bool<class_bool>` from **)** |
|
|
+-----------------------+------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`int<class_int_constructor_int>` **(** :ref:`float<class_float>` from **)** |
|
|
+-----------------------+------------------------------------------------------------------------------------+
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
Operators
|
|
---------
|
|
|
|
.. table::
|
|
:widths: auto
|
|
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`operator !=<class_int_operator_neq_float>` **(** :ref:`float<class_float>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`operator !=<class_int_operator_neq_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`operator %<class_int_operator_mod_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`operator &<class_int_operator_bwand_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Color<class_Color>` | :ref:`operator *<class_int_operator_mul_Color>` **(** :ref:`Color<class_Color>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Quaternion<class_Quaternion>` | :ref:`operator *<class_int_operator_mul_Quaternion>` **(** :ref:`Quaternion<class_Quaternion>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Vector2<class_Vector2>` | :ref:`operator *<class_int_operator_mul_Vector2>` **(** :ref:`Vector2<class_Vector2>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Vector2i<class_Vector2i>` | :ref:`operator *<class_int_operator_mul_Vector2i>` **(** :ref:`Vector2i<class_Vector2i>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Vector3<class_Vector3>` | :ref:`operator *<class_int_operator_mul_Vector3>` **(** :ref:`Vector3<class_Vector3>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Vector3i<class_Vector3i>` | :ref:`operator *<class_int_operator_mul_Vector3i>` **(** :ref:`Vector3i<class_Vector3i>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Vector4<class_Vector4>` | :ref:`operator *<class_int_operator_mul_Vector4>` **(** :ref:`Vector4<class_Vector4>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`Vector4i<class_Vector4i>` | :ref:`operator *<class_int_operator_mul_Vector4i>` **(** :ref:`Vector4i<class_Vector4i>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`float<class_float>` | :ref:`operator *<class_int_operator_mul_float>` **(** :ref:`float<class_float>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`operator *<class_int_operator_mul_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`float<class_float>` | :ref:`operator **<class_int_operator_pow_float>` **(** :ref:`float<class_float>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`operator **<class_int_operator_pow_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`float<class_float>` | :ref:`operator +<class_int_operator_sum_float>` **(** :ref:`float<class_float>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`operator +<class_int_operator_sum_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`float<class_float>` | :ref:`operator -<class_int_operator_dif_float>` **(** :ref:`float<class_float>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`operator -<class_int_operator_dif_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`float<class_float>` | :ref:`operator /<class_int_operator_div_float>` **(** :ref:`float<class_float>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`operator /<class_int_operator_div_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`operator \<<class_int_operator_lt_float>` **(** :ref:`float<class_float>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`operator \<<class_int_operator_lt_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`operator \<\<<class_int_operator_bwsl_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`operator \<=<class_int_operator_lte_float>` **(** :ref:`float<class_float>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`operator \<=<class_int_operator_lte_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`operator ==<class_int_operator_eq_float>` **(** :ref:`float<class_float>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`operator ==<class_int_operator_eq_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`operator ><class_int_operator_gt_float>` **(** :ref:`float<class_float>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`operator ><class_int_operator_gt_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`operator >=<class_int_operator_gte_float>` **(** :ref:`float<class_float>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`operator >=<class_int_operator_gte_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`operator >><class_int_operator_bwsr_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`operator ^<class_int_operator_bwxor_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`operator unary+<class_int_operator_unplus>` **(** **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`operator unary-<class_int_operator_unminus>` **(** **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`operator |<class_int_operator_bwor_int>` **(** :ref:`int<class_int>` right **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`operator ~<class_int_operator_bwnot>` **(** **)** |
|
|
+-------------------------------------+------------------------------------------------------------------------------------------------------------+
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
Constructor Descriptions
|
|
------------------------
|
|
|
|
.. _class_int_constructor_int:
|
|
|
|
.. rst-class:: classref-constructor
|
|
|
|
:ref:`int<class_int>` **int** **(** **)**
|
|
|
|
Constructs a default-initialized **int** set to ``0``.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-constructor
|
|
|
|
:ref:`int<class_int>` **int** **(** :ref:`int<class_int>` from **)**
|
|
|
|
Constructs an **int** as a copy of the given **int**.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-constructor
|
|
|
|
:ref:`int<class_int>` **int** **(** :ref:`String<class_String>` from **)**
|
|
|
|
Converts a :ref:`String<class_String>` to an **int**, following the same rules as :ref:`String.to_int<class_String_method_to_int>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-constructor
|
|
|
|
:ref:`int<class_int>` **int** **(** :ref:`bool<class_bool>` from **)**
|
|
|
|
Cast a :ref:`bool<class_bool>` value to an integer value, ``int(true)`` will be equals to 1 and ``int(false)`` will be equals to 0.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-constructor
|
|
|
|
:ref:`int<class_int>` **int** **(** :ref:`float<class_float>` from **)**
|
|
|
|
Cast a float value to an integer value, this method simply removes the number fractions (i.e. rounds ``from`` towards zero), so for example ``int(2.7)`` will be equals to 2, ``int(0.1)`` will be equals to 0 and ``int(-2.7)`` will be equals to -2. This operation is also called truncation.
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
Operator Descriptions
|
|
---------------------
|
|
|
|
.. _class_int_operator_neq_float:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`bool<class_bool>` **operator !=** **(** :ref:`float<class_float>` right **)**
|
|
|
|
Returns ``true`` if this **int** is not equivalent to the given :ref:`float<class_float>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_neq_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`bool<class_bool>` **operator !=** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Returns ``true`` if the integers are not equal.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_mod_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`int<class_int>` **operator %** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Returns the remainder after dividing two integers. This operation uses truncated division, which is often not desired as it does not work well with negative numbers. Consider using :ref:`@GlobalScope.posmod<class_@GlobalScope_method_posmod>` instead if you want to handle negative numbers.
|
|
|
|
::
|
|
|
|
print(5 % 2) # 1
|
|
print(12 % 4) # 0
|
|
print(-5 % 3) # -2
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_bwand_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`int<class_int>` **operator &** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Returns the result of bitwise ``AND`` operation for two integers.
|
|
|
|
::
|
|
|
|
print(3 & 1) # 1
|
|
print(11 & 3) # 3
|
|
|
|
It's useful to retrieve binary flags from a variable.
|
|
|
|
::
|
|
|
|
var flags = 5
|
|
# Do something if the first bit is enabled.
|
|
if flags & 1:
|
|
do_stuff()
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_mul_Color:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`Color<class_Color>` **operator *** **(** :ref:`Color<class_Color>` right **)**
|
|
|
|
Multiplies each component of the :ref:`Color<class_Color>` by the given **int**.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_mul_Quaternion:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`Quaternion<class_Quaternion>` **operator *** **(** :ref:`Quaternion<class_Quaternion>` right **)**
|
|
|
|
Multiplies each component of the :ref:`Quaternion<class_Quaternion>` by the given **int**. This operation is not meaningful on its own, but it can be used as a part of a larger expression.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_mul_Vector2:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`Vector2<class_Vector2>` **operator *** **(** :ref:`Vector2<class_Vector2>` right **)**
|
|
|
|
Multiplies each component of the :ref:`Vector2<class_Vector2>` by the given **int**.
|
|
|
|
::
|
|
|
|
print(2 * Vector2(1, 1)) # Vector2(2, 2)
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_mul_Vector2i:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`Vector2i<class_Vector2i>` **operator *** **(** :ref:`Vector2i<class_Vector2i>` right **)**
|
|
|
|
Multiplies each component of the :ref:`Vector2i<class_Vector2i>` by the given **int**.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_mul_Vector3:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`Vector3<class_Vector3>` **operator *** **(** :ref:`Vector3<class_Vector3>` right **)**
|
|
|
|
Multiplies each component of the :ref:`Vector3<class_Vector3>` by the given **int**.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_mul_Vector3i:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`Vector3i<class_Vector3i>` **operator *** **(** :ref:`Vector3i<class_Vector3i>` right **)**
|
|
|
|
Multiplies each component of the :ref:`Vector3i<class_Vector3i>` by the given **int**.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_mul_Vector4:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`Vector4<class_Vector4>` **operator *** **(** :ref:`Vector4<class_Vector4>` right **)**
|
|
|
|
Multiplies each component of the :ref:`Vector4<class_Vector4>` by the given **int**.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_mul_Vector4i:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`Vector4i<class_Vector4i>` **operator *** **(** :ref:`Vector4i<class_Vector4i>` right **)**
|
|
|
|
Multiplies each component of the :ref:`Vector4i<class_Vector4i>` by the given **int**.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_mul_float:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`float<class_float>` **operator *** **(** :ref:`float<class_float>` right **)**
|
|
|
|
Multiplies an **int** and a :ref:`float<class_float>`. The result is a :ref:`float<class_float>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_mul_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`int<class_int>` **operator *** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Multiplies two **int**\ s.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_pow_float:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`float<class_float>` **operator **** **(** :ref:`float<class_float>` right **)**
|
|
|
|
Raises an **int** to a power of a :ref:`float<class_float>`. The result is a :ref:`float<class_float>`.
|
|
|
|
::
|
|
|
|
print(8**0.25) # 1.68179283050743
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_pow_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`int<class_int>` **operator **** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Raises an **int** to a power of a **int**.
|
|
|
|
::
|
|
|
|
print(5**5) # 3125
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_sum_float:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`float<class_float>` **operator +** **(** :ref:`float<class_float>` right **)**
|
|
|
|
Adds an **int** and a :ref:`float<class_float>`. The result is a :ref:`float<class_float>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_sum_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`int<class_int>` **operator +** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Adds two integers.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_dif_float:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`float<class_float>` **operator -** **(** :ref:`float<class_float>` right **)**
|
|
|
|
Subtracts a :ref:`float<class_float>` from an **int**. The result is a :ref:`float<class_float>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_dif_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`int<class_int>` **operator -** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Subtracts two integers.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_div_float:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`float<class_float>` **operator /** **(** :ref:`float<class_float>` right **)**
|
|
|
|
Divides an **int** by a :ref:`float<class_float>`. The result is a :ref:`float<class_float>`.
|
|
|
|
::
|
|
|
|
print(10 / 3.0) # 3.333...
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_div_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`int<class_int>` **operator /** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Divides two integers. The decimal part of the result is discarded (truncated).
|
|
|
|
::
|
|
|
|
print(10 / 2) # 5
|
|
print(10 / 3) # 3
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_lt_float:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`bool<class_bool>` **operator <** **(** :ref:`float<class_float>` right **)**
|
|
|
|
Returns ``true`` if this **int** is less than the given :ref:`float<class_float>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_lt_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`bool<class_bool>` **operator <** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Returns ``true`` if the left integer is less than the right one.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_bwsl_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`int<class_int>` **operator <<** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Performs bitwise shift left operation on the integer. Effectively the same as multiplying by a power of 2.
|
|
|
|
::
|
|
|
|
print(10 << 1) # 20
|
|
print(10 << 4) # 160
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_lte_float:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`bool<class_bool>` **operator <=** **(** :ref:`float<class_float>` right **)**
|
|
|
|
Returns ``true`` if this **int** is less than or equal to the given :ref:`float<class_float>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_lte_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`bool<class_bool>` **operator <=** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Returns ``true`` if the left integer is less than or equal to the right one.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_eq_float:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`bool<class_bool>` **operator ==** **(** :ref:`float<class_float>` right **)**
|
|
|
|
Returns ``true`` if the integer is equal to the given :ref:`float<class_float>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_eq_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`bool<class_bool>` **operator ==** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Returns ``true`` if both integers are equal.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_gt_float:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`bool<class_bool>` **operator >** **(** :ref:`float<class_float>` right **)**
|
|
|
|
Returns ``true`` if this **int** is greater than the given :ref:`float<class_float>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_gt_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`bool<class_bool>` **operator >** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Returns ``true`` if the left integer is greater than the right one.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_gte_float:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`bool<class_bool>` **operator >=** **(** :ref:`float<class_float>` right **)**
|
|
|
|
Returns ``true`` if this **int** is greater than or equal to the given :ref:`float<class_float>`.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_gte_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`bool<class_bool>` **operator >=** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Returns ``true`` if the left integer is greater than or equal to the right one.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_bwsr_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`int<class_int>` **operator >>** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Performs bitwise shift right operation on the integer. Effectively the same as dividing by a power of 2.
|
|
|
|
::
|
|
|
|
print(10 >> 1) # 5
|
|
print(10 >> 2) # 2
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_bwxor_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`int<class_int>` **operator ^** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Returns the result of bitwise ``XOR`` operation for two integers.
|
|
|
|
::
|
|
|
|
print(5 ^ 1) # 4
|
|
print(4 ^ 7) # 3
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_unplus:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`int<class_int>` **operator unary+** **(** **)**
|
|
|
|
Returns the same value as if the ``+`` was not there. Unary ``+`` does nothing, but sometimes it can make your code more readable.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_unminus:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`int<class_int>` **operator unary-** **(** **)**
|
|
|
|
Returns the negated value of the **int**. If positive, turns the number negative. If negative, turns the number positive. If zero, does nothing.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_bwor_int:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`int<class_int>` **operator |** **(** :ref:`int<class_int>` right **)**
|
|
|
|
Returns the result of bitwise ``OR`` operation for two integers.
|
|
|
|
::
|
|
|
|
print(2 | 4) # 6
|
|
print(1 | 3) # 3
|
|
|
|
It's useful to store binary flags in a variable.
|
|
|
|
::
|
|
|
|
var flags = 0
|
|
# Turn first and third bit on.
|
|
flags |= 1
|
|
flags |= 4
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_int_operator_bwnot:
|
|
|
|
.. rst-class:: classref-operator
|
|
|
|
:ref:`int<class_int>` **operator ~** **(** **)**
|
|
|
|
Returns the result of bitwise ``NOT`` operation for the integer. It's effectively equal to ``-int + 1``.
|
|
|
|
::
|
|
|
|
print(~4) # -3
|
|
print(~7) # -6
|
|
|
|
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
|
|
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
|
|
.. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
|
|
.. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
|
|
.. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
|
|
.. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
|