class_int.rst 29 KB

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