mirror of
https://github.com/Relintai/pandemonium_engine_docs.git
synced 2025-01-21 15:07:22 +01:00
65 lines
3.9 KiB
ReStructuredText
65 lines
3.9 KiB
ReStructuredText
|
: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/<name>/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<class_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``.
|
||
|
|
||
|
Most 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<class_Vector2>` and :ref:`Vector3<class_Vector3>`, Godot uses 32-bit floating-point numbers.
|
||
|
|
||
|
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:`@GDScript.is_equal_approx<class_@GDScript_method_is_equal_approx>` and :ref:`@GDScript.is_zero_approx<class_@GDScript_method_is_zero_approx>` methods instead of ``==`` to compare ``float`` values for equality.
|
||
|
|
||
|
Tutorials
|
||
|
---------
|
||
|
|
||
|
- `Wikipedia: Double-precision floating-point format <https://en.wikipedia.org/wiki/Double-precision_floating-point_format>`__
|
||
|
|
||
|
- `Wikipedia: Single-precision floating-point format <https://en.wikipedia.org/wiki/Single-precision_floating-point_format>`__
|
||
|
|
||
|
Methods
|
||
|
-------
|
||
|
|
||
|
+---------------------------+-------------------------------------------------------------------------------------+
|
||
|
| :ref:`float<class_float>` | :ref:`float<class_float_method_float>` **(** :ref:`bool<class_bool>` from **)** |
|
||
|
+---------------------------+-------------------------------------------------------------------------------------+
|
||
|
| :ref:`float<class_float>` | :ref:`float<class_float_method_float>` **(** :ref:`int<class_int>` from **)** |
|
||
|
+---------------------------+-------------------------------------------------------------------------------------+
|
||
|
| :ref:`float<class_float>` | :ref:`float<class_float_method_float>` **(** :ref:`String<class_String>` from **)** |
|
||
|
+---------------------------+-------------------------------------------------------------------------------------+
|
||
|
|
||
|
Method Descriptions
|
||
|
-------------------
|
||
|
|
||
|
.. _class_float_method_float:
|
||
|
|
||
|
- :ref:`float<class_float>` **float** **(** :ref:`bool<class_bool>` from **)**
|
||
|
|
||
|
Cast a :ref:`bool<class_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<class_float>` **float** **(** :ref:`int<class_int>` from **)**
|
||
|
|
||
|
Cast an :ref:`int<class_int>` value to a floating-point value, ``float(1)`` will be equal to 1.0.
|
||
|
|
||
|
----
|
||
|
|
||
|
- :ref:`float<class_float>` **float** **(** :ref:`String<class_String>` from **)**
|
||
|
|
||
|
Cast a :ref:`String<class_String>` value to a floating-point value. This method accepts float value strings like ``"1.23"`` and exponential notation strings for its parameter so calling ``float("1e3")`` will return 1000.0 and calling ``float("1e-3")`` will return 0.001. Calling this method with an invalid float string will return 0. This method stops parsing at the first invalid character and will return the parsed result so far, so calling ``float("1a3")`` will return 1 while calling ``float("1e3a2")`` will return 1000.0.
|
||
|
|
||
|
.. |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.)`
|