Provides constants and static methods for common mathematical functions.
Static variables
staticread onlyEPSILON:Single
A very small number used for float comparison with error tolerance.
1e-06 with single-precision floats, but 1e-14 if REAL_T_IS_DOUBLE
.
staticread onlyNA_N:Single
"Not a Number", an invalid value. NaN
has special properties, including
that it is not equal to itself. It is output by some invalid operations,
such as dividing zero by zero.
Static methods
staticabs(s:Int):Int
staticAbs(s:Single):Single
Returns the absolute value of s
(i.e. positive value).
Parameters:
s | The input number. |
---|
Returns:
The absolute value of s
.
staticacos(s:Single):Single
Returns the arc cosine of s
in radians.
Use to get the angle of cosine s
.
Parameters:
s | The input cosine value. Must be on the range of -1.0 to 1.0. |
---|
Returns:
An angle that would result in the given cosine value. On the range 0
to Tau/2
.
staticasin(s:Single):Single
Returns the arc sine of s
in radians.
Use to get the angle of sine s
.
Parameters:
s | The input sine value. Must be on the range of -1.0 to 1.0. |
---|
Returns:
An angle that would result in the given sine value. On the range -Tau/4
to Tau/4
.
staticatan(s:Single):Single
Returns the arc tangent of s
in radians.
Use to get the angle of tangent s
.
The method cannot know in which quadrant the angle should fall.
See godot.Mathf.atan2
if you have both y
and x
.
Parameters:
s | The input tangent value. |
---|
Returns:
An angle that would result in the given tangent value. On the range -Tau/4
to Tau/4
.
staticatan2(y:Single, x:Single):Single
Returns the arc tangent of y
and x
in radians.
Use to get the angle of the tangent of y/x
. To compute the value, the method takes into
account the sign of both arguments in order to determine the quadrant.
Important note: The Y coordinate comes first, by convention.
Parameters:
y | The Y coordinate of the point to find the angle to. |
---|---|
x | The X coordinate of the point to find the angle to. |
Returns:
An angle that would result in the given tangent value. On the range -Tau/2
to Tau/2
.
staticcartesian2Polar(x:Single, y:Single):Vector2
Converts a 2D point expressed in the cartesian coordinate system (X and Y axis) to the polar coordinate system (a distance from the origin and an angle).
Parameters:
x | The input X coordinate. |
---|---|
y | The input Y coordinate. |
Returns:
A godot.Vector2
with X representing the distance and Y representing the angle.
staticceil(s:Single):Single
Rounds s
upward (towards positive infinity).
Parameters:
s | The number to ceil. |
---|
Returns:
The smallest whole number that is not less than s
.
staticceilToInt(s:Single):Int
Rounds s
upward (towards positive infinity).
This is the same as godot.Mathf.ceil
, but returns an int
.
Parameters:
s | The number to ceil. |
---|
Returns:
The smallest whole number that is not less than s
.
staticclamp(value:Int, min:Int, max:Int):Int
staticClamp(value:Single, min:Single, max:Single):Single
Clamps a value
so that it is not less than min
and not more than max
.
Parameters:
value | The value to clamp. |
---|---|
min | The minimum allowed value. |
max | The maximum allowed value. |
Returns:
The clamped value.
staticcos(s:Single):Single
Returns the cosine of angle s
in radians.
Parameters:
s | The angle in radians. |
---|
Returns:
The cosine of that angle.
staticcosh(s:Single):Single
Returns the hyperbolic cosine of angle s
in radians.
Parameters:
s | The angle in radians. |
---|
Returns:
The hyperbolic cosine of that angle.
staticdecimalCount(s:Single):Int
staticDecimalCount(s:Decimal):Int
Returns the amount of digits after the decimal place.
Parameters:
s | The input value. |
---|
Returns:
The amount of digits.
staticdeg2Rad(deg:Single):Single
Converts an angle expressed in degrees to radians.
Parameters:
deg | An angle expressed in degrees. |
---|
Returns:
The same angle expressed in radians.
staticease(s:Single, curve:Single):Single
Easing function, based on exponent. The curve
values are:
0
is constant, 1
is linear, 0
to 1
is ease-in, 1
or more is ease-out.
Negative values are in-out/out-in.
Parameters:
s | The value to ease. |
---|---|
curve |
|
Returns:
The eased value.
staticexp(s:Single):Single
The natural exponential function. It raises the mathematical
constant e
to the power of s
and returns it.
Parameters:
s | The exponent to raise |
---|
Returns:
e
raised to the power of s
.
staticfloor(s:Single):Single
Rounds s
downward (towards negative infinity).
Parameters:
s | The number to floor. |
---|
Returns:
The largest whole number that is not more than s
.
staticfloorToInt(s:Single):Int
Rounds s
downward (towards negative infinity).
This is the same as godot.Mathf.floor
, but returns an int
.
Parameters:
s | The number to floor. |
---|
Returns:
The largest whole number that is not more than s
.
staticinverseLerp(from:Single, to:Single, weight:Single):Single
Returns a normalized value considering the given range.
This is the opposite of godot.Mathf.lerp
.
Parameters:
from | The interpolated value. |
---|---|
to | The destination value for interpolation. |
weight | A value on the range of 0.0 to 1.0, representing the amount of interpolation. |
Returns:
The resulting value of the inverse interpolation.
staticisEqualApprox(a:Single, b:Single):Bool
staticIsEqualApprox(a:Single, b:Single, tolerance:Single):Bool
Returns true
if a
and b
are approximately equal
to each other.
The comparison is done using a tolerance calculation with godot.Mathf.EPSILON
.
Parameters:
a | One of the values. |
---|---|
b | The other value. |
Returns:
A bool
for whether or not the two values are approximately equal.
staticisInf(s:Single):Bool
Returns whether s
is an infinity value (either positive infinity or negative infinity).
Parameters:
s | The value to check. |
---|
Returns:
A bool
for whether or not the value is an infinity value.
staticisNaN(s:Single):Bool
Returns whether s
is a NaN
("Not a Number" or invalid) value.
Parameters:
s | The value to check. |
---|
Returns:
A bool
for whether or not the value is a NaN
value.
staticisZeroApprox(s:Single):Bool
Returns true
if s
is approximately zero.
The comparison is done using a tolerance calculation with godot.Mathf.EPSILON
.
This method is faster than using godot.Mathf.isEqualApprox
with one value as zero.
Parameters:
s | The value to check. |
---|
Returns:
A bool
for whether or not the value is nearly zero.
staticlerp(from:Single, to:Single, weight:Single):Single
Linearly interpolates between two values by a normalized value.
This is the opposite godot.Mathf.inverseLerp
.
Parameters:
from | The start value for interpolation. |
---|---|
to | The destination value for interpolation. |
weight | A value on the range of 0.0 to 1.0, representing the amount of interpolation. |
Returns:
The resulting value of the interpolation.
staticlerpAngle(from:Single, to:Single, weight:Single):Single
Linearly interpolates between two angles (in radians) by a normalized value.
Similar to godot.Mathf.lerp
,
but interpolates correctly when the angles wrap around godot.Mathf.TAU
.
Parameters:
from | The start angle for interpolation. |
---|---|
to | The destination angle for interpolation. |
weight | A value on the range of 0.0 to 1.0, representing the amount of interpolation. |
Returns:
The resulting angle of the interpolation.
staticlog(s:Single):Single
Natural logarithm. The amount of time needed to reach a certain level of continuous growth.
Note: This is not the same as the "log" function on most calculators, which uses a base 10 logarithm.
Parameters:
s | The input value. |
---|
Returns:
The natural log of s
.
staticmax(a:Int, b:Int):Int
staticMax(a:Single, b:Single):Single
Returns the maximum of two values.
Parameters:
a | One of the values. |
---|---|
b | The other value. |
Returns:
Whichever of the two values is higher.
staticmin(a:Int, b:Int):Int
staticMin(a:Single, b:Single):Single
Returns the minimum of two values.
Parameters:
a | One of the values. |
---|---|
b | The other value. |
Returns:
Whichever of the two values is lower.
staticmoveToward(from:Single, to:Single, delta:Single):Single
Moves from
toward to
by the delta
value.
Use a negative delta
value to move away.
Parameters:
from | The start value. |
---|---|
to | The value to move towards. |
delta | The amount to move by. |
Returns:
The value after moving.
staticnearestPo2(value:Int):Int
Returns the nearest larger power of 2 for the integer value
.
Parameters:
value | The input value. |
---|
Returns:
The nearest larger power of 2.
staticpolar2Cartesian(r:Single, th:Single):Vector2
Converts a 2D point expressed in the polar coordinate
system (a distance from the origin r
and an angle th
) to the cartesian
coordinate system (X and Y axis).
Parameters:
r | The distance from the origin. |
---|---|
th | The angle of the point. |
Returns:
A godot.Vector2
representing the cartesian coordinate.
staticposMod(a:Int, b:Int):Int
staticPosMod(a:Single, b:Single):Single
Performs a canonical Modulus operation, where the output is on the range [0, b
).
Parameters:
a | The dividend, the primary input. |
---|---|
b | The divisor. The output is on the range [0, |
Returns:
The resulting output.
staticpow(x:Single, y:Single):Single
Returns the result of x
raised to the power of y
.
Parameters:
x | The base. |
---|---|
y | The exponent. |
Returns:
x
raised to the power of y
.
staticrad2Deg(rad:Single):Single
Converts an angle expressed in radians to degrees.
Parameters:
rad | An angle expressed in radians. |
---|
Returns:
The same angle expressed in degrees.
staticround(s:Single):Single
Rounds s
to the nearest whole number,
with halfway cases rounded towards the nearest multiple of two.
Parameters:
s | The number to round. |
---|
Returns:
The rounded number.
staticroundToInt(s:Single):Int
Rounds s
to the nearest whole number.
This is the same as godot.Mathf.round
, but returns an int
.
Parameters:
s | The number to round. |
---|
Returns:
The rounded number.
staticsign(s:Int):Int
staticSign(s:Single):Int
Returns the sign of s
: -1
or 1
.
Returns 0
if s
is 0
.
Parameters:
s | The input number. |
---|
Returns:
One of three possible values: 1
, -1
, or 0
.
staticsin(s:Single):Single
Returns the sine of angle s
in radians.
Parameters:
s | The angle in radians. |
---|
Returns:
The sine of that angle.
staticsinh(s:Single):Single
Returns the hyperbolic sine of angle s
in radians.
Parameters:
s | The angle in radians. |
---|
Returns:
The hyperbolic sine of that angle.
staticsmoothStep(from:Single, to:Single, weight:Single):Single
Returns a number smoothly interpolated between from
and to
,
based on the weight
. Similar to godot.Mathf.lerp
,
but interpolates faster at the beginning and slower at the end.
Parameters:
from | The start value for interpolation. |
---|---|
to | The destination value for interpolation. |
weight | A value representing the amount of interpolation. |
Returns:
The resulting value of the interpolation.
staticsqrt(s:Single):Single
Returns the square root of s
, where s
is a non-negative number.
If you need negative inputs, use cs.system.numerics.Complex
.
Parameters:
s | The input number. Must not be negative. |
---|
Returns:
The square root of s
.
staticstepDecimals(step:Single):Int
Returns the position of the first non-zero digit, after the decimal point. Note that the maximum return value is 10, which is a design decision in the implementation.
Parameters:
step | The input value. |
---|
Returns:
The position of the first non-zero digit.
staticstepify(s:Single, step:Single):Single
Snaps float value s
to a given step
.
This can also be used to round a floating point number to an arbitrary number of decimals.
@returns
Parameters:
s | The value to stepify. |
---|---|
step | The step size to snap to. |
statictan(s:Single):Single
Returns the tangent of angle s
in radians.
Parameters:
s | The angle in radians. |
---|
Returns:
The tangent of that angle.
statictanh(s:Single):Single
Returns the hyperbolic tangent of angle s
in radians.
Parameters:
s | The angle in radians. |
---|
Returns:
The hyperbolic tangent of that angle.
staticwrap(value:Int, min:Int, max:Int):Int
staticWrap(value:Single, min:Single, max:Single):Single
Wraps value
between min
and max
.
Usable for creating loop-alike behavior or infinite surfaces.
If min
is 0
, this is equivalent
to godot.Mathf.posMod
, so prefer using that instead.
Parameters:
value | The value to wrap. |
---|---|
min | The minimum allowed value and lower bound of the range. |
max | The maximum allowed value and upper bound of the range. |
Returns:
The wrapped value.