int.xml 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="int" category="Built-In Types" version="3.1.2">
  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. <methods>
  25. <method name="int">
  26. <return type="int">
  27. </return>
  28. <argument index="0" name="from" type="bool">
  29. </argument>
  30. <description>
  31. 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.
  32. </description>
  33. </method>
  34. <method name="int">
  35. <return type="int">
  36. </return>
  37. <argument index="0" name="from" type="float">
  38. </argument>
  39. <description>
  40. 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.
  41. </description>
  42. </method>
  43. <method name="int">
  44. <return type="int">
  45. </return>
  46. <argument index="0" name="from" type="String">
  47. </argument>
  48. <description>
  49. 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.
  50. </description>
  51. </method>
  52. </methods>
  53. <constants>
  54. </constants>
  55. </class>