int.xml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="int" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
  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. [int] 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 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. <argument index="0" name="from" type="bool" />
  28. <description>
  29. 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.
  30. </description>
  31. </method>
  32. <method name="int">
  33. <return type="int" />
  34. <argument index="0" name="from" type="float" />
  35. <description>
  36. Cast a float value to an integer value, this method simply removes the number fractions (i.e. rounds [code]from[/code] towards zero), so for example [code]int(2.7)[/code] will be equals to 2, [code]int(0.1)[/code] will be equals to 0 and [code]int(-2.7)[/code] will be equals to -2. This operation is also called truncation.
  37. </description>
  38. </method>
  39. <method name="int">
  40. <return type="int" />
  41. <argument index="0" name="from" type="String" />
  42. <description>
  43. 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.
  44. </description>
  45. </method>
  46. </methods>
  47. <constants>
  48. </constants>
  49. </class>