float.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="float" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
  3. <brief_description>
  4. Float built-in type.
  5. </brief_description>
  6. <description>
  7. The [float] built-in type is a 64-bit double-precision floating-point number, equivalent to [code]double[/code] in C++. This type has 14 reliable decimal digits of precision. The [float] type can be stored in [Variant], which is the generic type used by the engine. The maximum value of [float] is approximately [code]1.79769e308[/code], and the minimum is approximately [code]-1.79769e308[/code].
  8. Many methods and properties in the engine use 32-bit single-precision floating-point numbers instead, equivalent to [code]float[/code] in C++, which have 6 reliable decimal digits of precision. For data structures such as [Vector2] and [Vector3], Godot uses 32-bit floating-point numbers by default, but it can be changed to use 64-bit doubles if Godot is compiled with the [code]float=64[/code] option.
  9. Math done using the [float] type is not guaranteed to be exact or deterministic, and will often result in small errors. You should usually use the [method @GlobalScope.is_equal_approx] and [method @GlobalScope.is_zero_approx] methods instead of [code]==[/code] to compare [float] values for equality.
  10. </description>
  11. <tutorials>
  12. <link title="Wikipedia: Double-precision floating-point format">https://en.wikipedia.org/wiki/Double-precision_floating-point_format</link>
  13. <link title="Wikipedia: Single-precision floating-point format">https://en.wikipedia.org/wiki/Single-precision_floating-point_format</link>
  14. </tutorials>
  15. <constructors>
  16. <constructor name="float">
  17. <return type="float" />
  18. <description>
  19. Constructs a default-initialized [float] set to [code]0.0[/code].
  20. </description>
  21. </constructor>
  22. <constructor name="float">
  23. <return type="float" />
  24. <argument index="0" name="from" type="float" />
  25. <description>
  26. Constructs a [float] as a copy of the given [float].
  27. </description>
  28. </constructor>
  29. <constructor name="float">
  30. <return type="float" />
  31. <argument index="0" name="from" type="bool" />
  32. <description>
  33. Cast a [bool] value to a floating-point value, [code]float(true)[/code] will be equal to 1.0 and [code]float(false)[/code] will be equal to 0.0.
  34. </description>
  35. </constructor>
  36. <constructor name="float">
  37. <return type="float" />
  38. <argument index="0" name="from" type="int" />
  39. <description>
  40. Cast an [int] value to a floating-point value, [code]float(1)[/code] will be equal to [code]1.0[/code].
  41. </description>
  42. </constructor>
  43. </constructors>
  44. <operators>
  45. <operator name="operator !=">
  46. <return type="bool" />
  47. <argument index="0" name="right" type="float" />
  48. <description>
  49. Returns [code]true[/code] if two floats are different from each other.
  50. </description>
  51. </operator>
  52. <operator name="operator !=">
  53. <return type="bool" />
  54. <argument index="0" name="right" type="int" />
  55. <description>
  56. Returns [code]true[/code] if the integer has different value than the float.
  57. </description>
  58. </operator>
  59. <operator name="operator *">
  60. <return type="Color" />
  61. <argument index="0" name="right" type="Color" />
  62. <description>
  63. Multiplies each component of the [Color] by the given [float].
  64. [codeblock]
  65. print(1.5 * Color(0.5, 0.5, 0.5)) # Color(0.75, 0.75, 0.75)
  66. [/codeblock]
  67. </description>
  68. </operator>
  69. <operator name="operator *">
  70. <return type="Quaternion" />
  71. <argument index="0" name="right" type="Quaternion" />
  72. <description>
  73. Multiplies each component of the [Quaternion] by the given [float]. This operation is not meaningful on its own, but it can be used as a part of a larger expression.
  74. </description>
  75. </operator>
  76. <operator name="operator *">
  77. <return type="Vector2" />
  78. <argument index="0" name="right" type="Vector2" />
  79. <description>
  80. Multiplies each component of the [Vector2] by the given [float].
  81. [codeblock]
  82. print(2.5 * Vector2(1, 3)) # Prints "(2.5, 7.5)"
  83. [/codeblock]
  84. </description>
  85. </operator>
  86. <operator name="operator *">
  87. <return type="Vector2" />
  88. <argument index="0" name="right" type="Vector2i" />
  89. <description>
  90. Multiplies each component of the [Vector2i] by the given [float]. Returns a [Vector2].
  91. [codeblock]
  92. print(0.9 * Vector2i(10, 15)) # Prints "(9, 13.5)"
  93. [/codeblock]
  94. </description>
  95. </operator>
  96. <operator name="operator *">
  97. <return type="Vector3" />
  98. <argument index="0" name="right" type="Vector3" />
  99. <description>
  100. Multiplies each component of the [Vector3] by the given [float].
  101. </description>
  102. </operator>
  103. <operator name="operator *">
  104. <return type="Vector3" />
  105. <argument index="0" name="right" type="Vector3i" />
  106. <description>
  107. Multiplies each component of the [Vector3i] by the given [float]. Returns a [Vector3].
  108. [codeblock]
  109. print(0.9 * Vector3i(10, 15, 20)) # Prints "(9, 13.5, 18)"
  110. [/codeblock]
  111. </description>
  112. </operator>
  113. <operator name="operator *">
  114. <return type="Vector4" />
  115. <argument index="0" name="right" type="Vector4" />
  116. <description>
  117. </description>
  118. </operator>
  119. <operator name="operator *">
  120. <return type="Vector4" />
  121. <argument index="0" name="right" type="Vector4i" />
  122. <description>
  123. </description>
  124. </operator>
  125. <operator name="operator *">
  126. <return type="float" />
  127. <argument index="0" name="right" type="float" />
  128. <description>
  129. Multiplies two [float]s.
  130. </description>
  131. </operator>
  132. <operator name="operator *">
  133. <return type="float" />
  134. <argument index="0" name="right" type="int" />
  135. <description>
  136. Multiplies a [float] and an [int]. The result is a [float].
  137. </description>
  138. </operator>
  139. <operator name="operator **">
  140. <return type="float" />
  141. <argument index="0" name="right" type="float" />
  142. <description>
  143. </description>
  144. </operator>
  145. <operator name="operator **">
  146. <return type="float" />
  147. <argument index="0" name="right" type="int" />
  148. <description>
  149. </description>
  150. </operator>
  151. <operator name="operator +">
  152. <return type="float" />
  153. <argument index="0" name="right" type="float" />
  154. <description>
  155. Adds two floats.
  156. </description>
  157. </operator>
  158. <operator name="operator +">
  159. <return type="float" />
  160. <argument index="0" name="right" type="int" />
  161. <description>
  162. Adds a [float] and an [int]. The result is a [float].
  163. </description>
  164. </operator>
  165. <operator name="operator -">
  166. <return type="float" />
  167. <argument index="0" name="right" type="float" />
  168. <description>
  169. Subtracts a float from a float.
  170. </description>
  171. </operator>
  172. <operator name="operator -">
  173. <return type="float" />
  174. <argument index="0" name="right" type="int" />
  175. <description>
  176. Subtracts an [int] from a [float]. The result is a [float].
  177. </description>
  178. </operator>
  179. <operator name="operator /">
  180. <return type="float" />
  181. <argument index="0" name="right" type="float" />
  182. <description>
  183. Divides two floats.
  184. </description>
  185. </operator>
  186. <operator name="operator /">
  187. <return type="float" />
  188. <argument index="0" name="right" type="int" />
  189. <description>
  190. Divides a [float] by an [int]. The result is a [float].
  191. </description>
  192. </operator>
  193. <operator name="operator &lt;">
  194. <return type="bool" />
  195. <argument index="0" name="right" type="float" />
  196. <description>
  197. Returns [code]true[/code] the left float is less than the right one.
  198. </description>
  199. </operator>
  200. <operator name="operator &lt;">
  201. <return type="bool" />
  202. <argument index="0" name="right" type="int" />
  203. <description>
  204. Returns [code]true[/code] if this [float] is less than the given [int].
  205. </description>
  206. </operator>
  207. <operator name="operator &lt;=">
  208. <return type="bool" />
  209. <argument index="0" name="right" type="float" />
  210. <description>
  211. Returns [code]true[/code] the left integer is less than or equal to the right one.
  212. </description>
  213. </operator>
  214. <operator name="operator &lt;=">
  215. <return type="bool" />
  216. <argument index="0" name="right" type="int" />
  217. <description>
  218. Returns [code]true[/code] if this [float] is less than or equal to the given [int].
  219. </description>
  220. </operator>
  221. <operator name="operator ==">
  222. <return type="bool" />
  223. <argument index="0" name="right" type="float" />
  224. <description>
  225. Returns [code]true[/code] if both floats are exactly equal.
  226. [b]Note:[/b] Due to floating-point precision errors, consider using [method @GlobalScope.is_equal_approx] or [method @GlobalScope.is_zero_approx] instead, which are more reliable.
  227. </description>
  228. </operator>
  229. <operator name="operator ==">
  230. <return type="bool" />
  231. <argument index="0" name="right" type="int" />
  232. <description>
  233. Returns [code]true[/code] if the [float] and the given [int] are equal.
  234. </description>
  235. </operator>
  236. <operator name="operator &gt;">
  237. <return type="bool" />
  238. <argument index="0" name="right" type="float" />
  239. <description>
  240. Returns [code]true[/code] the left float is greater than the right one.
  241. </description>
  242. </operator>
  243. <operator name="operator &gt;">
  244. <return type="bool" />
  245. <argument index="0" name="right" type="int" />
  246. <description>
  247. Returns [code]true[/code] if this [float] is greater than the given [int].
  248. </description>
  249. </operator>
  250. <operator name="operator &gt;=">
  251. <return type="bool" />
  252. <argument index="0" name="right" type="float" />
  253. <description>
  254. Returns [code]true[/code] the left float is greater than or equal to the right one.
  255. </description>
  256. </operator>
  257. <operator name="operator &gt;=">
  258. <return type="bool" />
  259. <argument index="0" name="right" type="int" />
  260. <description>
  261. Returns [code]true[/code] if this [float] is greater than or equal to the given [int].
  262. </description>
  263. </operator>
  264. <operator name="operator unary+">
  265. <return type="float" />
  266. <description>
  267. Returns the same value as if the [code]+[/code] was not there. Unary [code]+[/code] does nothing, but sometimes it can make your code more readable.
  268. </description>
  269. </operator>
  270. <operator name="operator unary-">
  271. <return type="float" />
  272. <description>
  273. Returns the negative value of the [float]. If positive, turns the number negative. If negative, turns the number positive. With floats, the number zero can be either positive or negative.
  274. </description>
  275. </operator>
  276. </operators>
  277. </class>