Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

float

Un tipo incorporado para números de punto float.

Descripción

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 -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 precision=double option.

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.

Note: In a boolean context, a float will evaluate to false if it's exactly equal to 0.0, and to true otherwise.

Tutoriales

Constructores

float

float()

float

float(from: float)

float

float(from: String)

float

float(from: bool)

float

float(from: int)

Operadores

bool

operator !=(right: float)

bool

operator !=(right: int)

Color

operator *(right: Color)

Quaternion

operator *(right: Quaternion)

Vector2

operator *(right: Vector2)

Vector2

operator *(right: Vector2i)

Vector3

operator *(right: Vector3)

Vector3

operator *(right: Vector3i)

Vector4

operator *(right: Vector4)

Vector4

operator *(right: Vector4i)

float

operator *(right: float)

float

operator *(right: int)

float

operator **(right: float)

float

operator **(right: int)

float

operator +(right: float)

float

operator +(right: int)

float

operator -(right: float)

float

operator -(right: int)

float

operator /(right: float)

float

operator /(right: int)

bool

operator <(right: float)

bool

operator <(right: int)

bool

operator <=(right: float)

bool

operator <=(right: int)

bool

operator ==(right: float)

bool

operator ==(right: int)

bool

operator >(right: float)

bool

operator >(right: int)

bool

operator >=(right: float)

bool

operator >=(right: int)

float

operator unary+()

float

operator unary-()


Descripciones de Constructores

float float() 🔗

Construye un float inicializado por defecto establecido en 0.0.


float float(from: float)

Construye un float como una copia del float dado.


float float(from: String)

Convierte un String a un float, siguiendo las mismas reglas que String.to_float().


float float(from: bool)

Convierte un valor bool a un valor de real, float(true) será igual a 1.0 y float(false) será igual a 0.0.


float float(from: int)

Convierte un valor int a un valor de punto flotante, float(1) será igual a 1.0.


Descripciones de Operadores

bool operator !=(right: float) 🔗

Devuelve true si dos floats son diferentes entre sí.

Nota: @GDScript.NAN no se comporta igual que otros números. Por lo tanto, los resultados de este operador pueden no ser precisos si se incluyen NaN.


bool operator !=(right: int) 🔗

Devuelve true si el entero tiene un valor diferente al float.


Color operator *(right: Color) 🔗

Multiplica cada componente del Color, incluido el alfa, por el float dado.

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

Quaternion operator *(right: Quaternion) 🔗

Multiplica cada componente del Quaternion por el float dado. Esta operación no es significativa por sí sola, pero puede usarse como parte de una expresión mayor.


Vector2 operator *(right: Vector2) 🔗

Multiplica cada componente del Vector2 por el float dado.

print(2.5 * Vector2(1, 3)) # Imprime (2.5, 7.5)

Vector2 operator *(right: Vector2i) 🔗

Multiplica cada componente de Vector2i por el float dado. Devuelve un Vector2.

print(0.9 * Vector2i(10, 15)) # Imprime (9.0, 13.5)

Vector3 operator *(right: Vector3) 🔗

Multiplica cada componente del Vector3 por el float dado.


Vector3 operator *(right: Vector3i) 🔗

Multiplica cada componente del Vector3i por el float dado. Devuelve un Vector3.

print(0.9 * Vector3i(10, 15, 20)) # Imprime (9.0, 13.5, 18.0)

Vector4 operator *(right: Vector4) 🔗

Multiplica cada componente del Vector4 por el float dado.


Vector4 operator *(right: Vector4i) 🔗

Multiplica cada componente del Vector4i por el float dado. Devuelve un Vector4

print(0.9 * Vector4i(10, 15, 20, -10)) # Imprime (9.0, 13.5, 18.0, -9.0)

float operator *(right: float) 🔗

Multiplica dos floats.


float operator *(right: int) 🔗

Multiplica un float y un int. El resultado es un float.


float operator **(right: float) 🔗

Eleva un float a una potencia de un float.

print(39.0625**0.25) # 2.5

float operator **(right: int) 🔗

Eleva un float a una potencia de un int. El resultado es un float.

print(0.9**3) # 0.729

float operator +(right: float) 🔗

Añade dos floats.


float operator +(right: int) 🔗

Suma un float y un int. El resultado es un float.


float operator -(right: float) 🔗

Resta un float de un float.


float operator -(right: int) 🔗

Resta un int de un float. El resultado es un float.


float operator /(right: float) 🔗

Divide dos floats.


float operator /(right: int) 🔗

Divide un float por un int. El resultado es un float.


bool operator <(right: float) 🔗

Devuelve true si el float de la izquierda es menor que el de la derecha.

Nota: @GDScript.NAN no se comporta igual que otros números. Por lo tanto, los resultados de este operador pueden no ser precisos si se incluyen NaN.


bool operator <(right: int) 🔗

Devuelve true si este float es menor que el int dado.


bool operator <=(right: float) 🔗

Devuelve true si el float de la izquierda es menor o igual que el de la derecha.

Nota: @GDScript.NAN no se comporta igual que otros números. Por lo tanto, los resultados de este operador pueden no ser precisos si se incluyen NaN.


bool operator <=(right: int) 🔗

Devuelve true si este float es menor o igual que el int dado.


bool operator ==(right: float) 🔗

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.

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.


bool operator ==(right: int) 🔗

Devuelve true si el float y el int dado son iguales.


bool operator >(right: float) 🔗

Devuelve true si el float de la izquierda es mayor que el de la derecha.

Nota: @GDScript.NAN no se comporta igual que otros números. Por lo tanto, los resultados de este operador pueden no ser precisos si se incluyen NaN.


bool operator >(right: int) 🔗

Devuelve true si este float es mayor que el int dado.


bool operator >=(right: float) 🔗

Devuelve true si el float de la izquierda es mayor o igual que el de la derecha.

Nota: @GDScript.NAN no se comporta igual que otros números. Por lo tanto, los resultados de este operador pueden no ser precisos si se incluyen NaN.


bool operator >=(right: int) 🔗

Devuelve true si este float es mayor o igual que el int dado.


float operator unary+() 🔗

Devuelve el mismo valor como si el + no estuviera ahí. El + unario no hace nada, pero a veces puede hacer que tu código sea más legible.


float operator unary-() 🔗

Devuelve el valor negativo del float. Si es positivo, convierte el número en negativo. Si es negativo, convierte el número en positivo. Con los floats, el número cero puede ser positivo o negativo.