class_int.rst 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  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. Integer built-in type.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. Signed 64-bit integer type.
  14. It can take values in the interval ``[-2^63, 2^63 - 1]``, i.e. ``[-9223372036854775808, 9223372036854775807]``. Exceeding those bounds will wrap around.
  15. \ **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.
  16. .. tabs::
  17. .. code-tab:: gdscript
  18. var my_variant = 0 # int, value 0.
  19. my_variant += 4.2 # float, value 4.2.
  20. var my_int: int = 1 # int, value 1.
  21. my_int = 4.2 # int, value 4, the right value is implicitly cast to int.
  22. my_int = int("6.7") # int, value 6, the String is explicitly cast with int.
  23. var max_int = 9223372036854775807
  24. print(max_int) # 9223372036854775807, OK.
  25. max_int += 1
  26. print(max_int) # -9223372036854775808, we overflowed and wrapped around.
  27. .. code-tab:: csharp
  28. int myInt = (int)"6.7".ToFloat(); // int, value 6, the String is explicitly cast with int.
  29. // We have to use `long` here, because GDSript's `int`
  30. // is 64 bits long while C#'s `int` is only 32 bits.
  31. long maxInt = 9223372036854775807;
  32. GD.Print(maxInt); // 9223372036854775807, OK.
  33. maxInt++;
  34. GD.Print(maxInt); // -9223372036854775808, we overflowed and wrapped around.
  35. // Alternatively, if we used C#'s 32-bit `int` type, the maximum value is much smaller:
  36. int halfInt = 2147483647;
  37. GD.Print(halfInt); // 2147483647, OK.
  38. halfInt++;
  39. GD.Print(halfInt); // -2147483648, we overflowed and wrapped around.
  40. .. rst-class:: classref-reftable-group
  41. Constructors
  42. ------------
  43. .. table::
  44. :widths: auto
  45. +-----------------------+------------------------------------------------------------------------------------+
  46. | :ref:`int<class_int>` | :ref:`int<class_int_constructor_int>` **(** **)** |
  47. +-----------------------+------------------------------------------------------------------------------------+
  48. | :ref:`int<class_int>` | :ref:`int<class_int_constructor_int>` **(** :ref:`int<class_int>` from **)** |
  49. +-----------------------+------------------------------------------------------------------------------------+
  50. | :ref:`int<class_int>` | :ref:`int<class_int_constructor_int>` **(** :ref:`String<class_String>` from **)** |
  51. +-----------------------+------------------------------------------------------------------------------------+
  52. | :ref:`int<class_int>` | :ref:`int<class_int_constructor_int>` **(** :ref:`bool<class_bool>` from **)** |
  53. +-----------------------+------------------------------------------------------------------------------------+
  54. | :ref:`int<class_int>` | :ref:`int<class_int_constructor_int>` **(** :ref:`float<class_float>` from **)** |
  55. +-----------------------+------------------------------------------------------------------------------------+
  56. .. rst-class:: classref-reftable-group
  57. Operators
  58. ---------
  59. .. table::
  60. :widths: auto
  61. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  62. | :ref:`bool<class_bool>` | :ref:`operator !=<class_int_operator_neq_float>` **(** :ref:`float<class_float>` right **)** |
  63. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  64. | :ref:`bool<class_bool>` | :ref:`operator !=<class_int_operator_neq_int>` **(** :ref:`int<class_int>` right **)** |
  65. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  66. | :ref:`int<class_int>` | :ref:`operator %<class_int_operator_mod_int>` **(** :ref:`int<class_int>` right **)** |
  67. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  68. | :ref:`int<class_int>` | :ref:`operator &<class_int_operator_bwand_int>` **(** :ref:`int<class_int>` right **)** |
  69. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Color<class_Color>` | :ref:`operator *<class_int_operator_mul_Color>` **(** :ref:`Color<class_Color>` right **)** |
  71. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  72. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator *<class_int_operator_mul_Quaternion>` **(** :ref:`Quaternion<class_Quaternion>` right **)** |
  73. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  74. | :ref:`Vector2<class_Vector2>` | :ref:`operator *<class_int_operator_mul_Vector2>` **(** :ref:`Vector2<class_Vector2>` right **)** |
  75. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  76. | :ref:`Vector2i<class_Vector2i>` | :ref:`operator *<class_int_operator_mul_Vector2i>` **(** :ref:`Vector2i<class_Vector2i>` right **)** |
  77. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  78. | :ref:`Vector3<class_Vector3>` | :ref:`operator *<class_int_operator_mul_Vector3>` **(** :ref:`Vector3<class_Vector3>` right **)** |
  79. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  80. | :ref:`Vector3i<class_Vector3i>` | :ref:`operator *<class_int_operator_mul_Vector3i>` **(** :ref:`Vector3i<class_Vector3i>` right **)** |
  81. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  82. | :ref:`Vector4<class_Vector4>` | :ref:`operator *<class_int_operator_mul_Vector4>` **(** :ref:`Vector4<class_Vector4>` right **)** |
  83. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  84. | :ref:`Vector4i<class_Vector4i>` | :ref:`operator *<class_int_operator_mul_Vector4i>` **(** :ref:`Vector4i<class_Vector4i>` right **)** |
  85. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  86. | :ref:`float<class_float>` | :ref:`operator *<class_int_operator_mul_float>` **(** :ref:`float<class_float>` right **)** |
  87. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  88. | :ref:`int<class_int>` | :ref:`operator *<class_int_operator_mul_int>` **(** :ref:`int<class_int>` right **)** |
  89. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  90. | :ref:`float<class_float>` | :ref:`operator **<class_int_operator_pow_float>` **(** :ref:`float<class_float>` right **)** |
  91. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  92. | :ref:`int<class_int>` | :ref:`operator **<class_int_operator_pow_int>` **(** :ref:`int<class_int>` right **)** |
  93. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  94. | :ref:`float<class_float>` | :ref:`operator +<class_int_operator_sum_float>` **(** :ref:`float<class_float>` right **)** |
  95. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  96. | :ref:`int<class_int>` | :ref:`operator +<class_int_operator_sum_int>` **(** :ref:`int<class_int>` right **)** |
  97. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  98. | :ref:`float<class_float>` | :ref:`operator -<class_int_operator_dif_float>` **(** :ref:`float<class_float>` right **)** |
  99. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  100. | :ref:`int<class_int>` | :ref:`operator -<class_int_operator_dif_int>` **(** :ref:`int<class_int>` right **)** |
  101. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  102. | :ref:`float<class_float>` | :ref:`operator /<class_int_operator_div_float>` **(** :ref:`float<class_float>` right **)** |
  103. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  104. | :ref:`int<class_int>` | :ref:`operator /<class_int_operator_div_int>` **(** :ref:`int<class_int>` right **)** |
  105. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  106. | :ref:`bool<class_bool>` | :ref:`operator \<<class_int_operator_lt_float>` **(** :ref:`float<class_float>` right **)** |
  107. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  108. | :ref:`bool<class_bool>` | :ref:`operator \<<class_int_operator_lt_int>` **(** :ref:`int<class_int>` right **)** |
  109. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  110. | :ref:`int<class_int>` | :ref:`operator \<\<<class_int_operator_bwsl_int>` **(** :ref:`int<class_int>` right **)** |
  111. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  112. | :ref:`bool<class_bool>` | :ref:`operator \<=<class_int_operator_lte_float>` **(** :ref:`float<class_float>` right **)** |
  113. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  114. | :ref:`bool<class_bool>` | :ref:`operator \<=<class_int_operator_lte_int>` **(** :ref:`int<class_int>` right **)** |
  115. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  116. | :ref:`bool<class_bool>` | :ref:`operator ==<class_int_operator_eq_float>` **(** :ref:`float<class_float>` right **)** |
  117. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  118. | :ref:`bool<class_bool>` | :ref:`operator ==<class_int_operator_eq_int>` **(** :ref:`int<class_int>` right **)** |
  119. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  120. | :ref:`bool<class_bool>` | :ref:`operator ><class_int_operator_gt_float>` **(** :ref:`float<class_float>` right **)** |
  121. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  122. | :ref:`bool<class_bool>` | :ref:`operator ><class_int_operator_gt_int>` **(** :ref:`int<class_int>` right **)** |
  123. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  124. | :ref:`bool<class_bool>` | :ref:`operator >=<class_int_operator_gte_float>` **(** :ref:`float<class_float>` right **)** |
  125. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  126. | :ref:`bool<class_bool>` | :ref:`operator >=<class_int_operator_gte_int>` **(** :ref:`int<class_int>` right **)** |
  127. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  128. | :ref:`int<class_int>` | :ref:`operator >><class_int_operator_bwsr_int>` **(** :ref:`int<class_int>` right **)** |
  129. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  130. | :ref:`int<class_int>` | :ref:`operator ^<class_int_operator_bwxor_int>` **(** :ref:`int<class_int>` right **)** |
  131. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  132. | :ref:`int<class_int>` | :ref:`operator unary+<class_int_operator_unplus>` **(** **)** |
  133. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  134. | :ref:`int<class_int>` | :ref:`operator unary-<class_int_operator_unminus>` **(** **)** |
  135. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  136. | :ref:`int<class_int>` | :ref:`operator |<class_int_operator_bwor_int>` **(** :ref:`int<class_int>` right **)** |
  137. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  138. | :ref:`int<class_int>` | :ref:`operator ~<class_int_operator_bwnot>` **(** **)** |
  139. +-------------------------------------+------------------------------------------------------------------------------------------------------------+
  140. .. rst-class:: classref-section-separator
  141. ----
  142. .. rst-class:: classref-descriptions-group
  143. Constructor Descriptions
  144. ------------------------
  145. .. _class_int_constructor_int:
  146. .. rst-class:: classref-constructor
  147. :ref:`int<class_int>` **int** **(** **)**
  148. Constructs a default-initialized **int** set to ``0``.
  149. .. rst-class:: classref-item-separator
  150. ----
  151. .. rst-class:: classref-constructor
  152. :ref:`int<class_int>` **int** **(** :ref:`int<class_int>` from **)**
  153. Constructs an **int** as a copy of the given **int**.
  154. .. rst-class:: classref-item-separator
  155. ----
  156. .. rst-class:: classref-constructor
  157. :ref:`int<class_int>` **int** **(** :ref:`String<class_String>` from **)**
  158. Converts a :ref:`String<class_String>` to an **int**, following the same rules as :ref:`String.to_int<class_String_method_to_int>`.
  159. .. rst-class:: classref-item-separator
  160. ----
  161. .. rst-class:: classref-constructor
  162. :ref:`int<class_int>` **int** **(** :ref:`bool<class_bool>` from **)**
  163. 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.
  164. .. rst-class:: classref-item-separator
  165. ----
  166. .. rst-class:: classref-constructor
  167. :ref:`int<class_int>` **int** **(** :ref:`float<class_float>` from **)**
  168. 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.
  169. .. rst-class:: classref-section-separator
  170. ----
  171. .. rst-class:: classref-descriptions-group
  172. Operator Descriptions
  173. ---------------------
  174. .. _class_int_operator_neq_float:
  175. .. rst-class:: classref-operator
  176. :ref:`bool<class_bool>` **operator !=** **(** :ref:`float<class_float>` right **)**
  177. Returns ``true`` if this **int** is not equivalent to the given :ref:`float<class_float>`.
  178. .. rst-class:: classref-item-separator
  179. ----
  180. .. _class_int_operator_neq_int:
  181. .. rst-class:: classref-operator
  182. :ref:`bool<class_bool>` **operator !=** **(** :ref:`int<class_int>` right **)**
  183. Returns ``true`` if the integers are not equal.
  184. .. rst-class:: classref-item-separator
  185. ----
  186. .. _class_int_operator_mod_int:
  187. .. rst-class:: classref-operator
  188. :ref:`int<class_int>` **operator %** **(** :ref:`int<class_int>` right **)**
  189. 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.
  190. ::
  191. print(5 % 2) # 1
  192. print(12 % 4) # 0
  193. print(-5 % 3) # -2
  194. .. rst-class:: classref-item-separator
  195. ----
  196. .. _class_int_operator_bwand_int:
  197. .. rst-class:: classref-operator
  198. :ref:`int<class_int>` **operator &** **(** :ref:`int<class_int>` right **)**
  199. Returns the result of bitwise ``AND`` operation for two integers.
  200. ::
  201. print(3 & 1) # 1
  202. print(11 & 3) # 3
  203. It's useful to retrieve binary flags from a variable.
  204. ::
  205. var flags = 5
  206. # Do something if the first bit is enabled.
  207. if flags & 1:
  208. do_stuff()
  209. .. rst-class:: classref-item-separator
  210. ----
  211. .. _class_int_operator_mul_Color:
  212. .. rst-class:: classref-operator
  213. :ref:`Color<class_Color>` **operator *** **(** :ref:`Color<class_Color>` right **)**
  214. Multiplies each component of the :ref:`Color<class_Color>` by the given **int**.
  215. .. rst-class:: classref-item-separator
  216. ----
  217. .. _class_int_operator_mul_Quaternion:
  218. .. rst-class:: classref-operator
  219. :ref:`Quaternion<class_Quaternion>` **operator *** **(** :ref:`Quaternion<class_Quaternion>` right **)**
  220. 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.
  221. .. rst-class:: classref-item-separator
  222. ----
  223. .. _class_int_operator_mul_Vector2:
  224. .. rst-class:: classref-operator
  225. :ref:`Vector2<class_Vector2>` **operator *** **(** :ref:`Vector2<class_Vector2>` right **)**
  226. Multiplies each component of the :ref:`Vector2<class_Vector2>` by the given **int**.
  227. ::
  228. print(2 * Vector2(1, 1)) # Vector2(2, 2)
  229. .. rst-class:: classref-item-separator
  230. ----
  231. .. _class_int_operator_mul_Vector2i:
  232. .. rst-class:: classref-operator
  233. :ref:`Vector2i<class_Vector2i>` **operator *** **(** :ref:`Vector2i<class_Vector2i>` right **)**
  234. Multiplies each component of the :ref:`Vector2i<class_Vector2i>` by the given **int**.
  235. .. rst-class:: classref-item-separator
  236. ----
  237. .. _class_int_operator_mul_Vector3:
  238. .. rst-class:: classref-operator
  239. :ref:`Vector3<class_Vector3>` **operator *** **(** :ref:`Vector3<class_Vector3>` right **)**
  240. Multiplies each component of the :ref:`Vector3<class_Vector3>` by the given **int**.
  241. .. rst-class:: classref-item-separator
  242. ----
  243. .. _class_int_operator_mul_Vector3i:
  244. .. rst-class:: classref-operator
  245. :ref:`Vector3i<class_Vector3i>` **operator *** **(** :ref:`Vector3i<class_Vector3i>` right **)**
  246. Multiplies each component of the :ref:`Vector3i<class_Vector3i>` by the given **int**.
  247. .. rst-class:: classref-item-separator
  248. ----
  249. .. _class_int_operator_mul_Vector4:
  250. .. rst-class:: classref-operator
  251. :ref:`Vector4<class_Vector4>` **operator *** **(** :ref:`Vector4<class_Vector4>` right **)**
  252. Multiplies each component of the :ref:`Vector4<class_Vector4>` by the given **int**.
  253. .. rst-class:: classref-item-separator
  254. ----
  255. .. _class_int_operator_mul_Vector4i:
  256. .. rst-class:: classref-operator
  257. :ref:`Vector4i<class_Vector4i>` **operator *** **(** :ref:`Vector4i<class_Vector4i>` right **)**
  258. Multiplies each component of the :ref:`Vector4i<class_Vector4i>` by the given **int**.
  259. .. rst-class:: classref-item-separator
  260. ----
  261. .. _class_int_operator_mul_float:
  262. .. rst-class:: classref-operator
  263. :ref:`float<class_float>` **operator *** **(** :ref:`float<class_float>` right **)**
  264. Multiplies an **int** and a :ref:`float<class_float>`. The result is a :ref:`float<class_float>`.
  265. .. rst-class:: classref-item-separator
  266. ----
  267. .. _class_int_operator_mul_int:
  268. .. rst-class:: classref-operator
  269. :ref:`int<class_int>` **operator *** **(** :ref:`int<class_int>` right **)**
  270. Multiplies two **int**\ s.
  271. .. rst-class:: classref-item-separator
  272. ----
  273. .. _class_int_operator_pow_float:
  274. .. rst-class:: classref-operator
  275. :ref:`float<class_float>` **operator **** **(** :ref:`float<class_float>` right **)**
  276. Raises an **int** to a power of a :ref:`float<class_float>`. The result is a :ref:`float<class_float>`.
  277. ::
  278. print(8**0.25) # 1.68179283050743
  279. .. rst-class:: classref-item-separator
  280. ----
  281. .. _class_int_operator_pow_int:
  282. .. rst-class:: classref-operator
  283. :ref:`int<class_int>` **operator **** **(** :ref:`int<class_int>` right **)**
  284. Raises an **int** to a power of a **int**.
  285. ::
  286. print(5**5) # 3125
  287. .. rst-class:: classref-item-separator
  288. ----
  289. .. _class_int_operator_sum_float:
  290. .. rst-class:: classref-operator
  291. :ref:`float<class_float>` **operator +** **(** :ref:`float<class_float>` right **)**
  292. Adds an **int** and a :ref:`float<class_float>`. The result is a :ref:`float<class_float>`.
  293. .. rst-class:: classref-item-separator
  294. ----
  295. .. _class_int_operator_sum_int:
  296. .. rst-class:: classref-operator
  297. :ref:`int<class_int>` **operator +** **(** :ref:`int<class_int>` right **)**
  298. Adds two integers.
  299. .. rst-class:: classref-item-separator
  300. ----
  301. .. _class_int_operator_dif_float:
  302. .. rst-class:: classref-operator
  303. :ref:`float<class_float>` **operator -** **(** :ref:`float<class_float>` right **)**
  304. Subtracts a :ref:`float<class_float>` from an **int**. The result is a :ref:`float<class_float>`.
  305. .. rst-class:: classref-item-separator
  306. ----
  307. .. _class_int_operator_dif_int:
  308. .. rst-class:: classref-operator
  309. :ref:`int<class_int>` **operator -** **(** :ref:`int<class_int>` right **)**
  310. Subtracts two integers.
  311. .. rst-class:: classref-item-separator
  312. ----
  313. .. _class_int_operator_div_float:
  314. .. rst-class:: classref-operator
  315. :ref:`float<class_float>` **operator /** **(** :ref:`float<class_float>` right **)**
  316. Divides an **int** by a :ref:`float<class_float>`. The result is a :ref:`float<class_float>`.
  317. ::
  318. print(10 / 3.0) # 3.333...
  319. .. rst-class:: classref-item-separator
  320. ----
  321. .. _class_int_operator_div_int:
  322. .. rst-class:: classref-operator
  323. :ref:`int<class_int>` **operator /** **(** :ref:`int<class_int>` right **)**
  324. Divides two integers. The decimal part of the result is discarded (truncated).
  325. ::
  326. print(10 / 2) # 5
  327. print(10 / 3) # 3
  328. .. rst-class:: classref-item-separator
  329. ----
  330. .. _class_int_operator_lt_float:
  331. .. rst-class:: classref-operator
  332. :ref:`bool<class_bool>` **operator <** **(** :ref:`float<class_float>` right **)**
  333. Returns ``true`` if this **int** is less than the given :ref:`float<class_float>`.
  334. .. rst-class:: classref-item-separator
  335. ----
  336. .. _class_int_operator_lt_int:
  337. .. rst-class:: classref-operator
  338. :ref:`bool<class_bool>` **operator <** **(** :ref:`int<class_int>` right **)**
  339. Returns ``true`` if the left integer is less than the right one.
  340. .. rst-class:: classref-item-separator
  341. ----
  342. .. _class_int_operator_bwsl_int:
  343. .. rst-class:: classref-operator
  344. :ref:`int<class_int>` **operator <<** **(** :ref:`int<class_int>` right **)**
  345. Performs bitwise shift left operation on the integer. Effectively the same as multiplying by a power of 2.
  346. ::
  347. print(10 << 1) # 20
  348. print(10 << 4) # 160
  349. .. rst-class:: classref-item-separator
  350. ----
  351. .. _class_int_operator_lte_float:
  352. .. rst-class:: classref-operator
  353. :ref:`bool<class_bool>` **operator <=** **(** :ref:`float<class_float>` right **)**
  354. Returns ``true`` if this **int** is less than or equal to the given :ref:`float<class_float>`.
  355. .. rst-class:: classref-item-separator
  356. ----
  357. .. _class_int_operator_lte_int:
  358. .. rst-class:: classref-operator
  359. :ref:`bool<class_bool>` **operator <=** **(** :ref:`int<class_int>` right **)**
  360. Returns ``true`` if the left integer is less than or equal to the right one.
  361. .. rst-class:: classref-item-separator
  362. ----
  363. .. _class_int_operator_eq_float:
  364. .. rst-class:: classref-operator
  365. :ref:`bool<class_bool>` **operator ==** **(** :ref:`float<class_float>` right **)**
  366. Returns ``true`` if the integer is equal to the given :ref:`float<class_float>`.
  367. .. rst-class:: classref-item-separator
  368. ----
  369. .. _class_int_operator_eq_int:
  370. .. rst-class:: classref-operator
  371. :ref:`bool<class_bool>` **operator ==** **(** :ref:`int<class_int>` right **)**
  372. Returns ``true`` if both integers are equal.
  373. .. rst-class:: classref-item-separator
  374. ----
  375. .. _class_int_operator_gt_float:
  376. .. rst-class:: classref-operator
  377. :ref:`bool<class_bool>` **operator >** **(** :ref:`float<class_float>` right **)**
  378. Returns ``true`` if this **int** is greater than the given :ref:`float<class_float>`.
  379. .. rst-class:: classref-item-separator
  380. ----
  381. .. _class_int_operator_gt_int:
  382. .. rst-class:: classref-operator
  383. :ref:`bool<class_bool>` **operator >** **(** :ref:`int<class_int>` right **)**
  384. Returns ``true`` if the left integer is greater than the right one.
  385. .. rst-class:: classref-item-separator
  386. ----
  387. .. _class_int_operator_gte_float:
  388. .. rst-class:: classref-operator
  389. :ref:`bool<class_bool>` **operator >=** **(** :ref:`float<class_float>` right **)**
  390. Returns ``true`` if this **int** is greater than or equal to the given :ref:`float<class_float>`.
  391. .. rst-class:: classref-item-separator
  392. ----
  393. .. _class_int_operator_gte_int:
  394. .. rst-class:: classref-operator
  395. :ref:`bool<class_bool>` **operator >=** **(** :ref:`int<class_int>` right **)**
  396. Returns ``true`` if the left integer is greater than or equal to the right one.
  397. .. rst-class:: classref-item-separator
  398. ----
  399. .. _class_int_operator_bwsr_int:
  400. .. rst-class:: classref-operator
  401. :ref:`int<class_int>` **operator >>** **(** :ref:`int<class_int>` right **)**
  402. Performs bitwise shift right operation on the integer. Effectively the same as dividing by a power of 2.
  403. ::
  404. print(10 >> 1) # 5
  405. print(10 >> 2) # 2
  406. .. rst-class:: classref-item-separator
  407. ----
  408. .. _class_int_operator_bwxor_int:
  409. .. rst-class:: classref-operator
  410. :ref:`int<class_int>` **operator ^** **(** :ref:`int<class_int>` right **)**
  411. Returns the result of bitwise ``XOR`` operation for two integers.
  412. ::
  413. print(5 ^ 1) # 4
  414. print(4 ^ 7) # 3
  415. .. rst-class:: classref-item-separator
  416. ----
  417. .. _class_int_operator_unplus:
  418. .. rst-class:: classref-operator
  419. :ref:`int<class_int>` **operator unary+** **(** **)**
  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-** **(** **)**
  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 |** **(** :ref:`int<class_int>` right **)**
  432. Returns the result of bitwise ``OR`` operation for two integers.
  433. ::
  434. print(2 | 4) # 6
  435. print(1 | 3) # 3
  436. It's useful to store binary flags in a variable.
  437. ::
  438. var flags = 0
  439. # Turn first and third bit on.
  440. flags |= 1
  441. flags |= 4
  442. .. rst-class:: classref-item-separator
  443. ----
  444. .. _class_int_operator_bwnot:
  445. .. rst-class:: classref-operator
  446. :ref:`int<class_int>` **operator ~** **(** **)**
  447. Returns the result of bitwise ``NOT`` operation for the integer. It's effectively equal to ``-int + 1``.
  448. ::
  449. print(~4) # -3
  450. print(~7) # -6
  451. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  452. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  453. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  454. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  455. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  456. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`