:github_url: hide .. Generated automatically by doc/tools/make_rst.py in Godot's source tree. .. DO NOT EDIT THIS FILE, but the float.xml source instead. .. The source is found in doc/classes or modules//doc_classes. .. _class_float: float ===== Float built-in type. 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 ``float`` type can be stored in :ref:`Variant`, which is the generic type used by the engine. 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 ``float=64`` option. 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 :ref:`@GlobalScope.is_equal_approx` and :ref:`@GlobalScope.is_zero_approx` methods instead of ``==`` to compare ``float`` values for equality. Tutorials --------- - `Wikipedia: Double-precision floating-point format `__ - `Wikipedia: Single-precision floating-point format `__ Constructors ------------ +---------------------------+----------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`float` **(** **)** | +---------------------------+----------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`float` **(** :ref:`float` from **)** | +---------------------------+----------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`float` **(** :ref:`bool` from **)** | +---------------------------+----------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`float` **(** :ref:`int` from **)** | +---------------------------+----------------------------------------------------------------------------------------+ Operators --------- +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator !=` **(** **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ | :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:`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:`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-` **(** **)** | +-------------------------------------+--------------------------------------------------------------------------------------------------------------+ Constructor Descriptions ------------------------ .. _class_float_constructor_float: - :ref:`float` **float** **(** **)** Constructs a default-initialized ``float`` set to ``0.0``. ---- - :ref:`float` **float** **(** :ref:`float` from **)** Constructs a ``float`` as a copy of the given ``float``. ---- - :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. ---- - :ref:`float` **float** **(** :ref:`int` from **)** Cast an :ref:`int` value to a floating-point value, ``float(1)`` will be equal to ``1.0``. Operator Descriptions --------------------- .. _class_float_operator_neq_bool: - :ref:`bool` **operator !=** **(** **)** ---- - :ref:`bool` **operator !=** **(** :ref:`float` right **)** Returns ``true`` if two floats are different from each other. ---- - :ref:`bool` **operator !=** **(** :ref:`int` right **)** Returns ``true`` if the integer has different value than the float. ---- .. _class_float_operator_mul_Color: - :ref:`Color` **operator *** **(** :ref:`Color` right **)** Multiplies each component of the :ref:`Color` by the given ``float``. :: print(1.5 * Color(0.5, 0.5, 0.5)) # Color(0.75, 0.75, 0.75) ---- - :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. ---- - :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)" ---- - :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)" ---- - :ref:`Vector3` **operator *** **(** :ref:`Vector3` right **)** Multiplies each component of the :ref:`Vector3` by the given ``float``. ---- - :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)" ---- - :ref:`float` **operator *** **(** :ref:`float` right **)** Multiplies two ``float``\ s. ---- - :ref:`float` **operator *** **(** :ref:`int` right **)** Multiplies a ``float`` and an :ref:`int`. The result is a ``float``. ---- .. _class_float_operator_sum_float: - :ref:`float` **operator +** **(** :ref:`float` right **)** Adds two floats. ---- - :ref:`float` **operator +** **(** :ref:`int` right **)** Adds a ``float`` and an :ref:`int`. The result is a ``float``. ---- .. _class_float_operator_dif_float: - :ref:`float` **operator -** **(** :ref:`float` right **)** Subtracts a float from a float. ---- - :ref:`float` **operator -** **(** :ref:`int` right **)** Subtracts an :ref:`int` from a ``float``. The result is a ``float``. ---- .. _class_float_operator_div_float: - :ref:`float` **operator /** **(** :ref:`float` right **)** Divides two floats. ---- - :ref:`float` **operator /** **(** :ref:`int` right **)** Divides a ``float`` by an :ref:`int`. The result is a ``float``. ---- .. _class_float_operator_lt_bool: - :ref:`bool` **operator <** **(** :ref:`float` right **)** Returns ``true`` the left float is less than the right one. ---- - :ref:`bool` **operator <** **(** :ref:`int` right **)** Returns ``true`` if this ``float`` is less than the given :ref:`int`. ---- .. _class_float_operator_lte_bool: - :ref:`bool` **operator <=** **(** :ref:`float` right **)** Returns ``true`` the left integer is less than or equal to the right one. ---- - :ref:`bool` **operator <=** **(** :ref:`int` right **)** Returns ``true`` if this ``float`` is less than or equal to the given :ref:`int`. ---- .. _class_float_operator_eq_bool: - :ref:`bool` **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. ---- - :ref:`bool` **operator ==** **(** :ref:`int` right **)** Returns ``true`` if the ``float`` and the given :ref:`int` are equal. ---- .. _class_float_operator_gt_bool: - :ref:`bool` **operator >** **(** :ref:`float` right **)** Returns ``true`` the left float is greater than the right one. ---- - :ref:`bool` **operator >** **(** :ref:`int` right **)** Returns ``true`` if this ``float`` is greater than the given :ref:`int`. ---- .. _class_float_operator_gte_bool: - :ref:`bool` **operator >=** **(** :ref:`float` right **)** Returns ``true`` the left float is greater than or equal to the right one. ---- - :ref:`bool` **operator >=** **(** :ref:`int` right **)** Returns ``true`` if this ``float`` is greater than or equal to the given :ref:`int`. ---- .. _class_float_operator_unplus_float: - :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. ---- .. _class_float_operator_unminus_float: - :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.)`