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 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 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 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 @GlobalScope.is_equal_approx and @GlobalScope.is_zero_approx methods instead of == to compare float values for equality.

Methods

float

float ( ) constructor

float

float ( float from ) constructor

float

float ( bool from ) constructor

float

float ( int from ) constructor

bool

operator != ( ) operator

bool

operator != ( float right ) operator

bool

operator != ( int right ) operator

float

operator * ( float right ) operator

Vector2

operator * ( Vector2 right ) operator

Vector2i

operator * ( Vector2i right ) operator

Vector3

operator * ( Vector3 right ) operator

Vector3i

operator * ( Vector3i right ) operator

Quaternion

operator * ( Quaternion right ) operator

Color

operator * ( Color right ) operator

float

operator * ( int right ) operator

float

operator + ( float right ) operator

float

operator + ( int right ) operator

float

operator - ( float right ) operator

float

operator - ( int right ) operator

float

operator / ( float right ) operator

float

operator / ( int right ) operator

bool

operator < ( float right ) operator

bool

operator < ( int right ) operator

bool

operator <= ( float right ) operator

bool

operator <= ( int right ) operator

bool

operator == ( ) operator

bool

operator == ( float right ) operator

bool

operator == ( int right ) operator

bool

operator > ( float right ) operator

bool

operator > ( int right ) operator

bool

operator >= ( float right ) operator

bool

operator >= ( int right ) operator

float

operator unary+ ( ) operator

float

operator unary- ( ) operator

Method Descriptions

  • float float ( ) constructor

Constructs a default-initialized float set to 0.0.


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 1.0.


  • bool operator != ( ) operator


Returns true if two floats are different from each other.


  • bool operator != ( int right ) operator

Returns true if the integer has different value than the float.


Multiplies two floats.


Multiplies each component of the Vector2 by the given float.

print(2.5 * Vector2(1, 1)) # Vector2(2.5, 2.5)

Multiplies each component of the Vector2i by the given float.

print(2.0 * Vector2i(1, 1)) # Vector2i(2.0, 2.0)

Multiplies each component of the Vector3 by the given float.


Multiplies each component of the Vector3i by the given float.


Multiplies each component of the Quaternion by the given float.


Multiplies each component of the Color by the given float.

print(1.5 * Color(0.5, 0.5, 0.5)) # Color(0.75, 0.75, 0.75)

  • float operator * ( int right ) operator

Multiplies a float and an int. The result is a float.


Adds two floats.


  • float operator + ( int right ) operator

Adds a float and an int. The result is a float.


Subtracts a float from a float.


  • float operator - ( int right ) operator

Subtracts an int from a float. The result is a float.


Divides two floats.


  • float operator / ( int right ) operator

Divides a float by an int. The result is a float.


Returns true the left float is less than the right one.


  • bool operator < ( int right ) operator

Returns true if this float is less than the given int.


Returns true the left integer is less than or equal to the right one.


  • bool operator <= ( int right ) operator

Returns true if this float is less than or equal to the given int.


  • bool operator == ( ) operator


Returns true if both floats are exactly equal.

Note: Due to floating-point precision errors, consider using @GlobalScope.is_equal_approx or @GlobalScope.is_zero_approx instead, which are more reliable.


  • bool operator == ( int right ) operator

Returns true if the float and the given int are equal.


Returns true the left float is greater than the right one.


  • bool operator > ( int right ) operator

Returns true if this float is greater than the given int.


Returns true the left float is greater than or equal to the right one.


  • bool operator >= ( int right ) operator

Returns true if this float is greater than or equal to the given int.


  • float operator unary+ ( ) operator

Returns the same value as if the + was not there. Unary + does nothing, but sometimes it can make your code more readable.


  • float operator unary- ( ) operator

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.