| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <class name="float" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> |
| 3 | <brief_description> |
| 4 | A built-in type for floating-point numbers. |
| 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 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 skip-lint]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]precision=double[/code] option. |
| 9 | Math done using the [float] type is not guaranteed to be exact 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 | <param 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 | <param index="0" name="from" type="String" /> |
| 32 | <description> |
| 33 | Converts a [String] to a [float], following the same rules as [method String.to_float]. |
| 34 | </description> |
| 35 | </constructor> |
| 36 | <constructor name="float"> |
| 37 | <return type="float" /> |
| 38 | <param index="0" name="from" type="bool" /> |
| 39 | <description> |
| 40 | 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. |
| 41 | </description> |
| 42 | </constructor> |
| 43 | <constructor name="float"> |
| 44 | <return type="float" /> |
| 45 | <param index="0" name="from" type="int" /> |
| 46 | <description> |
| 47 | Cast an [int] value to a floating-point value, [code]float(1)[/code] will be equal to [code]1.0[/code]. |
| 48 | </description> |
| 49 | </constructor> |
| 50 | </constructors> |
| 51 | <operators> |
| 52 | <operator name="operator !="> |
| 53 | <return type="bool" /> |
| 54 | <param index="0" name="right" type="float" /> |
| 55 | <description> |
| 56 | Returns [code]true[/code] if two floats are different from each other. |
| 57 | [b]Note:[/b] [constant @GDScript.NAN] doesn't behave the same as other numbers. Therefore, the results from this operator may not be accurate if NaNs are included. |
| 58 | </description> |
| 59 | </operator> |
| 60 | <operator name="operator !="> |
| 61 | <return type="bool" /> |
| 62 | <param index="0" name="right" type="int" /> |
| 63 | <description> |
| 64 | Returns [code]true[/code] if the integer has different value than the float. |
| 65 | </description> |
| 66 | </operator> |
| 67 | <operator name="operator *"> |
| 68 | <return type="Color" /> |
| 69 | <param index="0" name="right" type="Color" /> |
| 70 | <description> |
| 71 | Multiplies each component of the [Color], including the alpha, by the given [float]. |
| 72 | [codeblock] |
| 73 | print(1.5 * Color(0.5, 0.5, 0.5)) # Prints (0.75, 0.75, 0.75, 1.5) |
| 74 | [/codeblock] |
| 75 | </description> |
| 76 | </operator> |
| 77 | <operator name="operator *"> |
| 78 | <return type="Quaternion" /> |
| 79 | <param index="0" name="right" type="Quaternion" /> |
| 80 | <description> |
| 81 | 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. |
| 82 | </description> |
| 83 | </operator> |
| 84 | <operator name="operator *"> |
| 85 | <return type="Vector2" /> |
| 86 | <param index="0" name="right" type="Vector2" /> |
| 87 | <description> |
| 88 | Multiplies each component of the [Vector2] by the given [float]. |
| 89 | [codeblock] |
| 90 | print(2.5 * Vector2(1, 3)) # Prints (2.5, 7.5) |
| 91 | [/codeblock] |
| 92 | </description> |
| 93 | </operator> |
| 94 | <operator name="operator *"> |
| 95 | <return type="Vector2" /> |
| 96 | <param index="0" name="right" type="Vector2i" /> |
| 97 | <description> |
| 98 | Multiplies each component of the [Vector2i] by the given [float]. Returns a [Vector2]. |
| 99 | [codeblock] |
| 100 | print(0.9 * Vector2i(10, 15)) # Prints (9.0, 13.5) |
| 101 | [/codeblock] |
| 102 | </description> |
| 103 | </operator> |
| 104 | <operator name="operator *"> |
| 105 | <return type="Vector3" /> |
| 106 | <param index="0" name="right" type="Vector3" /> |
| 107 | <description> |
| 108 | Multiplies each component of the [Vector3] by the given [float]. |
| 109 | </description> |
| 110 | </operator> |
| 111 | <operator name="operator *"> |
| 112 | <return type="Vector3" /> |
| 113 | <param index="0" name="right" type="Vector3i" /> |
| 114 | <description> |
| 115 | Multiplies each component of the [Vector3i] by the given [float]. Returns a [Vector3]. |
| 116 | [codeblock] |
| 117 | print(0.9 * Vector3i(10, 15, 20)) # Prints (9.0, 13.5, 18.0) |
| 118 | [/codeblock] |
| 119 | </description> |
| 120 | </operator> |
| 121 | <operator name="operator *"> |
| 122 | <return type="Vector4" /> |
| 123 | <param index="0" name="right" type="Vector4" /> |
| 124 | <description> |
| 125 | Multiplies each component of the [Vector4] by the given [float]. |
| 126 | </description> |
| 127 | </operator> |
| 128 | <operator name="operator *"> |
| 129 | <return type="Vector4" /> |
| 130 | <param index="0" name="right" type="Vector4i" /> |
| 131 | <description> |
| 132 | Multiplies each component of the [Vector4i] by the given [float]. Returns a [Vector4]. |
| 133 | [codeblock] |
| 134 | print(0.9 * Vector4i(10, 15, 20, -10)) # Prints (9.0, 13.5, 18.0, -9.0) |
| 135 | [/codeblock] |
| 136 | </description> |
| 137 | </operator> |
| 138 | <operator name="operator *"> |
| 139 | <return type="float" /> |
| 140 | <param index="0" name="right" type="float" /> |
| 141 | <description> |
| 142 | Multiplies two [float]s. |
| 143 | </description> |
| 144 | </operator> |
| 145 | <operator name="operator *"> |
| 146 | <return type="float" /> |
| 147 | <param index="0" name="right" type="int" /> |
| 148 | <description> |
| 149 | Multiplies a [float] and an [int]. The result is a [float]. |
| 150 | </description> |
| 151 | </operator> |
| 152 | <operator name="operator **"> |
| 153 | <return type="float" /> |
| 154 | <param index="0" name="right" type="float" /> |
| 155 | <description> |
| 156 | Raises a [float] to a power of a [float]. |
| 157 | [codeblock] |
| 158 | print(39.0625**0.25) # 2.5 |
| 159 | [/codeblock] |
| 160 | </description> |
| 161 | </operator> |
| 162 | <operator name="operator **"> |
| 163 | <return type="float" /> |
| 164 | <param index="0" name="right" type="int" /> |
| 165 | <description> |
| 166 | Raises a [float] to a power of an [int]. The result is a [float]. |
| 167 | [codeblock] |
| 168 | print(0.9**3) # 0.729 |
| 169 | [/codeblock] |
| 170 | </description> |
| 171 | </operator> |
| 172 | <operator name="operator +"> |
| 173 | <return type="float" /> |
| 174 | <param index="0" name="right" type="float" /> |
| 175 | <description> |
| 176 | Adds two floats. |
| 177 | </description> |
| 178 | </operator> |
| 179 | <operator name="operator +"> |
| 180 | <return type="float" /> |
| 181 | <param index="0" name="right" type="int" /> |
| 182 | <description> |
| 183 | Adds a [float] and an [int]. The result is a [float]. |
| 184 | </description> |
| 185 | </operator> |
| 186 | <operator name="operator -"> |
| 187 | <return type="float" /> |
| 188 | <param index="0" name="right" type="float" /> |
| 189 | <description> |
| 190 | Subtracts a float from a float. |
| 191 | </description> |
| 192 | </operator> |
| 193 | <operator name="operator -"> |
| 194 | <return type="float" /> |
| 195 | <param index="0" name="right" type="int" /> |
| 196 | <description> |
| 197 | Subtracts an [int] from a [float]. The result is a [float]. |
| 198 | </description> |
| 199 | </operator> |
| 200 | <operator name="operator /"> |
| 201 | <return type="float" /> |
| 202 | <param index="0" name="right" type="float" /> |
| 203 | <description> |
| 204 | Divides two floats. |
| 205 | </description> |
| 206 | </operator> |
| 207 | <operator name="operator /"> |
| 208 | <return type="float" /> |
| 209 | <param index="0" name="right" type="int" /> |
| 210 | <description> |
| 211 | Divides a [float] by an [int]. The result is a [float]. |
| 212 | </description> |
| 213 | </operator> |
| 214 | <operator name="operator <"> |
| 215 | <return type="bool" /> |
| 216 | <param index="0" name="right" type="float" /> |
| 217 | <description> |
| 218 | Returns [code]true[/code] if the left float is less than the right one. |
| 219 | [b]Note:[/b] [constant @GDScript.NAN] doesn't behave the same as other numbers. Therefore, the results from this operator may not be accurate if NaNs are included. |
| 220 | </description> |
| 221 | </operator> |
| 222 | <operator name="operator <"> |
| 223 | <return type="bool" /> |
| 224 | <param index="0" name="right" type="int" /> |
| 225 | <description> |
| 226 | Returns [code]true[/code] if this [float] is less than the given [int]. |
| 227 | </description> |
| 228 | </operator> |
| 229 | <operator name="operator <="> |
| 230 | <return type="bool" /> |
| 231 | <param index="0" name="right" type="float" /> |
| 232 | <description> |
| 233 | Returns [code]true[/code] if the left float is less than or equal to the right one. |
| 234 | [b]Note:[/b] [constant @GDScript.NAN] doesn't behave the same as other numbers. Therefore, the results from this operator may not be accurate if NaNs are included. |
| 235 | </description> |
| 236 | </operator> |
| 237 | <operator name="operator <="> |
| 238 | <return type="bool" /> |
| 239 | <param index="0" name="right" type="int" /> |
| 240 | <description> |
| 241 | Returns [code]true[/code] if this [float] is less than or equal to the given [int]. |
| 242 | </description> |
| 243 | </operator> |
| 244 | <operator name="operator =="> |
| 245 | <return type="bool" /> |
| 246 | <param index="0" name="right" type="float" /> |
| 247 | <description> |
| 248 | Returns [code]true[/code] if both floats are exactly equal. |
| 249 | [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. |
| 250 | [b]Note:[/b] [constant @GDScript.NAN] doesn't behave the same as other numbers. Therefore, the results from this operator may not be accurate if NaNs are included. |
| 251 | </description> |
| 252 | </operator> |
| 253 | <operator name="operator =="> |
| 254 | <return type="bool" /> |
| 255 | <param index="0" name="right" type="int" /> |
| 256 | <description> |
| 257 | Returns [code]true[/code] if the [float] and the given [int] are equal. |
| 258 | </description> |
| 259 | </operator> |
| 260 | <operator name="operator >"> |
| 261 | <return type="bool" /> |
| 262 | <param index="0" name="right" type="float" /> |
| 263 | <description> |
| 264 | Returns [code]true[/code] if the left float is greater than the right one. |
| 265 | [b]Note:[/b] [constant @GDScript.NAN] doesn't behave the same as other numbers. Therefore, the results from this operator may not be accurate if NaNs are included. |
| 266 | </description> |
| 267 | </operator> |
| 268 | <operator name="operator >"> |
| 269 | <return type="bool" /> |
| 270 | <param index="0" name="right" type="int" /> |
| 271 | <description> |
| 272 | Returns [code]true[/code] if this [float] is greater than the given [int]. |
| 273 | </description> |
| 274 | </operator> |
| 275 | <operator name="operator >="> |
| 276 | <return type="bool" /> |
| 277 | <param index="0" name="right" type="float" /> |
| 278 | <description> |
| 279 | Returns [code]true[/code] if the left float is greater than or equal to the right one. |
| 280 | [b]Note:[/b] [constant @GDScript.NAN] doesn't behave the same as other numbers. Therefore, the results from this operator may not be accurate if NaNs are included. |
| 281 | </description> |
| 282 | </operator> |
| 283 | <operator name="operator >="> |
| 284 | <return type="bool" /> |
| 285 | <param index="0" name="right" type="int" /> |
| 286 | <description> |
| 287 | Returns [code]true[/code] if this [float] is greater than or equal to the given [int]. |
| 288 | </description> |
| 289 | </operator> |
| 290 | <operator name="operator unary+"> |
| 291 | <return type="float" /> |
| 292 | <description> |
| 293 | 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. |
| 294 | </description> |
| 295 | </operator> |
| 296 | <operator name="operator unary-"> |
| 297 | <return type="float" /> |
| 298 | <description> |
| 299 | 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. |
| 300 | </description> |
| 301 | </operator> |
| 302 | </operators> |
| 303 | </class> |