Provides constants and static methods for common mathematical functions.

Static variables

@:native("E")staticread onlyE:Single

The natural number e.

@:native("Epsilon")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.

@:native("Inf")staticread onlyINF:Single

Positive infinity. For negative infinity, use -Mathf.Inf.

@:native("NaN")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.

@:native("Pi")staticread onlyPI:Single

Constant that represents how many times the diameter of a circle fits around its perimeter. This is equivalent to Mathf.Tau / 2.

@:native("Sqrt2")staticread onlySQRT_2:Single

The square root of 2.

@:native("Tau")staticread onlyTAU:Single

The circle constant, the circumference of the unit circle in radians.

Static methods

@:native("Abs")staticabs(s:Int):Int

@:native("Abs")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.

@:native("Acos")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.

@:native("Asin")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.

@:native("Atan")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.

@:native("Atan2")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.

@:native("Cartesian2Polar")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.

@:native("Ceil")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.

@:native("CeilToInt")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.

@:native("Clamp")staticclamp(value:Int, min:Int, max:Int):Int

@:native("Clamp")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.

@:native("Cos")staticcos(s:Single):Single

Returns the cosine of angle s in radians.

Parameters:

s

The angle in radians.

Returns:

The cosine of that angle.

@:native("Cosh")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.

@:native("DecimalCount")staticdecimalCount(s:Single):Int

@:native("DecimalCount")staticDecimalCount(s:Decimal):Int

Returns the amount of digits after the decimal place.

Parameters:

s

The input value.

Returns:

The amount of digits.

@:native("Deg2Rad")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.

@:native("Ease")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

0 is constant, 1 is linear, 0 to 1 is ease-in, 1 or more is ease-out.

Returns:

The eased value.

@:native("Exp")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 e to.

Returns:

e raised to the power of s.

@:native("Floor")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.

@:native("FloorToInt")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.

@:native("InverseLerp")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.

@:native("IsEqualApprox")staticisEqualApprox(a:Single, b:Single):Bool

@:native("IsEqualApprox")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.

@:native("IsInf")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.

@:native("IsNaN")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.

@:native("IsZeroApprox")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.

@:native("Lerp")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.

@:native("LerpAngle")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.

@:native("Log")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.

@:native("Max")staticmax(a:Int, b:Int):Int

@:native("Max")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.

@:native("Min")staticmin(a:Int, b:Int):Int

@:native("Min")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.

@:native("MoveToward")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.

@:native("NearestPo2")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.

@:native("Polar2Cartesian")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.

@:native("PosMod")staticposMod(a:Int, b:Int):Int

@:native("PosMod")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, b).

Returns:

The resulting output.

@:native("Pow")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.

@:native("Rad2Deg")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.

@:native("Round")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.

@:native("RoundToInt")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.

@:native("Sign")staticsign(s:Int):Int

@:native("Sign")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.

@:native("Sin")staticsin(s:Single):Single

Returns the sine of angle s in radians.

Parameters:

s

The angle in radians.

Returns:

The sine of that angle.

@:native("Sinh")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.

@:native("SmoothStep")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.

@:native("Sqrt")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.

@:native("StepDecimals")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.

@:native("Stepify")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.

@:native("Tan")statictan(s:Single):Single

Returns the tangent of angle s in radians.

Parameters:

s

The angle in radians.

Returns:

The tangent of that angle.

@:native("Tanh")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.

@:native("Wrap")staticwrap(value:Int, min:Int, max:Int):Int

@:native("Wrap")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.