class_int.rst 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/int.xml.
  6. .. _class_int:
  7. int
  8. ===
  9. A built-in type for integers.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. Signed 64-bit integer type. This means that it can take values from ``-2^63`` to ``2^63 - 1``, i.e. from ``-9223372036854775808`` to ``9223372036854775807``. When it exceeds these bounds, it will wrap around.
  14. \ **int**\ s can be automatically converted to :ref:`float<class_float>`\ s when necessary, for example when passing them as arguments in functions. The :ref:`float<class_float>` will be as close to the original integer as possible.
  15. Likewise, :ref:`float<class_float>`\ s can be automatically converted into **int**\ s. This will truncate the :ref:`float<class_float>`, discarding anything after the floating-point.
  16. \ **Note:** In a boolean context, an **int** will evaluate to ``false`` if it equals ``0``, and to ``true`` otherwise.
  17. .. tabs::
  18. .. code-tab:: gdscript
  19. var x: int = 1 # x is 1
  20. x = 4.2 # x is 4, because 4.2 gets truncated
  21. var max_int = 9223372036854775807 # Biggest value an int can store
  22. max_int += 1 # max_int is -9223372036854775808, because it wrapped around
  23. .. code-tab:: csharp
  24. int x = 1; // x is 1
  25. x = (int)4.2; // x is 4, because 4.2 gets truncated
  26. // We use long below, because GDScript's int is 64-bit while C#'s int is 32-bit.
  27. long maxLong = 9223372036854775807; // Biggest value a long can store
  28. maxLong++; // maxLong is now -9223372036854775808, because it wrapped around.
  29. // Alternatively with C#'s 32-bit int type, which has a smaller maximum value.
  30. int maxInt = 2147483647; // Biggest value an int can store
  31. maxInt++; // maxInt is now -2147483648, because it wrapped around
  32. You can use the ``0b`` literal for binary representation, the ``0x`` literal for hexadecimal representation, and the ``_`` symbol to separate long numbers and improve readability.
  33. .. tabs::
  34. .. code-tab:: gdscript
  35. var x = 0b1001 # x is 9
  36. var y = 0xF5 # y is 245
  37. var z = 10_000_000 # z is 10000000
  38. .. code-tab:: csharp
  39. int x = 0b1001; // x is 9
  40. int y = 0xF5; // y is 245
  41. int z = 10_000_000; // z is 10000000
  42. .. rst-class:: classref-reftable-group
  43. Constructors
  44. ------------
  45. .. table::
  46. :widths: auto
  47. +-----------------------+---------------------------------------------------------------------------------+
  48. | :ref:`int<class_int>` | :ref:`int<class_int_constructor_int>`\ (\ ) |
  49. +-----------------------+---------------------------------------------------------------------------------+
  50. | :ref:`int<class_int>` | :ref:`int<class_int_constructor_int>`\ (\ from\: :ref:`int<class_int>`\ ) |
  51. +-----------------------+---------------------------------------------------------------------------------+
  52. | :ref:`int<class_int>` | :ref:`int<class_int_constructor_int>`\ (\ from\: :ref:`String<class_String>`\ ) |
  53. +-----------------------+---------------------------------------------------------------------------------+
  54. | :ref:`int<class_int>` | :ref:`int<class_int_constructor_int>`\ (\ from\: :ref:`bool<class_bool>`\ ) |
  55. +-----------------------+---------------------------------------------------------------------------------+
  56. | :ref:`int<class_int>` | :ref:`int<class_int_constructor_int>`\ (\ from\: :ref:`float<class_float>`\ ) |
  57. +-----------------------+---------------------------------------------------------------------------------+
  58. .. rst-class:: classref-reftable-group
  59. Operators
  60. ---------
  61. .. table::
  62. :widths: auto
  63. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  64. | :ref:`bool<class_bool>` | :ref:`operator !=<class_int_operator_neq_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
  65. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  66. | :ref:`bool<class_bool>` | :ref:`operator !=<class_int_operator_neq_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  67. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  68. | :ref:`int<class_int>` | :ref:`operator %<class_int_operator_mod_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  69. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  70. | :ref:`int<class_int>` | :ref:`operator &<class_int_operator_bwand_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  71. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  72. | :ref:`Color<class_Color>` | :ref:`operator *<class_int_operator_mul_Color>`\ (\ right\: :ref:`Color<class_Color>`\ ) |
  73. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  74. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator *<class_int_operator_mul_Quaternion>`\ (\ right\: :ref:`Quaternion<class_Quaternion>`\ ) |
  75. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  76. | :ref:`Vector2<class_Vector2>` | :ref:`operator *<class_int_operator_mul_Vector2>`\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) |
  77. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  78. | :ref:`Vector2i<class_Vector2i>` | :ref:`operator *<class_int_operator_mul_Vector2i>`\ (\ right\: :ref:`Vector2i<class_Vector2i>`\ ) |
  79. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  80. | :ref:`Vector3<class_Vector3>` | :ref:`operator *<class_int_operator_mul_Vector3>`\ (\ right\: :ref:`Vector3<class_Vector3>`\ ) |
  81. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  82. | :ref:`Vector3i<class_Vector3i>` | :ref:`operator *<class_int_operator_mul_Vector3i>`\ (\ right\: :ref:`Vector3i<class_Vector3i>`\ ) |
  83. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  84. | :ref:`Vector4<class_Vector4>` | :ref:`operator *<class_int_operator_mul_Vector4>`\ (\ right\: :ref:`Vector4<class_Vector4>`\ ) |
  85. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  86. | :ref:`Vector4i<class_Vector4i>` | :ref:`operator *<class_int_operator_mul_Vector4i>`\ (\ right\: :ref:`Vector4i<class_Vector4i>`\ ) |
  87. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  88. | :ref:`float<class_float>` | :ref:`operator *<class_int_operator_mul_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
  89. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  90. | :ref:`int<class_int>` | :ref:`operator *<class_int_operator_mul_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  91. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  92. | :ref:`float<class_float>` | :ref:`operator **<class_int_operator_pow_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
  93. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  94. | :ref:`int<class_int>` | :ref:`operator **<class_int_operator_pow_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  95. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  96. | :ref:`float<class_float>` | :ref:`operator +<class_int_operator_sum_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
  97. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  98. | :ref:`int<class_int>` | :ref:`operator +<class_int_operator_sum_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  99. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  100. | :ref:`float<class_float>` | :ref:`operator -<class_int_operator_dif_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
  101. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  102. | :ref:`int<class_int>` | :ref:`operator -<class_int_operator_dif_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  103. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  104. | :ref:`float<class_float>` | :ref:`operator /<class_int_operator_div_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
  105. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  106. | :ref:`int<class_int>` | :ref:`operator /<class_int_operator_div_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  107. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  108. | :ref:`bool<class_bool>` | :ref:`operator \<<class_int_operator_lt_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
  109. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  110. | :ref:`bool<class_bool>` | :ref:`operator \<<class_int_operator_lt_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  111. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  112. | :ref:`int<class_int>` | :ref:`operator \<\<<class_int_operator_bwsl_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  113. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  114. | :ref:`bool<class_bool>` | :ref:`operator \<=<class_int_operator_lte_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
  115. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  116. | :ref:`bool<class_bool>` | :ref:`operator \<=<class_int_operator_lte_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  117. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  118. | :ref:`bool<class_bool>` | :ref:`operator ==<class_int_operator_eq_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
  119. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  120. | :ref:`bool<class_bool>` | :ref:`operator ==<class_int_operator_eq_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  121. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  122. | :ref:`bool<class_bool>` | :ref:`operator ><class_int_operator_gt_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
  123. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  124. | :ref:`bool<class_bool>` | :ref:`operator ><class_int_operator_gt_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  125. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  126. | :ref:`bool<class_bool>` | :ref:`operator >=<class_int_operator_gte_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
  127. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  128. | :ref:`bool<class_bool>` | :ref:`operator >=<class_int_operator_gte_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  129. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  130. | :ref:`int<class_int>` | :ref:`operator >><class_int_operator_bwsr_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  131. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  132. | :ref:`int<class_int>` | :ref:`operator ^<class_int_operator_bwxor_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  133. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  134. | :ref:`int<class_int>` | :ref:`operator unary+<class_int_operator_unplus>`\ (\ ) |
  135. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  136. | :ref:`int<class_int>` | :ref:`operator unary-<class_int_operator_unminus>`\ (\ ) |
  137. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  138. | :ref:`int<class_int>` | :ref:`operator |<class_int_operator_bwor_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
  139. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  140. | :ref:`int<class_int>` | :ref:`operator ~<class_int_operator_bwnot>`\ (\ ) |
  141. +-------------------------------------+---------------------------------------------------------------------------------------------------------+
  142. .. rst-class:: classref-section-separator
  143. ----
  144. .. rst-class:: classref-descriptions-group
  145. Constructor Descriptions
  146. ------------------------
  147. .. _class_int_constructor_int:
  148. .. rst-class:: classref-constructor
  149. :ref:`int<class_int>` **int**\ (\ ) :ref:`๐Ÿ”—<class_int_constructor_int>`
  150. Constructs an **int** set to ``0``.
  151. .. rst-class:: classref-item-separator
  152. ----
  153. .. rst-class:: classref-constructor
  154. :ref:`int<class_int>` **int**\ (\ from\: :ref:`int<class_int>`\ )
  155. Constructs an **int** as a copy of the given **int**.
  156. .. rst-class:: classref-item-separator
  157. ----
  158. .. rst-class:: classref-constructor
  159. :ref:`int<class_int>` **int**\ (\ from\: :ref:`String<class_String>`\ )
  160. Constructs a new **int** from a :ref:`String<class_String>`, following the same rules as :ref:`String.to_int<class_String_method_to_int>`.
  161. .. rst-class:: classref-item-separator
  162. ----
  163. .. rst-class:: classref-constructor
  164. :ref:`int<class_int>` **int**\ (\ from\: :ref:`bool<class_bool>`\ )
  165. Constructs a new **int** from a :ref:`bool<class_bool>`. ``true`` is converted to ``1`` and ``false`` is converted to ``0``.
  166. .. rst-class:: classref-item-separator
  167. ----
  168. .. rst-class:: classref-constructor
  169. :ref:`int<class_int>` **int**\ (\ from\: :ref:`float<class_float>`\ )
  170. Constructs a new **int** from a :ref:`float<class_float>`. This will truncate the :ref:`float<class_float>`, discarding anything after the floating point.
  171. .. rst-class:: classref-section-separator
  172. ----
  173. .. rst-class:: classref-descriptions-group
  174. Operator Descriptions
  175. ---------------------
  176. .. _class_int_operator_neq_float:
  177. .. rst-class:: classref-operator
  178. :ref:`bool<class_bool>` **operator !=**\ (\ right\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_int_operator_neq_float>`
  179. Returns ``true`` if the **int** is not equivalent to the :ref:`float<class_float>`.
  180. .. rst-class:: classref-item-separator
  181. ----
  182. .. _class_int_operator_neq_int:
  183. .. rst-class:: classref-operator
  184. :ref:`bool<class_bool>` **operator !=**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_neq_int>`
  185. Returns ``true`` if the **int**\ s are not equal.
  186. .. rst-class:: classref-item-separator
  187. ----
  188. .. _class_int_operator_mod_int:
  189. .. rst-class:: classref-operator
  190. :ref:`int<class_int>` **operator %**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_mod_int>`
  191. Returns the remainder after dividing two **int**\ s. Uses truncated division, which returns a negative number if the dividend is negative. If this is not desired, consider using :ref:`@GlobalScope.posmod<class_@GlobalScope_method_posmod>`.
  192. ::
  193. print(6 % 2) # Prints 0
  194. print(11 % 4) # Prints 3
  195. print(-5 % 3) # Prints -2
  196. .. rst-class:: classref-item-separator
  197. ----
  198. .. _class_int_operator_bwand_int:
  199. .. rst-class:: classref-operator
  200. :ref:`int<class_int>` **operator &**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_bwand_int>`
  201. Performs the bitwise ``AND`` operation.
  202. ::
  203. print(0b1100 & 0b1010) # Prints 8 (binary 1000)
  204. This is useful for retrieving binary flags from a variable.
  205. ::
  206. var flags = 0b101
  207. # Check if the first or second bit are enabled.
  208. if flags & 0b011:
  209. do_stuff() # This line will run.
  210. .. rst-class:: classref-item-separator
  211. ----
  212. .. _class_int_operator_mul_Color:
  213. .. rst-class:: classref-operator
  214. :ref:`Color<class_Color>` **operator ***\ (\ right\: :ref:`Color<class_Color>`\ ) :ref:`๐Ÿ”—<class_int_operator_mul_Color>`
  215. Multiplies each component of the :ref:`Color<class_Color>` by the **int**.
  216. .. rst-class:: classref-item-separator
  217. ----
  218. .. _class_int_operator_mul_Quaternion:
  219. .. rst-class:: classref-operator
  220. :ref:`Quaternion<class_Quaternion>` **operator ***\ (\ right\: :ref:`Quaternion<class_Quaternion>`\ ) :ref:`๐Ÿ”—<class_int_operator_mul_Quaternion>`
  221. Multiplies each component of the :ref:`Quaternion<class_Quaternion>` by the **int**. This operation is not meaningful on its own, but it can be used as a part of a larger expression.
  222. .. rst-class:: classref-item-separator
  223. ----
  224. .. _class_int_operator_mul_Vector2:
  225. .. rst-class:: classref-operator
  226. :ref:`Vector2<class_Vector2>` **operator ***\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) :ref:`๐Ÿ”—<class_int_operator_mul_Vector2>`
  227. Multiplies each component of the :ref:`Vector2<class_Vector2>` by the **int**.
  228. ::
  229. print(2 * Vector2(1, 4)) # Prints (2, 8)
  230. .. rst-class:: classref-item-separator
  231. ----
  232. .. _class_int_operator_mul_Vector2i:
  233. .. rst-class:: classref-operator
  234. :ref:`Vector2i<class_Vector2i>` **operator ***\ (\ right\: :ref:`Vector2i<class_Vector2i>`\ ) :ref:`๐Ÿ”—<class_int_operator_mul_Vector2i>`
  235. Multiplies each component of the :ref:`Vector2i<class_Vector2i>` by the **int**.
  236. .. rst-class:: classref-item-separator
  237. ----
  238. .. _class_int_operator_mul_Vector3:
  239. .. rst-class:: classref-operator
  240. :ref:`Vector3<class_Vector3>` **operator ***\ (\ right\: :ref:`Vector3<class_Vector3>`\ ) :ref:`๐Ÿ”—<class_int_operator_mul_Vector3>`
  241. Multiplies each component of the :ref:`Vector3<class_Vector3>` by the **int**.
  242. .. rst-class:: classref-item-separator
  243. ----
  244. .. _class_int_operator_mul_Vector3i:
  245. .. rst-class:: classref-operator
  246. :ref:`Vector3i<class_Vector3i>` **operator ***\ (\ right\: :ref:`Vector3i<class_Vector3i>`\ ) :ref:`๐Ÿ”—<class_int_operator_mul_Vector3i>`
  247. Multiplies each component of the :ref:`Vector3i<class_Vector3i>` by the **int**.
  248. .. rst-class:: classref-item-separator
  249. ----
  250. .. _class_int_operator_mul_Vector4:
  251. .. rst-class:: classref-operator
  252. :ref:`Vector4<class_Vector4>` **operator ***\ (\ right\: :ref:`Vector4<class_Vector4>`\ ) :ref:`๐Ÿ”—<class_int_operator_mul_Vector4>`
  253. Multiplies each component of the :ref:`Vector4<class_Vector4>` by the **int**.
  254. .. rst-class:: classref-item-separator
  255. ----
  256. .. _class_int_operator_mul_Vector4i:
  257. .. rst-class:: classref-operator
  258. :ref:`Vector4i<class_Vector4i>` **operator ***\ (\ right\: :ref:`Vector4i<class_Vector4i>`\ ) :ref:`๐Ÿ”—<class_int_operator_mul_Vector4i>`
  259. Multiplies each component of the :ref:`Vector4i<class_Vector4i>` by the **int**.
  260. .. rst-class:: classref-item-separator
  261. ----
  262. .. _class_int_operator_mul_float:
  263. .. rst-class:: classref-operator
  264. :ref:`float<class_float>` **operator ***\ (\ right\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_int_operator_mul_float>`
  265. Multiplies the :ref:`float<class_float>` by the **int**. The result is a :ref:`float<class_float>`.
  266. .. rst-class:: classref-item-separator
  267. ----
  268. .. _class_int_operator_mul_int:
  269. .. rst-class:: classref-operator
  270. :ref:`int<class_int>` **operator ***\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_mul_int>`
  271. Multiplies the two **int**\ s.
  272. .. rst-class:: classref-item-separator
  273. ----
  274. .. _class_int_operator_pow_float:
  275. .. rst-class:: classref-operator
  276. :ref:`float<class_float>` **operator ****\ (\ right\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_int_operator_pow_float>`
  277. Raises an **int** to a power of a :ref:`float<class_float>`. The result is a :ref:`float<class_float>`.
  278. ::
  279. print(2 ** 0.5) # Prints 1.4142135623731
  280. .. rst-class:: classref-item-separator
  281. ----
  282. .. _class_int_operator_pow_int:
  283. .. rst-class:: classref-operator
  284. :ref:`int<class_int>` **operator ****\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_pow_int>`
  285. Raises the left **int** to a power of the right **int**.
  286. ::
  287. print(3 ** 4) # Prints 81
  288. .. rst-class:: classref-item-separator
  289. ----
  290. .. _class_int_operator_sum_float:
  291. .. rst-class:: classref-operator
  292. :ref:`float<class_float>` **operator +**\ (\ right\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_int_operator_sum_float>`
  293. Adds the **int** and the :ref:`float<class_float>`. The result is a :ref:`float<class_float>`.
  294. .. rst-class:: classref-item-separator
  295. ----
  296. .. _class_int_operator_sum_int:
  297. .. rst-class:: classref-operator
  298. :ref:`int<class_int>` **operator +**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_sum_int>`
  299. Adds the two **int**\ s.
  300. .. rst-class:: classref-item-separator
  301. ----
  302. .. _class_int_operator_dif_float:
  303. .. rst-class:: classref-operator
  304. :ref:`float<class_float>` **operator -**\ (\ right\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_int_operator_dif_float>`
  305. Subtracts the :ref:`float<class_float>` from the **int**. The result is a :ref:`float<class_float>`.
  306. .. rst-class:: classref-item-separator
  307. ----
  308. .. _class_int_operator_dif_int:
  309. .. rst-class:: classref-operator
  310. :ref:`int<class_int>` **operator -**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_dif_int>`
  311. Subtracts the two **int**\ s.
  312. .. rst-class:: classref-item-separator
  313. ----
  314. .. _class_int_operator_div_float:
  315. .. rst-class:: classref-operator
  316. :ref:`float<class_float>` **operator /**\ (\ right\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_int_operator_div_float>`
  317. Divides the **int** by the :ref:`float<class_float>`. The result is a :ref:`float<class_float>`.
  318. ::
  319. print(10 / 3.0) # Prints 3.33333333333333
  320. .. rst-class:: classref-item-separator
  321. ----
  322. .. _class_int_operator_div_int:
  323. .. rst-class:: classref-operator
  324. :ref:`int<class_int>` **operator /**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_div_int>`
  325. Divides the two **int**\ s. The result is an **int**. This will truncate the :ref:`float<class_float>`, discarding anything after the floating point.
  326. ::
  327. print(6 / 2) # Prints 3
  328. print(5 / 3) # Prints 1
  329. .. rst-class:: classref-item-separator
  330. ----
  331. .. _class_int_operator_lt_float:
  332. .. rst-class:: classref-operator
  333. :ref:`bool<class_bool>` **operator <**\ (\ right\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_int_operator_lt_float>`
  334. Returns ``true`` if the **int** is less than the :ref:`float<class_float>`.
  335. .. rst-class:: classref-item-separator
  336. ----
  337. .. _class_int_operator_lt_int:
  338. .. rst-class:: classref-operator
  339. :ref:`bool<class_bool>` **operator <**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_lt_int>`
  340. Returns ``true`` if the left **int** is less than the right **int**.
  341. .. rst-class:: classref-item-separator
  342. ----
  343. .. _class_int_operator_bwsl_int:
  344. .. rst-class:: classref-operator
  345. :ref:`int<class_int>` **operator <<**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_bwsl_int>`
  346. Performs the bitwise shift left operation. Effectively the same as multiplying by a power of 2.
  347. ::
  348. print(0b1010 << 1) # Prints 20 (binary 10100)
  349. print(0b1010 << 3) # Prints 80 (binary 1010000)
  350. .. rst-class:: classref-item-separator
  351. ----
  352. .. _class_int_operator_lte_float:
  353. .. rst-class:: classref-operator
  354. :ref:`bool<class_bool>` **operator <=**\ (\ right\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_int_operator_lte_float>`
  355. Returns ``true`` if the **int** is less than or equal to the :ref:`float<class_float>`.
  356. .. rst-class:: classref-item-separator
  357. ----
  358. .. _class_int_operator_lte_int:
  359. .. rst-class:: classref-operator
  360. :ref:`bool<class_bool>` **operator <=**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_lte_int>`
  361. Returns ``true`` if the left **int** is less than or equal to the right **int**.
  362. .. rst-class:: classref-item-separator
  363. ----
  364. .. _class_int_operator_eq_float:
  365. .. rst-class:: classref-operator
  366. :ref:`bool<class_bool>` **operator ==**\ (\ right\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_int_operator_eq_float>`
  367. Returns ``true`` if the **int** is equal to the :ref:`float<class_float>`.
  368. .. rst-class:: classref-item-separator
  369. ----
  370. .. _class_int_operator_eq_int:
  371. .. rst-class:: classref-operator
  372. :ref:`bool<class_bool>` **operator ==**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_eq_int>`
  373. Returns ``true`` if the two **int**\ s are equal.
  374. .. rst-class:: classref-item-separator
  375. ----
  376. .. _class_int_operator_gt_float:
  377. .. rst-class:: classref-operator
  378. :ref:`bool<class_bool>` **operator >**\ (\ right\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_int_operator_gt_float>`
  379. Returns ``true`` if the **int** is greater than the :ref:`float<class_float>`.
  380. .. rst-class:: classref-item-separator
  381. ----
  382. .. _class_int_operator_gt_int:
  383. .. rst-class:: classref-operator
  384. :ref:`bool<class_bool>` **operator >**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_gt_int>`
  385. Returns ``true`` if the left **int** is greater than the right **int**.
  386. .. rst-class:: classref-item-separator
  387. ----
  388. .. _class_int_operator_gte_float:
  389. .. rst-class:: classref-operator
  390. :ref:`bool<class_bool>` **operator >=**\ (\ right\: :ref:`float<class_float>`\ ) :ref:`๐Ÿ”—<class_int_operator_gte_float>`
  391. Returns ``true`` if the **int** is greater than or equal to the :ref:`float<class_float>`.
  392. .. rst-class:: classref-item-separator
  393. ----
  394. .. _class_int_operator_gte_int:
  395. .. rst-class:: classref-operator
  396. :ref:`bool<class_bool>` **operator >=**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_gte_int>`
  397. Returns ``true`` if the left **int** is greater than or equal to the right **int**.
  398. .. rst-class:: classref-item-separator
  399. ----
  400. .. _class_int_operator_bwsr_int:
  401. .. rst-class:: classref-operator
  402. :ref:`int<class_int>` **operator >>**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_bwsr_int>`
  403. Performs the bitwise shift right operation. Effectively the same as dividing by a power of 2.
  404. ::
  405. print(0b1010 >> 1) # Prints 5 (binary 101)
  406. print(0b1010 >> 2) # Prints 2 (binary 10)
  407. .. rst-class:: classref-item-separator
  408. ----
  409. .. _class_int_operator_bwxor_int:
  410. .. rst-class:: classref-operator
  411. :ref:`int<class_int>` **operator ^**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_bwxor_int>`
  412. Performs the bitwise ``XOR`` operation.
  413. ::
  414. print(0b1100 ^ 0b1010) # Prints 6 (binary 110)
  415. .. rst-class:: classref-item-separator
  416. ----
  417. .. _class_int_operator_unplus:
  418. .. rst-class:: classref-operator
  419. :ref:`int<class_int>` **operator unary+**\ (\ ) :ref:`๐Ÿ”—<class_int_operator_unplus>`
  420. Returns the same value as if the ``+`` was not there. Unary ``+`` does nothing, but sometimes it can make your code more readable.
  421. .. rst-class:: classref-item-separator
  422. ----
  423. .. _class_int_operator_unminus:
  424. .. rst-class:: classref-operator
  425. :ref:`int<class_int>` **operator unary-**\ (\ ) :ref:`๐Ÿ”—<class_int_operator_unminus>`
  426. Returns the negated value of the **int**. If positive, turns the number negative. If negative, turns the number positive. If zero, does nothing.
  427. .. rst-class:: classref-item-separator
  428. ----
  429. .. _class_int_operator_bwor_int:
  430. .. rst-class:: classref-operator
  431. :ref:`int<class_int>` **operator |**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`๐Ÿ”—<class_int_operator_bwor_int>`
  432. Performs the bitwise ``OR`` operation.
  433. ::
  434. print(0b1100 | 0b1010) # Prints 14 (binary 1110)
  435. This is useful for storing binary flags in a variable.
  436. ::
  437. var flags = 0
  438. flags |= 0b101 # Turn the first and third bits on.
  439. .. rst-class:: classref-item-separator
  440. ----
  441. .. _class_int_operator_bwnot:
  442. .. rst-class:: classref-operator
  443. :ref:`int<class_int>` **operator ~**\ (\ ) :ref:`๐Ÿ”—<class_int_operator_bwnot>`
  444. Performs the bitwise ``NOT`` operation on the **int**. Due to `2's complement <https://en.wikipedia.org/wiki/Two%27s_complement>`__, it's effectively equal to ``-(int + 1)``.
  445. ::
  446. print(~4) # Prints -5
  447. print(~(-7)) # Prints 6
  448. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  449. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  450. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  451. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  452. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  453. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  454. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  455. .. |void| replace:: :abbr:`void (No return value.)`