2017-09-12 20:42:36 +00:00
<?xml version="1.0" encoding="UTF-8" ?>
2022-02-14 13:18:53 +00:00
<class name= "float" version= "4.0" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "../class.xsd" >
2017-09-12 20:42:36 +00:00
<brief_description >
2023-04-27 23:35:33 +00:00
A built-in type for floating point numbers.
2017-09-12 20:42:36 +00:00
</brief_description>
<description >
2023-04-27 23:35:33 +00:00
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].
2022-10-14 16:53:07 +00:00
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]precision=double[/code] option.
2023-04-27 23:35:33 +00:00
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.
2017-09-12 20:42:36 +00:00
</description>
<tutorials >
2021-08-18 18:04:10 +00:00
<link title= "Wikipedia: Double-precision floating-point format" > https://en.wikipedia.org/wiki/Double-precision_floating-point_format</link>
<link title= "Wikipedia: Single-precision floating-point format" > https://en.wikipedia.org/wiki/Single-precision_floating-point_format</link>
2017-09-12 20:42:36 +00:00
</tutorials>
2021-09-21 02:49:02 +00:00
<constructors >
<constructor name= "float" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2020-11-09 16:46:03 +00:00
<description >
Constructs a default-initialized [float] set to [code]0.0[/code].
</description>
2021-09-21 02:49:02 +00:00
</constructor>
<constructor name= "float" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "from" type= "float" />
2017-09-12 20:42:36 +00:00
<description >
2020-11-09 16:46:03 +00:00
Constructs a [float] as a copy of the given [float].
2017-09-12 20:42:36 +00:00
</description>
2021-09-21 02:49:02 +00:00
</constructor>
2021-09-18 22:46:57 +00:00
<constructor name= "float" >
<return type= "float" />
<param index= "0" name= "from" type= "String" />
<description >
Converts a [String] to a [float], following the same rules as [method String.to_float].
</description>
</constructor>
2021-09-21 02:49:02 +00:00
<constructor name= "float" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "from" type= "bool" />
2017-09-12 20:42:36 +00:00
<description >
2020-11-09 16:46:03 +00:00
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.
2017-09-12 20:42:36 +00:00
</description>
2021-09-21 02:49:02 +00:00
</constructor>
<constructor name= "float" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "from" type= "int" />
2017-09-12 20:42:36 +00:00
<description >
2020-11-09 16:46:03 +00:00
Cast an [int] value to a floating-point value, [code]float(1)[/code] will be equal to [code]1.0[/code].
2017-09-12 20:42:36 +00:00
</description>
2021-09-21 02:49:02 +00:00
</constructor>
</constructors>
<operators >
<operator name= "operator !=" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "float" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Returns [code]true[/code] if two floats are different from each other.
2023-04-03 09:38:09 +00:00
[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.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator !=" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "int" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Returns [code]true[/code] if the integer has different value than the float.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator *" >
2021-11-28 08:48:57 +00:00
<return type= "Color" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Color" />
2020-11-10 13:16:20 +00:00
<description >
2023-04-27 23:35:33 +00:00
Multiplies each component of the [Color], including the alpha, by the given [float].
2021-11-28 08:48:57 +00:00
[codeblock]
print(1.5 * Color(0.5, 0.5, 0.5)) # Color(0.75, 0.75, 0.75)
[/codeblock]
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator *" >
<return type= "Quaternion" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Quaternion" />
2021-09-21 02:49:02 +00:00
<description >
2021-11-04 15:58:20 +00:00
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.
2021-09-21 02:49:02 +00:00
</description>
</operator>
<operator name= "operator *" >
2021-07-30 13:28:05 +00:00
<return type= "Vector2" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Vector2" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Multiplies each component of the [Vector2] by the given [float].
[codeblock]
2021-11-04 15:58:20 +00:00
print(2.5 * Vector2(1, 3)) # Prints "(2.5, 7.5)"
2021-01-06 00:13:11 +00:00
[/codeblock]
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator *" >
2022-02-03 21:16:58 +00:00
<return type= "Vector2" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Vector2i" />
2020-11-10 13:16:20 +00:00
<description >
2022-02-03 21:16:58 +00:00
Multiplies each component of the [Vector2i] by the given [float]. Returns a [Vector2].
2021-01-06 00:13:11 +00:00
[codeblock]
2022-02-03 21:16:58 +00:00
print(0.9 * Vector2i(10, 15)) # Prints "(9, 13.5)"
2021-01-06 00:13:11 +00:00
[/codeblock]
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator *" >
2021-07-30 13:28:05 +00:00
<return type= "Vector3" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Vector3" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Multiplies each component of the [Vector3] by the given [float].
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator *" >
2022-02-03 21:16:58 +00:00
<return type= "Vector3" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Vector3i" />
2020-11-10 13:16:20 +00:00
<description >
2022-02-03 21:16:58 +00:00
Multiplies each component of the [Vector3i] by the given [float]. Returns a [Vector3].
2021-11-04 15:58:20 +00:00
[codeblock]
2022-02-03 21:16:58 +00:00
print(0.9 * Vector3i(10, 15, 20)) # Prints "(9, 13.5, 18)"
2021-11-04 15:58:20 +00:00
[/codeblock]
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-19 23:11:13 +00:00
<operator name= "operator *" >
<return type= "Vector4" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Vector4" />
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-19 23:11:13 +00:00
<description >
2022-10-30 12:23:41 +00:00
Multiplies each component of the [Vector4] by the given [float].
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-19 23:11:13 +00:00
</description>
</operator>
<operator name= "operator *" >
<return type= "Vector4" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "Vector4i" />
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-19 23:11:13 +00:00
<description >
2022-10-30 12:23:41 +00:00
Multiplies each component of the [Vector4i] by the given [float]. Returns a [Vector4].
[codeblock]
print(0.9 * Vector4i(10, 15, 20, -10)) # Prints "(9, 13.5, 18, -9)"
[/codeblock]
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-19 23:11:13 +00:00
</description>
</operator>
2021-09-21 02:49:02 +00:00
<operator name= "operator *" >
2021-11-28 08:48:57 +00:00
<return type= "float" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "float" />
2020-11-10 13:16:20 +00:00
<description >
2021-11-28 08:48:57 +00:00
Multiplies two [float]s.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator *" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "int" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Multiplies a [float] and an [int]. The result is a [float].
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
2022-03-07 17:25:21 +00:00
<operator name= "operator **" >
<return type= "float" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "float" />
2022-03-07 17:25:21 +00:00
<description >
2022-10-30 12:23:41 +00:00
Raises a [float] to a power of a [float].
[codeblock]
print(39.0625**0.25) # 2.5
[/codeblock]
2022-03-07 17:25:21 +00:00
</description>
</operator>
<operator name= "operator **" >
<return type= "float" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "int" />
2022-03-07 17:25:21 +00:00
<description >
2022-10-30 12:23:41 +00:00
Raises a [float] to a power of an [int]. The result is a [float].
[codeblock]
print(0.9**3) # 0.729
[/codeblock]
2022-03-07 17:25:21 +00:00
</description>
</operator>
2021-09-21 02:49:02 +00:00
<operator name= "operator +" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "float" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Adds two floats.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator +" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "int" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Adds a [float] and an [int]. The result is a [float].
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator -" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "float" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Subtracts a float from a float.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator -" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "int" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Subtracts an [int] from a [float]. The result is a [float].
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator /" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "float" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Divides two floats.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator /" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "int" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Divides a [float] by an [int]. The result is a [float].
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator <" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "float" />
2020-11-10 13:16:20 +00:00
<description >
2022-10-20 02:09:17 +00:00
Returns [code]true[/code] if the left float is less than the right one.
2023-04-03 09:38:09 +00:00
[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.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator <" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "int" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Returns [code]true[/code] if this [float] is less than the given [int].
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator <=" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "float" />
2020-11-10 13:16:20 +00:00
<description >
2022-10-20 02:09:17 +00:00
Returns [code]true[/code] if the left float is less than or equal to the right one.
2023-04-03 09:38:09 +00:00
[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.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator <=" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "int" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Returns [code]true[/code] if this [float] is less than or equal to the given [int].
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator ==" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "float" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Returns [code]true[/code] if both floats are exactly equal.
[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.
2023-04-03 09:38:09 +00:00
[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.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator ==" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "int" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Returns [code]true[/code] if the [float] and the given [int] are equal.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator >" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "float" />
2020-11-10 13:16:20 +00:00
<description >
2022-10-20 02:09:17 +00:00
Returns [code]true[/code] if the left float is greater than the right one.
2023-04-03 09:38:09 +00:00
[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.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator >" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "int" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Returns [code]true[/code] if this [float] is greater than the given [int].
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator >=" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "float" />
2020-11-10 13:16:20 +00:00
<description >
2022-10-20 02:09:17 +00:00
Returns [code]true[/code] if the left float is greater than or equal to the right one.
2023-04-03 09:38:09 +00:00
[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.
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator >=" >
2021-07-30 13:28:05 +00:00
<return type= "bool" />
2022-08-06 18:11:48 +00:00
<param index= "0" name= "right" type= "int" />
2020-11-10 13:16:20 +00:00
<description >
2021-01-06 00:13:11 +00:00
Returns [code]true[/code] if this [float] is greater than or equal to the given [int].
2020-11-10 13:16:20 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator unary+" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2021-06-19 15:58:49 +00:00
<description >
2021-08-18 18:04:10 +00:00
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.
2021-06-19 15:58:49 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
<operator name= "operator unary-" >
2021-07-30 13:28:05 +00:00
<return type= "float" />
2021-06-19 15:58:49 +00:00
<description >
2021-08-18 18:04:10 +00:00
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.
2021-06-19 15:58:49 +00:00
</description>
2021-09-21 02:49:02 +00:00
</operator>
</operators>
2017-09-12 20:42:36 +00:00
</class>