class_float.rst 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/float.xml.
  6. .. _class_float:
  7. float
  8. =====
  9. Float built-in type.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. 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``.
  14. 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.
  15. 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.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - `Wikipedia: Double-precision floating-point format <https://en.wikipedia.org/wiki/Double-precision_floating-point_format>`__
  20. - `Wikipedia: Single-precision floating-point format <https://en.wikipedia.org/wiki/Single-precision_floating-point_format>`__
  21. .. rst-class:: classref-reftable-group
  22. Methods
  23. -------
  24. .. table::
  25. :widths: auto
  26. +---------------------------+-------------------------------------------------------------------------------------+
  27. | :ref:`float<class_float>` | :ref:`float<class_float_method_float>` **(** :ref:`bool<class_bool>` from **)** |
  28. +---------------------------+-------------------------------------------------------------------------------------+
  29. | :ref:`float<class_float>` | :ref:`float<class_float_method_float>` **(** :ref:`int<class_int>` from **)** |
  30. +---------------------------+-------------------------------------------------------------------------------------+
  31. | :ref:`float<class_float>` | :ref:`float<class_float_method_float>` **(** :ref:`String<class_String>` from **)** |
  32. +---------------------------+-------------------------------------------------------------------------------------+
  33. .. rst-class:: classref-section-separator
  34. ----
  35. .. rst-class:: classref-descriptions-group
  36. Method Descriptions
  37. -------------------
  38. .. _class_float_method_float:
  39. .. rst-class:: classref-method
  40. :ref:`float<class_float>` **float** **(** :ref:`bool<class_bool>` from **)**
  41. 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.
  42. .. rst-class:: classref-item-separator
  43. ----
  44. .. rst-class:: classref-method
  45. :ref:`float<class_float>` **float** **(** :ref:`int<class_int>` from **)**
  46. Cast an :ref:`int<class_int>` value to a floating-point value, ``float(1)`` will be equal to 1.0.
  47. .. rst-class:: classref-item-separator
  48. ----
  49. .. rst-class:: classref-method
  50. :ref:`float<class_float>` **float** **(** :ref:`String<class_String>` from **)**
  51. 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.
  52. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  53. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  54. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  55. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`