:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/4.2/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/4.2/doc/classes/float.xml. .. _class_float: float ===== A built-in type for floating point numbers. .. rst-class:: classref-introduction-group Description ----------- The **float** built-in type is a 64-bit double-precision floating-point number, equivalent to ``double`` in C++. This type has 14 reliable decimal digits of precision. The maximum value of **float** is approximately ``1.79769e308``, and the minimum is approximately ``-1.79769e308``. Many methods and properties in the engine use 32-bit single-precision floating-point numbers instead, equivalent to ``float`` in C++, which have 6 reliable decimal digits of precision. For data structures such as :ref:`Vector2` and :ref:`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 ``precision=double`` option. Math done using the **float** type is not guaranteed to be exact and will often result in small errors. You should usually use the :ref:`@GlobalScope.is_equal_approx` and :ref:`@GlobalScope.is_zero_approx` methods instead of ``==`` to compare **float** values for equality. .. rst-class:: classref-introduction-group Tutorials --------- - `Wikipedia: Double-precision floating-point format `__ - `Wikipedia: Single-precision floating-point format `__ .. rst-class:: classref-reftable-group Constructors ------------ .. table:: :widths: auto +---------------------------+------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`float` **(** **)** | +---------------------------+------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`float` **(** :ref:`float` from **)** | +---------------------------+------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`float` **(** :ref:`String` from **)** | +---------------------------+------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`float` **(** :ref:`bool` from **)** | +---------------------------+------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`float` **(** :ref:`int` from **)** | +---------------------------+------------------------------------------------------------------------------------------+ .. rst-class:: classref-reftable-group Operators --------- .. table:: :widths: auto +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator !=` **(** :ref:`float` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator !=` **(** :ref:`int` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`Color` | :ref:`operator *` **(** :ref:`Color` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`Quaternion` | :ref:`operator *` **(** :ref:`Quaternion` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`operator *` **(** :ref:`Vector2` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`operator *` **(** :ref:`Vector2i` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`Vector3` | :ref:`operator *` **(** :ref:`Vector3` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`Vector3` | :ref:`operator *` **(** :ref:`Vector3i` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`Vector4` | :ref:`operator *` **(** :ref:`Vector4` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`Vector4` | :ref:`operator *` **(** :ref:`Vector4i` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`operator *` **(** :ref:`float` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`operator *` **(** :ref:`int` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`operator **` **(** :ref:`float` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`operator **` **(** :ref:`int` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`operator +` **(** :ref:`float` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`operator +` **(** :ref:`int` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`operator -` **(** :ref:`float` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`operator -` **(** :ref:`int` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`operator /` **(** :ref:`float` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`operator /` **(** :ref:`int` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator \<` **(** :ref:`float` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator \<` **(** :ref:`int` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator \<=` **(** :ref:`float` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator \<=` **(** :ref:`int` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator ==` **(** :ref:`float` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator ==` **(** :ref:`int` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator >` **(** :ref:`float` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator >` **(** :ref:`int` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator >=` **(** :ref:`float` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator >=` **(** :ref:`int` right **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`operator unary+` **(** **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`operator unary-` **(** **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Constructor Descriptions ------------------------ .. _class_float_constructor_float: .. rst-class:: classref-constructor :ref:`float` **float** **(** **)** Constructs a default-initialized **float** set to ``0.0``. .. rst-class:: classref-item-separator ---- .. rst-class:: classref-constructor :ref:`float` **float** **(** :ref:`float` from **)** Constructs a **float** as a copy of the given **float**. .. rst-class:: classref-item-separator ---- .. rst-class:: classref-constructor :ref:`float` **float** **(** :ref:`String` from **)** Converts a :ref:`String` to a **float**, following the same rules as :ref:`String.to_float`. .. rst-class:: classref-item-separator ---- .. rst-class:: classref-constructor :ref:`float` **float** **(** :ref:`bool` from **)** Cast a :ref:`bool` value to a floating-point value, ``float(true)`` will be equal to 1.0 and ``float(false)`` will be equal to 0.0. .. rst-class:: classref-item-separator ---- .. rst-class:: classref-constructor :ref:`float` **float** **(** :ref:`int` from **)** Cast an :ref:`int` value to a floating-point value, ``float(1)`` will be equal to ``1.0``. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Operator Descriptions --------------------- .. _class_float_operator_neq_float: .. rst-class:: classref-operator :ref:`bool` **operator !=** **(** :ref:`float` right **)** Returns ``true`` if two floats are different from each other. \ **Note:** :ref:`@GDScript.NAN` doesn't behave the same as other numbers. Therefore, the results from this operator may not be accurate if NaNs are included. .. rst-class:: classref-item-separator ---- .. _class_float_operator_neq_int: .. rst-class:: classref-operator :ref:`bool` **operator !=** **(** :ref:`int` right **)** Returns ``true`` if the integer has different value than the float. .. rst-class:: classref-item-separator ---- .. _class_float_operator_mul_Color: .. rst-class:: classref-operator :ref:`Color` **operator *** **(** :ref:`Color` right **)** Multiplies each component of the :ref:`Color`, including the alpha, by the given **float**. :: print(1.5 * Color(0.5, 0.5, 0.5)) # Prints "(0.75, 0.75, 0.75, 1.5)" .. rst-class:: classref-item-separator ---- .. _class_float_operator_mul_Quaternion: .. rst-class:: classref-operator :ref:`Quaternion` **operator *** **(** :ref:`Quaternion` right **)** Multiplies each component of the :ref:`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. .. rst-class:: classref-item-separator ---- .. _class_float_operator_mul_Vector2: .. rst-class:: classref-operator :ref:`Vector2` **operator *** **(** :ref:`Vector2` right **)** Multiplies each component of the :ref:`Vector2` by the given **float**. :: print(2.5 * Vector2(1, 3)) # Prints "(2.5, 7.5)" .. rst-class:: classref-item-separator ---- .. _class_float_operator_mul_Vector2i: .. rst-class:: classref-operator :ref:`Vector2` **operator *** **(** :ref:`Vector2i` right **)** Multiplies each component of the :ref:`Vector2i` by the given **float**. Returns a :ref:`Vector2`. :: print(0.9 * Vector2i(10, 15)) # Prints "(9, 13.5)" .. rst-class:: classref-item-separator ---- .. _class_float_operator_mul_Vector3: .. rst-class:: classref-operator :ref:`Vector3` **operator *** **(** :ref:`Vector3` right **)** Multiplies each component of the :ref:`Vector3` by the given **float**. .. rst-class:: classref-item-separator ---- .. _class_float_operator_mul_Vector3i: .. rst-class:: classref-operator :ref:`Vector3` **operator *** **(** :ref:`Vector3i` right **)** Multiplies each component of the :ref:`Vector3i` by the given **float**. Returns a :ref:`Vector3`. :: print(0.9 * Vector3i(10, 15, 20)) # Prints "(9, 13.5, 18)" .. rst-class:: classref-item-separator ---- .. _class_float_operator_mul_Vector4: .. rst-class:: classref-operator :ref:`Vector4` **operator *** **(** :ref:`Vector4` right **)** Multiplies each component of the :ref:`Vector4` by the given **float**. .. rst-class:: classref-item-separator ---- .. _class_float_operator_mul_Vector4i: .. rst-class:: classref-operator :ref:`Vector4` **operator *** **(** :ref:`Vector4i` right **)** Multiplies each component of the :ref:`Vector4i` by the given **float**. Returns a :ref:`Vector4`. :: print(0.9 * Vector4i(10, 15, 20, -10)) # Prints "(9, 13.5, 18, -9)" .. rst-class:: classref-item-separator ---- .. _class_float_operator_mul_float: .. rst-class:: classref-operator :ref:`float` **operator *** **(** :ref:`float` right **)** Multiplies two **float**\ s. .. rst-class:: classref-item-separator ---- .. _class_float_operator_mul_int: .. rst-class:: classref-operator :ref:`float` **operator *** **(** :ref:`int` right **)** Multiplies a **float** and an :ref:`int`. The result is a **float**. .. rst-class:: classref-item-separator ---- .. _class_float_operator_pow_float: .. rst-class:: classref-operator :ref:`float` **operator **** **(** :ref:`float` right **)** Raises a **float** to a power of a **float**. :: print(39.0625**0.25) # 2.5 .. rst-class:: classref-item-separator ---- .. _class_float_operator_pow_int: .. rst-class:: classref-operator :ref:`float` **operator **** **(** :ref:`int` right **)** Raises a **float** to a power of an :ref:`int`. The result is a **float**. :: print(0.9**3) # 0.729 .. rst-class:: classref-item-separator ---- .. _class_float_operator_sum_float: .. rst-class:: classref-operator :ref:`float` **operator +** **(** :ref:`float` right **)** Adds two floats. .. rst-class:: classref-item-separator ---- .. _class_float_operator_sum_int: .. rst-class:: classref-operator :ref:`float` **operator +** **(** :ref:`int` right **)** Adds a **float** and an :ref:`int`. The result is a **float**. .. rst-class:: classref-item-separator ---- .. _class_float_operator_dif_float: .. rst-class:: classref-operator :ref:`float` **operator -** **(** :ref:`float` right **)** Subtracts a float from a float. .. rst-class:: classref-item-separator ---- .. _class_float_operator_dif_int: .. rst-class:: classref-operator :ref:`float` **operator -** **(** :ref:`int` right **)** Subtracts an :ref:`int` from a **float**. The result is a **float**. .. rst-class:: classref-item-separator ---- .. _class_float_operator_div_float: .. rst-class:: classref-operator :ref:`float` **operator /** **(** :ref:`float` right **)** Divides two floats. .. rst-class:: classref-item-separator ---- .. _class_float_operator_div_int: .. rst-class:: classref-operator :ref:`float` **operator /** **(** :ref:`int` right **)** Divides a **float** by an :ref:`int`. The result is a **float**. .. rst-class:: classref-item-separator ---- .. _class_float_operator_lt_float: .. rst-class:: classref-operator :ref:`bool` **operator <** **(** :ref:`float` right **)** Returns ``true`` if the left float is less than the right one. \ **Note:** :ref:`@GDScript.NAN` doesn't behave the same as other numbers. Therefore, the results from this operator may not be accurate if NaNs are included. .. rst-class:: classref-item-separator ---- .. _class_float_operator_lt_int: .. rst-class:: classref-operator :ref:`bool` **operator <** **(** :ref:`int` right **)** Returns ``true`` if this **float** is less than the given :ref:`int`. .. rst-class:: classref-item-separator ---- .. _class_float_operator_lte_float: .. rst-class:: classref-operator :ref:`bool` **operator <=** **(** :ref:`float` right **)** Returns ``true`` if the left float is less than or equal to the right one. \ **Note:** :ref:`@GDScript.NAN` doesn't behave the same as other numbers. Therefore, the results from this operator may not be accurate if NaNs are included. .. rst-class:: classref-item-separator ---- .. _class_float_operator_lte_int: .. rst-class:: classref-operator :ref:`bool` **operator <=** **(** :ref:`int` right **)** Returns ``true`` if this **float** is less than or equal to the given :ref:`int`. .. rst-class:: classref-item-separator ---- .. _class_float_operator_eq_float: .. rst-class:: classref-operator :ref:`bool` **operator ==** **(** :ref:`float` right **)** Returns ``true`` if both floats are exactly equal. \ **Note:** Due to floating-point precision errors, consider using :ref:`@GlobalScope.is_equal_approx` or :ref:`@GlobalScope.is_zero_approx` instead, which are more reliable. \ **Note:** :ref:`@GDScript.NAN` doesn't behave the same as other numbers. Therefore, the results from this operator may not be accurate if NaNs are included. .. rst-class:: classref-item-separator ---- .. _class_float_operator_eq_int: .. rst-class:: classref-operator :ref:`bool` **operator ==** **(** :ref:`int` right **)** Returns ``true`` if the **float** and the given :ref:`int` are equal. .. rst-class:: classref-item-separator ---- .. _class_float_operator_gt_float: .. rst-class:: classref-operator :ref:`bool` **operator >** **(** :ref:`float` right **)** Returns ``true`` if the left float is greater than the right one. \ **Note:** :ref:`@GDScript.NAN` doesn't behave the same as other numbers. Therefore, the results from this operator may not be accurate if NaNs are included. .. rst-class:: classref-item-separator ---- .. _class_float_operator_gt_int: .. rst-class:: classref-operator :ref:`bool` **operator >** **(** :ref:`int` right **)** Returns ``true`` if this **float** is greater than the given :ref:`int`. .. rst-class:: classref-item-separator ---- .. _class_float_operator_gte_float: .. rst-class:: classref-operator :ref:`bool` **operator >=** **(** :ref:`float` right **)** Returns ``true`` if the left float is greater than or equal to the right one. \ **Note:** :ref:`@GDScript.NAN` doesn't behave the same as other numbers. Therefore, the results from this operator may not be accurate if NaNs are included. .. rst-class:: classref-item-separator ---- .. _class_float_operator_gte_int: .. rst-class:: classref-operator :ref:`bool` **operator >=** **(** :ref:`int` right **)** Returns ``true`` if this **float** is greater than or equal to the given :ref:`int`. .. rst-class:: classref-item-separator ---- .. _class_float_operator_unplus: .. rst-class:: classref-operator :ref:`float` **operator unary+** **(** **)** Returns the same value as if the ``+`` was not there. Unary ``+`` does nothing, but sometimes it can make your code more readable. .. rst-class:: classref-item-separator ---- .. _class_float_operator_unminus: .. rst-class:: classref-operator :ref:`float` **operator unary-** **(** **)** 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. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)` .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)` .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`