int.xml 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="int" category="Built-In Types" version="3.1">
  3. <brief_description>
  4. Integer built-in type.
  5. </brief_description>
  6. <description>
  7. Signed 64-bit integer type.
  8. It can take values in the interval [code][-2^63, 2^63 - 1][/code], i.e. [code][-9223372036854775808, 9223372036854775807][/code]. Exceeding those bounds will wrap around.
  9. [code]int[/code] is a [Variant] type, and will thus be used when assigning an integer value to a [Variant]. It can also be enforced with the [code]: int[/code] type hint.
  10. [codeblock]
  11. var my_variant = 0 # int, value 0
  12. my_variant += 4.2 # float, value 4.2
  13. var my_int: int = 1 # int, value 1
  14. my_int = 4.2 # int, value 4, the right value is implicitly cast to int
  15. my_int = int("6.7") # int, value 6, the String is explicitly cast with [method int]
  16. var max_int = 9223372036854775807
  17. print(max_int) # 9223372036854775807, OK
  18. max_int += 1
  19. print(max_int) # -9223372036854775808, we overflowed and wrapped around
  20. [/codeblock]
  21. </description>
  22. <tutorials>
  23. </tutorials>
  24. <demos>
  25. </demos>
  26. <methods>
  27. <method name="int">
  28. <return type="int">
  29. </return>
  30. <argument index="0" name="from" type="bool">
  31. </argument>
  32. <description>
  33. Cast a [bool] value to an integer value, [code]int(true)[/code] will be equals to 1 and [code]int(false)[/code] will be equals to 0.
  34. </description>
  35. </method>
  36. <method name="int">
  37. <return type="int">
  38. </return>
  39. <argument index="0" name="from" type="float">
  40. </argument>
  41. <description>
  42. Cast a float value to an integer value, this method simply removes the number fractions, so for example [code]int(2.7)[/code] will be equals to 2, [code]int(.1)[/code] will be equals to 0 and [code]int(-2.7)[/code] will be equals to -2.
  43. </description>
  44. </method>
  45. <method name="int">
  46. <return type="int">
  47. </return>
  48. <argument index="0" name="from" type="String">
  49. </argument>
  50. <description>
  51. Cast a [String] value to an integer value, this method is an integer parser from a string, so calling this method with an invalid integer string will return 0, a valid string will be something like [code]'1.7'[/code]. This method will ignore all non-number characters, so calling [code]int('1e3')[/code] will return 13.
  52. </description>
  53. </method>
  54. </methods>
  55. <constants>
  56. </constants>
  57. </class>