Attention: Here be dragons
This is the
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
A built-in type for floating point numbers.
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
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 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
Math done using the float type is not guaranteed to be exact and will often result in small errors. You should usually use the @GlobalScope.is_equal_approx and @GlobalScope.is_zero_approx methods instead of
== to compare float values for equality.
float ( )
operator unary+ ( )
operator unary- ( )
float float ( )
Constructs a default-initialized float set to
Constructs a float as a copy of the given float.
Cast a bool value to a floating-point value,
float(true) will be equal to 1.0 and
float(false) will be equal to 0.0.
Cast an int value to a floating-point value,
float(1) will be equal to
true if two floats are different from each other.
Note: @GDScript.NAN doesn't behave the same as other numbers. Therefore, the results from this operator may not be accurate if NaNs are included.
true if the integer has different value than the float.
Multiplies each component of the 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)"
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.
Multiplies each component of the Vector2 by the given float.
print(2.5 * Vector2(1, 3)) # Prints "(2.5, 7.5)"
print(0.9 * Vector2i(10, 15)) # Prints "(9, 13.5)"
Multiplies each component of the Vector3 by the given float.
print(0.9 * Vector3i(10, 15, 20)) # Prints "(9, 13.5, 18)"
Multiplies each component of the Vector4 by the given float.
print(0.9 * Vector4i(10, 15, 20, -10)) # Prints "(9, 13.5, 18, -9)"
Multiplies two floats.
Multiplies a float and an int. The result is a float.
Raises a float to a power of a float.
print(39.0625**0.25) # 2.5
Raises a float to a power of an int. The result is a float.
print(0.9**3) # 0.729
Adds two floats.
Adds a float and an int. The result is a float.
Subtracts a float from a float.