2
0

float.xml 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="float" version="4.0">
  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. <description>
  48. </description>
  49. </operator>
  50. <operator name="operator !=">
  51. <return type="bool" />
  52. <argument index="0" name="right" type="float" />
  53. <description>
  54. Returns [code]true[/code] if two floats are different from each other.
  55. </description>
  56. </operator>
  57. <operator name="operator !=">
  58. <return type="bool" />
  59. <argument index="0" name="right" type="int" />
  60. <description>
  61. Returns [code]true[/code] if the integer has different value than the float.
  62. </description>
  63. </operator>
  64. <operator name="operator *">
  65. <return type="float" />
  66. <argument index="0" name="right" type="float" />
  67. <description>
  68. Multiplies two [float]s.
  69. </description>
  70. </operator>
  71. <operator name="operator *">
  72. <return type="Quaternion" />
  73. <argument index="0" name="right" type="Quaternion" />
  74. <description>
  75. Multiplies each component of the [Quaternion] by the given [float].
  76. </description>
  77. </operator>
  78. <operator name="operator *">
  79. <return type="Vector2" />
  80. <argument index="0" name="right" type="Vector2" />
  81. <description>
  82. Multiplies each component of the [Vector2] by the given [float].
  83. [codeblock]
  84. print(2.5 * Vector2(1, 1)) # Vector2(2.5, 2.5)
  85. [/codeblock]
  86. </description>
  87. </operator>
  88. <operator name="operator *">
  89. <return type="Vector2i" />
  90. <argument index="0" name="right" type="Vector2i" />
  91. <description>
  92. Multiplies each component of the [Vector2i] by the given [float].
  93. [codeblock]
  94. print(2.0 * Vector2i(1, 1)) # Vector2i(2.0, 2.0)
  95. [/codeblock]
  96. </description>
  97. </operator>
  98. <operator name="operator *">
  99. <return type="Vector3" />
  100. <argument index="0" name="right" type="Vector3" />
  101. <description>
  102. Multiplies each component of the [Vector3] by the given [float].
  103. </description>
  104. </operator>
  105. <operator name="operator *">
  106. <return type="Vector3i" />
  107. <argument index="0" name="right" type="Vector3i" />
  108. <description>
  109. Multiplies each component of the [Vector3i] by the given [float].
  110. </description>
  111. </operator>
  112. <operator name="operator *">
  113. <return type="Color" />
  114. <argument index="0" name="right" type="Color" />
  115. <description>
  116. Multiplies each component of the [Color] by the given [float].
  117. [codeblock]
  118. print(1.5 * Color(0.5, 0.5, 0.5)) # Color(0.75, 0.75, 0.75)
  119. [/codeblock]
  120. </description>
  121. </operator>
  122. <operator name="operator *">
  123. <return type="float" />
  124. <argument index="0" name="right" type="int" />
  125. <description>
  126. Multiplies a [float] and an [int]. The result is a [float].
  127. </description>
  128. </operator>
  129. <operator name="operator +">
  130. <return type="float" />
  131. <argument index="0" name="right" type="float" />
  132. <description>
  133. Adds two floats.
  134. </description>
  135. </operator>
  136. <operator name="operator +">
  137. <return type="float" />
  138. <argument index="0" name="right" type="int" />
  139. <description>
  140. Adds a [float] and an [int]. The result is a [float].
  141. </description>
  142. </operator>
  143. <operator name="operator -">
  144. <return type="float" />
  145. <argument index="0" name="right" type="float" />
  146. <description>
  147. Subtracts a float from a float.
  148. </description>
  149. </operator>
  150. <operator name="operator -">
  151. <return type="float" />
  152. <argument index="0" name="right" type="int" />
  153. <description>
  154. Subtracts an [int] from a [float]. The result is a [float].
  155. </description>
  156. </operator>
  157. <operator name="operator /">
  158. <return type="float" />
  159. <argument index="0" name="right" type="float" />
  160. <description>
  161. Divides two floats.
  162. </description>
  163. </operator>
  164. <operator name="operator /">
  165. <return type="float" />
  166. <argument index="0" name="right" type="int" />
  167. <description>
  168. Divides a [float] by an [int]. The result is a [float].
  169. </description>
  170. </operator>
  171. <operator name="operator &lt;">
  172. <return type="bool" />
  173. <argument index="0" name="right" type="float" />
  174. <description>
  175. Returns [code]true[/code] the left float is less than the right one.
  176. </description>
  177. </operator>
  178. <operator name="operator &lt;">
  179. <return type="bool" />
  180. <argument index="0" name="right" type="int" />
  181. <description>
  182. Returns [code]true[/code] if this [float] is less than the given [int].
  183. </description>
  184. </operator>
  185. <operator name="operator &lt;=">
  186. <return type="bool" />
  187. <argument index="0" name="right" type="float" />
  188. <description>
  189. Returns [code]true[/code] the left integer is less than or equal to the right one.
  190. </description>
  191. </operator>
  192. <operator name="operator &lt;=">
  193. <return type="bool" />
  194. <argument index="0" name="right" type="int" />
  195. <description>
  196. Returns [code]true[/code] if this [float] is less than or equal to the given [int].
  197. </description>
  198. </operator>
  199. <operator name="operator ==">
  200. <return type="bool" />
  201. <description>
  202. </description>
  203. </operator>
  204. <operator name="operator ==">
  205. <return type="bool" />
  206. <argument index="0" name="right" type="float" />
  207. <description>
  208. Returns [code]true[/code] if both floats are exactly equal.
  209. [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.
  210. </description>
  211. </operator>
  212. <operator name="operator ==">
  213. <return type="bool" />
  214. <argument index="0" name="right" type="int" />
  215. <description>
  216. Returns [code]true[/code] if the [float] and the given [int] are equal.
  217. </description>
  218. </operator>
  219. <operator name="operator &gt;">
  220. <return type="bool" />
  221. <argument index="0" name="right" type="float" />
  222. <description>
  223. Returns [code]true[/code] the left float is greater than the right one.
  224. </description>
  225. </operator>
  226. <operator name="operator &gt;">
  227. <return type="bool" />
  228. <argument index="0" name="right" type="int" />
  229. <description>
  230. Returns [code]true[/code] if this [float] is greater than the given [int].
  231. </description>
  232. </operator>
  233. <operator name="operator &gt;=">
  234. <return type="bool" />
  235. <argument index="0" name="right" type="float" />
  236. <description>
  237. Returns [code]true[/code] the left float is greater than or equal to the right one.
  238. </description>
  239. </operator>
  240. <operator name="operator &gt;=">
  241. <return type="bool" />
  242. <argument index="0" name="right" type="int" />
  243. <description>
  244. Returns [code]true[/code] if this [float] is greater than or equal to the given [int].
  245. </description>
  246. </operator>
  247. <operator name="operator unary+">
  248. <return type="float" />
  249. <description>
  250. 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.
  251. </description>
  252. </operator>
  253. <operator name="operator unary-">
  254. <return type="float" />
  255. <description>
  256. 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.
  257. </description>
  258. </operator>
  259. </operators>
  260. </class>