Table of Contents

Class Mathf

Namespace
Godot
Assembly
GodotSharp.dll

Provides constants and static methods for common mathematical functions.

public static class Mathf
Inheritance
Mathf
Inherited Members

Fields

E

The natural number e.

public const float E = 2.7182817

Field Value

float

Epsilon

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.

public const float Epsilon = 1E-06

Field Value

float

Inf

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

public const float Inf = Infinity

Field Value

float

NaN

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

public const float NaN = NaN

Field Value

float

Pi

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

public const float Pi = 3.1415927

Field Value

float

Sqrt2

The square root of 2.

public const float Sqrt2 = 1.4142135

Field Value

float

Tau

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

public const float Tau = 6.2831855

Field Value

float

Methods

Abs(double)

Returns the absolute value of s (i.e. positive value).

public static double Abs(double s)

Parameters

s double

The input number.

Returns

double

The absolute value of s.

Abs(int)

Returns the absolute value of s (i.e. positive value).

public static int Abs(int s)

Parameters

s int

The input number.

Returns

int

The absolute value of s.

Abs(float)

Returns the absolute value of s (i.e. positive value).

public static float Abs(float s)

Parameters

s float

The input number.

Returns

float

The absolute value of s.

Acos(double)

Returns the arc cosine of s in radians. Use to get the angle of cosine s.

public static double Acos(double s)

Parameters

s double

The input cosine value. Must be on the range of -1.0 to 1.0.

Returns

double

An angle that would result in the given cosine value. On the range 0 to Tau/2.

Acos(float)

Returns the arc cosine of s in radians. Use to get the angle of cosine s.

public static float Acos(float s)

Parameters

s float

The input cosine value. Must be on the range of -1.0 to 1.0.

Returns

float

An angle that would result in the given cosine value. On the range 0 to Tau/2.

Acosh(double)

Returns the hyperbolic arc (also called inverse) cosine of s in radians. Use it to get the angle from an angle's cosine in hyperbolic space if s is larger or equal to 1.

public static double Acosh(double s)

Parameters

s double

The input hyperbolic cosine value.

Returns

double

An angle that would result in the given hyperbolic cosine value.

Acosh(float)

Returns the hyperbolic arc (also called inverse) cosine of s in radians. Use it to get the angle from an angle's cosine in hyperbolic space if s is larger or equal to 1.

public static float Acosh(float s)

Parameters

s float

The input hyperbolic cosine value.

Returns

float

An angle that would result in the given hyperbolic cosine value.

AngleDifference(double, double)

Returns the difference between the two angles, in range of -Pi, Pi. When from and to are opposite, returns -Pi if from is smaller than to, or Pi otherwise.

public static double AngleDifference(double from, double to)

Parameters

from double

The start angle.

to double

The destination angle.

Returns

double

The difference between the two angles.

AngleDifference(float, float)

Returns the difference between the two angles, in range of -Pi, Pi. When from and to are opposite, returns -Pi if from is smaller than to, or Pi otherwise.

public static float AngleDifference(float from, float to)

Parameters

from float

The start angle.

to float

The destination angle.

Returns

float

The difference between the two angles.

Asin(double)

Returns the arc sine of s in radians. Use to get the angle of sine s.

public static double Asin(double s)

Parameters

s double

The input sine value. Must be on the range of -1.0 to 1.0.

Returns

double

An angle that would result in the given sine value. On the range -Tau/4 to Tau/4.

Asin(float)

Returns the arc sine of s in radians. Use to get the angle of sine s.

public static float Asin(float s)

Parameters

s float

The input sine value. Must be on the range of -1.0 to 1.0.

Returns

float

An angle that would result in the given sine value. On the range -Tau/4 to Tau/4.

Asinh(double)

Returns the hyperbolic arc (also called inverse) sine of s in radians. Use it to get the angle from an angle's sine in hyperbolic space if s is larger or equal to 1.

public static double Asinh(double s)

Parameters

s double

The input hyperbolic sine value.

Returns

double

An angle that would result in the given hyperbolic sine value.

Asinh(float)

Returns the hyperbolic arc (also called inverse) sine of s in radians. Use it to get the angle from an angle's sine in hyperbolic space if s is larger or equal to 1.

public static float Asinh(float s)

Parameters

s float

The input hyperbolic sine value.

Returns

float

An angle that would result in the given hyperbolic sine value.

Atan(double)

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 Atan2(double, double) if you have both y and x.

public static double Atan(double s)

Parameters

s double

The input tangent value.

Returns

double

An angle that would result in the given tangent value. On the range -Tau/4 to Tau/4.

Atan(float)

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 Atan2(float, float) if you have both y and x.

public static float Atan(float s)

Parameters

s float

The input tangent value.

Returns

float

An angle that would result in the given tangent value. On the range -Tau/4 to Tau/4.

Atan2(double, double)

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.

public static double Atan2(double y, double x)

Parameters

y double

The Y coordinate of the point to find the angle to.

x double

The X coordinate of the point to find the angle to.

Returns

double

An angle that would result in the given tangent value. On the range -Tau/2 to Tau/2.

Atan2(float, float)

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.

public static float Atan2(float y, float x)

Parameters

y float

The Y coordinate of the point to find the angle to.

x float

The X coordinate of the point to find the angle to.

Returns

float

An angle that would result in the given tangent value. On the range -Tau/2 to Tau/2.

Atanh(double)

Returns the hyperbolic arc (also called inverse) tangent of s in radians. Use it to get the angle from an angle's tangent in hyperbolic space if s is between -1 and 1 (non-inclusive).

public static double Atanh(double s)

Parameters

s double

The input hyperbolic tangent value.

Returns

double

An angle that would result in the given hyperbolic tangent value.

Atanh(float)

Returns the hyperbolic arc (also called inverse) tangent of s in radians. Use it to get the angle from an angle's tangent in hyperbolic space if s is between -1 and 1 (non-inclusive).

public static float Atanh(float s)

Parameters

s float

The input hyperbolic tangent value.

Returns

float

An angle that would result in the given hyperbolic tangent value.

BezierDerivative(double, double, double, double, double)

Returns the derivative at the given t on a one dimensional Bezier curve defined by the given control1, control2, and end points.

public static double BezierDerivative(double start, double control1, double control2, double end, double t)

Parameters

start double

The start value for the interpolation.

control1 double

Control point that defines the bezier curve.

control2 double

Control point that defines the bezier curve.

end double

The destination value for the interpolation.

t double

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns

double

The resulting value of the interpolation.

BezierDerivative(float, float, float, float, float)

Returns the derivative at the given t on a one dimensional Bezier curve defined by the given control1, control2, and end points.

public static float BezierDerivative(float start, float control1, float control2, float end, float t)

Parameters

start float

The start value for the interpolation.

control1 float

Control point that defines the bezier curve.

control2 float

Control point that defines the bezier curve.

end float

The destination value for the interpolation.

t float

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns

float

The resulting value of the interpolation.

BezierInterpolate(double, double, double, double, double)

Returns the point at the given t on a one-dimensional Bezier curve defined by the given control1, control2, and end points.

public static double BezierInterpolate(double start, double control1, double control2, double end, double t)

Parameters

start double

The start value for the interpolation.

control1 double

Control point that defines the bezier curve.

control2 double

Control point that defines the bezier curve.

end double

The destination value for the interpolation.

t double

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns

double

The resulting value of the interpolation.

BezierInterpolate(float, float, float, float, float)

Returns the point at the given t on a one-dimensional Bezier curve defined by the given control1, control2, and end points.

public static float BezierInterpolate(float start, float control1, float control2, float end, float t)

Parameters

start float

The start value for the interpolation.

control1 float

Control point that defines the bezier curve.

control2 float

Control point that defines the bezier curve.

end float

The destination value for the interpolation.

t float

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns

float

The resulting value of the interpolation.

Ceil(double)

Rounds s upward (towards positive infinity).

public static double Ceil(double s)

Parameters

s double

The number to ceil.

Returns

double

The smallest whole number that is not less than s.

Ceil(float)

Rounds s upward (towards positive infinity).

public static float Ceil(float s)

Parameters

s float

The number to ceil.

Returns

float

The smallest whole number that is not less than s.

CeilToInt(double)

Rounds s upward (towards positive infinity).

This is the same as Ceil(double), but returns an int.

public static int CeilToInt(double s)

Parameters

s double

The number to ceil.

Returns

int

The smallest whole number that is not less than s.

CeilToInt(float)

Rounds s upward (towards positive infinity).

This is the same as Ceil(float), but returns an int.

public static int CeilToInt(float s)

Parameters

s float

The number to ceil.

Returns

int

The smallest whole number that is not less than s.

Clamp(double, double, double)

Clamps a value so that it is not less than min and not more than max.

public static double Clamp(double value, double min, double max)

Parameters

value double

The value to clamp.

min double

The minimum allowed value.

max double

The maximum allowed value.

Returns

double

The clamped value.

Clamp(int, int, int)

Clamps a value so that it is not less than min and not more than max.

public static int Clamp(int value, int min, int max)

Parameters

value int

The value to clamp.

min int

The minimum allowed value.

max int

The maximum allowed value.

Returns

int

The clamped value.

Clamp(float, float, float)

Clamps a value so that it is not less than min and not more than max.

public static float Clamp(float value, float min, float max)

Parameters

value float

The value to clamp.

min float

The minimum allowed value.

max float

The maximum allowed value.

Returns

float

The clamped value.

Cos(double)

Returns the cosine of angle s in radians.

public static double Cos(double s)

Parameters

s double

The angle in radians.

Returns

double

The cosine of that angle.

Cos(float)

Returns the cosine of angle s in radians.

public static float Cos(float s)

Parameters

s float

The angle in radians.

Returns

float

The cosine of that angle.

Cosh(double)

Returns the hyperbolic cosine of angle s in radians.

public static double Cosh(double s)

Parameters

s double

The angle in radians.

Returns

double

The hyperbolic cosine of that angle.

Cosh(float)

Returns the hyperbolic cosine of angle s in radians.

public static float Cosh(float s)

Parameters

s float

The angle in radians.

Returns

float

The hyperbolic cosine of that angle.

CubicInterpolate(double, double, double, double, double)

Cubic interpolates between two values by the factor defined in weight with pre and post values.

public static double CubicInterpolate(double from, double to, double pre, double post, double weight)

Parameters

from double

The start value for interpolation.

to double

The destination value for interpolation.

pre double

The value which before "from" value for interpolation.

post double

The value which after "to" value for interpolation.

weight double

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns

double

The resulting value of the interpolation.

CubicInterpolate(float, float, float, float, float)

Cubic interpolates between two values by the factor defined in weight with pre and post values.

public static float CubicInterpolate(float from, float to, float pre, float post, float weight)

Parameters

from float

The start value for interpolation.

to float

The destination value for interpolation.

pre float

The value which before "from" value for interpolation.

post float

The value which after "to" value for interpolation.

weight float

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns

float

The resulting value of the interpolation.

CubicInterpolateAngle(double, double, double, double, double)

Cubic interpolates between two rotation values with shortest path by the factor defined in weight with pre and post values. See also LerpAngle(double, double, double).

public static double CubicInterpolateAngle(double from, double to, double pre, double post, double weight)

Parameters

from double

The start value for interpolation.

to double

The destination value for interpolation.

pre double

The value which before "from" value for interpolation.

post double

The value which after "to" value for interpolation.

weight double

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns

double

The resulting value of the interpolation.

CubicInterpolateAngle(float, float, float, float, float)

Cubic interpolates between two rotation values with shortest path by the factor defined in weight with pre and post values. See also LerpAngle(float, float, float).

public static float CubicInterpolateAngle(float from, float to, float pre, float post, float weight)

Parameters

from float

The start value for interpolation.

to float

The destination value for interpolation.

pre float

The value which before "from" value for interpolation.

post float

The value which after "to" value for interpolation.

weight float

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns

float

The resulting value of the interpolation.

CubicInterpolateAngleInTime(double, double, double, double, double, double, double, double)

Cubic interpolates between two rotation values with shortest path by the factor defined in weight with pre and post values. See also LerpAngle(double, double, double). It can perform smoother interpolation than CubicInterpolateAngle(double, double, double, double, double) by the time values.

public static double CubicInterpolateAngleInTime(double from, double to, double pre, double post, double weight, double toT, double preT, double postT)

Parameters

from double

The start value for interpolation.

to double

The destination value for interpolation.

pre double

The value which before "from" value for interpolation.

post double

The value which after "to" value for interpolation.

weight double

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

toT double
preT double
postT double

Returns

double

The resulting value of the interpolation.

CubicInterpolateAngleInTime(float, float, float, float, float, float, float, float)

Cubic interpolates between two rotation values with shortest path by the factor defined in weight with pre and post values. See also LerpAngle(float, float, float). It can perform smoother interpolation than CubicInterpolateAngle(float, float, float, float, float) by the time values.

public static float CubicInterpolateAngleInTime(float from, float to, float pre, float post, float weight, float toT, float preT, float postT)

Parameters

from float

The start value for interpolation.

to float

The destination value for interpolation.

pre float

The value which before "from" value for interpolation.

post float

The value which after "to" value for interpolation.

weight float

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

toT float
preT float
postT float

Returns

float

The resulting value of the interpolation.

CubicInterpolateInTime(double, double, double, double, double, double, double, double)

Cubic interpolates between two values by the factor defined in weight with pre and post values. It can perform smoother interpolation than CubicInterpolate(double, double, double, double, double) by the time values.

public static double CubicInterpolateInTime(double from, double to, double pre, double post, double weight, double toT, double preT, double postT)

Parameters

from double

The start value for interpolation.

to double

The destination value for interpolation.

pre double

The value which before "from" value for interpolation.

post double

The value which after "to" value for interpolation.

weight double

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

toT double
preT double
postT double

Returns

double

The resulting value of the interpolation.

CubicInterpolateInTime(float, float, float, float, float, float, float, float)

Cubic interpolates between two values by the factor defined in weight with pre and post values. It can perform smoother interpolation than CubicInterpolate(float, float, float, float, float) by the time values.

public static float CubicInterpolateInTime(float from, float to, float pre, float post, float weight, float toT, float preT, float postT)

Parameters

from float

The start value for interpolation.

to float

The destination value for interpolation.

pre float

The value which before "from" value for interpolation.

post float

The value which after "to" value for interpolation.

weight float

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

toT float
preT float
postT float

Returns

float

The resulting value of the interpolation.

DbToLinear(double)

Converts from decibels to linear energy (audio).

public static double DbToLinear(double db)

Parameters

db double

Decibels to convert.

Returns

double

Audio volume as linear energy.

See Also

DbToLinear(float)

Converts from decibels to linear energy (audio).

public static float DbToLinear(float db)

Parameters

db float

Decibels to convert.

Returns

float

Audio volume as linear energy.

See Also

DecimalCount(decimal)

Returns the amount of digits after the decimal place.

public static int DecimalCount(decimal s)

Parameters

s decimal

The input decimal value.

Returns

int

The amount of digits.

DecimalCount(double)

Returns the amount of digits after the decimal place.

public static int DecimalCount(double s)

Parameters

s double

The input value.

Returns

int

The amount of digits.

DegToRad(double)

Converts an angle expressed in degrees to radians.

public static double DegToRad(double deg)

Parameters

deg double

An angle expressed in degrees.

Returns

double

The same angle expressed in radians.

DegToRad(float)

Converts an angle expressed in degrees to radians.

public static float DegToRad(float deg)

Parameters

deg float

An angle expressed in degrees.

Returns

float

The same angle expressed in radians.

Ease(double, double)

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.

public static double Ease(double s, double curve)

Parameters

s double

The value to ease.

curve double

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

Returns

double

The eased value.

Ease(float, float)

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.

public static float Ease(float s, float curve)

Parameters

s float

The value to ease.

curve float

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

Returns

float

The eased value.

Exp(double)

The natural exponential function. It raises the mathematical constant e to the power of s and returns it.

public static double Exp(double s)

Parameters

s double

The exponent to raise e to.

Returns

double

e raised to the power of s.

Exp(float)

The natural exponential function. It raises the mathematical constant e to the power of s and returns it.

public static float Exp(float s)

Parameters

s float

The exponent to raise e to.

Returns

float

e raised to the power of s.

Floor(double)

Rounds s downward (towards negative infinity).

public static double Floor(double s)

Parameters

s double

The number to floor.

Returns

double

The largest whole number that is not more than s.

Floor(float)

Rounds s downward (towards negative infinity).

public static float Floor(float s)

Parameters

s float

The number to floor.

Returns

float

The largest whole number that is not more than s.

FloorToInt(double)

Rounds s downward (towards negative infinity).

This is the same as Floor(double), but returns an int.

public static int FloorToInt(double s)

Parameters

s double

The number to floor.

Returns

int

The largest whole number that is not more than s.

FloorToInt(float)

Rounds s downward (towards negative infinity).

This is the same as Floor(float), but returns an int.

public static int FloorToInt(float s)

Parameters

s float

The number to floor.

Returns

int

The largest whole number that is not more than s.

InverseLerp(double, double, double)

Returns a normalized value considering the given range. This is the opposite of Lerp(double, double, double).

public static double InverseLerp(double from, double to, double weight)

Parameters

from double

The start value for interpolation.

to double

The destination value for interpolation.

weight double

The interpolated value.

Returns

double

The resulting value of the inverse interpolation. The returned value will be between 0.0 and 1.0 if weight is between from and to (inclusive).

InverseLerp(float, float, float)

Returns a normalized value considering the given range. This is the opposite of Lerp(float, float, float).

public static float InverseLerp(float from, float to, float weight)

Parameters

from float

The start value for interpolation.

to float

The destination value for interpolation.

weight float

The interpolated value.

Returns

float

The resulting value of the inverse interpolation. The returned value will be between 0.0 and 1.0 if weight is between from and to (inclusive).

IsEqualApprox(double, double)

Returns true if a and b are approximately equal to each other. The comparison is done using a tolerance calculation with Epsilon.

public static bool IsEqualApprox(double a, double b)

Parameters

a double

One of the values.

b double

The other value.

Returns

bool

A bool for whether or not the two values are approximately equal.

IsEqualApprox(double, double, double)

Returns true if a and b are approximately equal to each other. The comparison is done using the provided tolerance value. If you want the tolerance to be calculated for you, use IsEqualApprox(double, double).

public static bool IsEqualApprox(double a, double b, double tolerance)

Parameters

a double

One of the values.

b double

The other value.

tolerance double

The pre-calculated tolerance value.

Returns

bool

A bool for whether or not the two values are equal.

IsEqualApprox(float, float)

Returns true if a and b are approximately equal to each other. The comparison is done using a tolerance calculation with Epsilon.

public static bool IsEqualApprox(float a, float b)

Parameters

a float

One of the values.

b float

The other value.

Returns

bool

A bool for whether or not the two values are approximately equal.

IsEqualApprox(float, float, float)

Returns true if a and b are approximately equal to each other. The comparison is done using the provided tolerance value. If you want the tolerance to be calculated for you, use IsEqualApprox(float, float).

public static bool IsEqualApprox(float a, float b, float tolerance)

Parameters

a float

One of the values.

b float

The other value.

tolerance float

The pre-calculated tolerance value.

Returns

bool

A bool for whether or not the two values are equal.

IsFinite(double)

Returns whether s is a finite value, i.e. it is not NaN, positive infinite, or negative infinity.

public static bool IsFinite(double s)

Parameters

s double

The value to check.

Returns

bool

A bool for whether or not the value is a finite value.

IsFinite(float)

Returns whether s is a finite value, i.e. it is not NaN, positive infinite, or negative infinity.

public static bool IsFinite(float s)

Parameters

s float

The value to check.

Returns

bool

A bool for whether or not the value is a finite value.

IsInf(double)

Returns whether s is an infinity value (either positive infinity or negative infinity).

public static bool IsInf(double s)

Parameters

s double

The value to check.

Returns

bool

A bool for whether or not the value is an infinity value.

IsInf(float)

Returns whether s is an infinity value (either positive infinity or negative infinity).

public static bool IsInf(float s)

Parameters

s float

The value to check.

Returns

bool

A bool for whether or not the value is an infinity value.

IsNaN(double)

Returns whether s is a NaN ("Not a Number" or invalid) value.

public static bool IsNaN(double s)

Parameters

s double

The value to check.

Returns

bool

A bool for whether or not the value is a NaN value.

IsNaN(float)

Returns whether s is a NaN ("Not a Number" or invalid) value.

public static bool IsNaN(float s)

Parameters

s float

The value to check.

Returns

bool

A bool for whether or not the value is a NaN value.

IsZeroApprox(double)

Returns true if s is zero or almost zero. The comparison is done using a tolerance calculation with Epsilon.

This method is faster than using IsEqualApprox(double, double) with one value as zero.

public static bool IsZeroApprox(double s)

Parameters

s double

The value to check.

Returns

bool

A bool for whether or not the value is nearly zero.

IsZeroApprox(float)

Returns true if s is zero or almost zero. The comparison is done using a tolerance calculation with Epsilon.

This method is faster than using IsEqualApprox(float, float) with one value as zero.

public static bool IsZeroApprox(float s)

Parameters

s float

The value to check.

Returns

bool

A bool for whether or not the value is nearly zero.

Lerp(double, double, double)

Linearly interpolates between two values by a normalized value. This is the opposite InverseLerp(double, double, double).

public static double Lerp(double from, double to, double weight)

Parameters

from double

The start value for interpolation.

to double

The destination value for interpolation.

weight double

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns

double

The resulting value of the interpolation.

Lerp(float, float, float)

Linearly interpolates between two values by a normalized value. This is the opposite InverseLerp(float, float, float).

public static float Lerp(float from, float to, float weight)

Parameters

from float

The start value for interpolation.

to float

The destination value for interpolation.

weight float

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns

float

The resulting value of the interpolation.

LerpAngle(double, double, double)

Linearly interpolates between two angles (in radians) by a normalized value.

Similar to Lerp(double, double, double), but interpolates correctly when the angles wrap around Tau.

public static double LerpAngle(double from, double to, double weight)

Parameters

from double

The start angle for interpolation.

to double

The destination angle for interpolation.

weight double

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns

double

The resulting angle of the interpolation.

LerpAngle(float, float, float)

Linearly interpolates between two angles (in radians) by a normalized value.

Similar to Lerp(float, float, float), but interpolates correctly when the angles wrap around Tau.

public static float LerpAngle(float from, float to, float weight)

Parameters

from float

The start angle for interpolation.

to float

The destination angle for interpolation.

weight float

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns

float

The resulting angle of the interpolation.

LinearToDb(double)

Converts from linear energy to decibels (audio). This can be used to implement volume sliders that behave as expected (since volume isn't linear).

public static double LinearToDb(double linear)

Parameters

linear double

The linear energy to convert.

Returns

double

Audio as decibels.

Examples

// "slider" refers to a node that inherits Range such as HSlider or VSlider.
// Its range must be configured to go from 0 to 1.
// Change the bus name if you'd like to change the volume of a specific bus only.
AudioServer.SetBusVolumeDb(AudioServer.GetBusIndex("Master"), GD.LinearToDb(slider.value));
See Also

LinearToDb(float)

Converts from linear energy to decibels (audio). This can be used to implement volume sliders that behave as expected (since volume isn't linear).

public static float LinearToDb(float linear)

Parameters

linear float

The linear energy to convert.

Returns

float

Audio as decibels.

Examples

// "slider" refers to a node that inherits Range such as HSlider or VSlider.
// Its range must be configured to go from 0 to 1.
// Change the bus name if you'd like to change the volume of a specific bus only.
AudioServer.SetBusVolumeDb(AudioServer.GetBusIndex("Master"), GD.LinearToDb(slider.value));
See Also

Log(double)

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.

public static double Log(double s)

Parameters

s double

The input value.

Returns

double

The natural log of s.

Log(float)

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.

public static float Log(float s)

Parameters

s float

The input value.

Returns

float

The natural log of s.

Max(double, double)

Returns the maximum of two values.

public static double Max(double a, double b)

Parameters

a double

One of the values.

b double

The other value.

Returns

double

Whichever of the two values is higher.

Max(int, int)

Returns the maximum of two values.

public static int Max(int a, int b)

Parameters

a int

One of the values.

b int

The other value.

Returns

int

Whichever of the two values is higher.

Max(float, float)

Returns the maximum of two values.

public static float Max(float a, float b)

Parameters

a float

One of the values.

b float

The other value.

Returns

float

Whichever of the two values is higher.

Min(double, double)

Returns the minimum of two values.

public static double Min(double a, double b)

Parameters

a double

One of the values.

b double

The other value.

Returns

double

Whichever of the two values is lower.

Min(int, int)

Returns the minimum of two values.

public static int Min(int a, int b)

Parameters

a int

One of the values.

b int

The other value.

Returns

int

Whichever of the two values is lower.

Min(float, float)

Returns the minimum of two values.

public static float Min(float a, float b)

Parameters

a float

One of the values.

b float

The other value.

Returns

float

Whichever of the two values is lower.

MoveToward(double, double, double)

Moves from toward to by the delta value.

Use a negative delta value to move away.

public static double MoveToward(double from, double to, double delta)

Parameters

from double

The start value.

to double

The value to move towards.

delta double

The amount to move by.

Returns

double

The value after moving.

MoveToward(float, float, float)

Moves from toward to by the delta value.

Use a negative delta value to move away.

public static float MoveToward(float from, float to, float delta)

Parameters

from float

The start value.

to float

The value to move towards.

delta float

The amount to move by.

Returns

float

The value after moving.

NearestPo2(int)

Returns the nearest larger power of 2 for the integer value.

public static int NearestPo2(int value)

Parameters

value int

The input value.

Returns

int

The nearest larger power of 2.

PingPong(double, double)

Returns the value wrapped between 0 and the length. If the limit is reached, the next value the function returned is decreased to the 0 side or increased to the length side (like a triangle wave). If length is less than zero, it becomes positive.

public static double PingPong(double value, double length)

Parameters

value double

The value to pingpong.

length double

The maximum value of the function.

Returns

double

The ping-ponged value.

PingPong(float, float)

Returns the value wrapped between 0 and the length. If the limit is reached, the next value the function returned is decreased to the 0 side or increased to the length side (like a triangle wave). If length is less than zero, it becomes positive.

public static float PingPong(float value, float length)

Parameters

value float

The value to pingpong.

length float

The maximum value of the function.

Returns

float

The ping-ponged value.

PosMod(double, double)

Performs a canonical Modulus operation, where the output is on the range [0, b).

public static double PosMod(double a, double b)

Parameters

a double

The dividend, the primary input.

b double

The divisor. The output is on the range [0, b).

Returns

double

The resulting output.

PosMod(int, int)

Performs a canonical Modulus operation, where the output is on the range [0, b).

public static int PosMod(int a, int b)

Parameters

a int

The dividend, the primary input.

b int

The divisor. The output is on the range [0, b).

Returns

int

The resulting output.

PosMod(float, float)

Performs a canonical Modulus operation, where the output is on the range [0, b).

public static float PosMod(float a, float b)

Parameters

a float

The dividend, the primary input.

b float

The divisor. The output is on the range [0, b).

Returns

float

The resulting output.

Pow(double, double)

Returns the result of x raised to the power of y.

public static double Pow(double x, double y)

Parameters

x double

The base.

y double

The exponent.

Returns

double

x raised to the power of y.

Pow(float, float)

Returns the result of x raised to the power of y.

public static float Pow(float x, float y)

Parameters

x float

The base.

y float

The exponent.

Returns

float

x raised to the power of y.

RadToDeg(double)

Converts an angle expressed in radians to degrees.

public static double RadToDeg(double rad)

Parameters

rad double

An angle expressed in radians.

Returns

double

The same angle expressed in degrees.

RadToDeg(float)

Converts an angle expressed in radians to degrees.

public static float RadToDeg(float rad)

Parameters

rad float

An angle expressed in radians.

Returns

float

The same angle expressed in degrees.

Remap(double, double, double, double, double)

Maps a value from [inFrom, inTo] to [outFrom, outTo].

public static double Remap(double value, double inFrom, double inTo, double outFrom, double outTo)

Parameters

value double

The value to map.

inFrom double

The start value for the input interpolation.

inTo double

The destination value for the input interpolation.

outFrom double

The start value for the output interpolation.

outTo double

The destination value for the output interpolation.

Returns

double

The resulting mapped value mapped.

Remap(float, float, float, float, float)

Maps a value from [inFrom, inTo] to [outFrom, outTo].

public static float Remap(float value, float inFrom, float inTo, float outFrom, float outTo)

Parameters

value float

The value to map.

inFrom float

The start value for the input interpolation.

inTo float

The destination value for the input interpolation.

outFrom float

The start value for the output interpolation.

outTo float

The destination value for the output interpolation.

Returns

float

The resulting mapped value mapped.

RotateToward(double, double, double)

Rotates from toward to by the delta amount. Will not go past to. Similar to MoveToward(double, double, double) but interpolates correctly when the angles wrap around Tau. If delta is negative, this function will rotate away from to, toward the opposite angle, and will not go past the opposite angle.

public static double RotateToward(double from, double to, double delta)

Parameters

from double

The start angle.

to double

The angle to move towards.

delta double

The amount to move by.

Returns

double

The angle after moving.

RotateToward(float, float, float)

Rotates from toward to by the delta amount. Will not go past to. Similar to MoveToward(float, float, float) but interpolates correctly when the angles wrap around Tau. If delta is negative, this function will rotate away from to, toward the opposite angle, and will not go past the opposite angle.

public static float RotateToward(float from, float to, float delta)

Parameters

from float

The start angle.

to float

The angle to move towards.

delta float

The amount to move by.

Returns

float

The angle after moving.

Round(double)

Rounds s to the nearest whole number, with halfway cases rounded towards the nearest multiple of two.

public static double Round(double s)

Parameters

s double

The number to round.

Returns

double

The rounded number.

Round(float)

Rounds s to the nearest whole number, with halfway cases rounded towards the nearest multiple of two.

public static float Round(float s)

Parameters

s float

The number to round.

Returns

float

The rounded number.

RoundToInt(double)

Rounds s to the nearest whole number.

This is the same as Round(double), but returns an int.

public static int RoundToInt(double s)

Parameters

s double

The number to round.

Returns

int

The rounded number.

RoundToInt(float)

Rounds s to the nearest whole number.

This is the same as Round(float), but returns an int.

public static int RoundToInt(float s)

Parameters

s float

The number to round.

Returns

int

The rounded number.

Sign(double)

Returns the sign of s: -1 or 1. Returns 0 if s is 0.

public static int Sign(double s)

Parameters

s double

The input number.

Returns

int

One of three possible values: 1, -1, or 0.

Sign(int)

Returns the sign of s: -1 or 1. Returns 0 if s is 0.

public static int Sign(int s)

Parameters

s int

The input number.

Returns

int

One of three possible values: 1, -1, or 0.

Sign(float)

Returns the sign of s: -1 or 1. Returns 0 if s is 0.

public static int Sign(float s)

Parameters

s float

The input number.

Returns

int

One of three possible values: 1, -1, or 0.

Sin(double)

Returns the sine of angle s in radians.

public static double Sin(double s)

Parameters

s double

The angle in radians.

Returns

double

The sine of that angle.

Sin(float)

Returns the sine of angle s in radians.

public static float Sin(float s)

Parameters

s float

The angle in radians.

Returns

float

The sine of that angle.

SinCos(double)

Returns the sine and cosine of angle s in radians.

public static (double Sin, double Cos) SinCos(double s)

Parameters

s double

The angle in radians.

Returns

(double Sin, double Cos)

The sine and cosine of that angle.

SinCos(float)

Returns the sine and cosine of angle s in radians.

public static (float Sin, float Cos) SinCos(float s)

Parameters

s float

The angle in radians.

Returns

(float Sin, float Cos)

The sine and cosine of that angle.

Sinh(double)

Returns the hyperbolic sine of angle s in radians.

public static double Sinh(double s)

Parameters

s double

The angle in radians.

Returns

double

The hyperbolic sine of that angle.

Sinh(float)

Returns the hyperbolic sine of angle s in radians.

public static float Sinh(float s)

Parameters

s float

The angle in radians.

Returns

float

The hyperbolic sine of that angle.

SmoothStep(double, double, double)

Returns a number smoothly interpolated between from and to, based on the weight. Similar to Lerp(double, double, double), but interpolates faster at the beginning and slower at the end.

public static double SmoothStep(double from, double to, double weight)

Parameters

from double

The start value for interpolation.

to double

The destination value for interpolation.

weight double

A value representing the amount of interpolation.

Returns

double

The resulting value of the interpolation.

SmoothStep(float, float, float)

Returns a number smoothly interpolated between from and to, based on the weight. Similar to Lerp(float, float, float), but interpolates faster at the beginning and slower at the end.

public static float SmoothStep(float from, float to, float weight)

Parameters

from float

The start value for interpolation.

to float

The destination value for interpolation.

weight float

A value representing the amount of interpolation.

Returns

float

The resulting value of the interpolation.

Snapped(double, double)

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.

public static double Snapped(double s, double step)

Parameters

s double

The value to snap.

step double

The step size to snap to.

Returns

double

The snapped value.

Snapped(float, float)

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.

public static float Snapped(float s, float step)

Parameters

s float

The value to snap.

step float

The step size to snap to.

Returns

float

The snapped value.

Sqrt(double)

Returns the square root of s, where s is a non-negative number.

If you need negative inputs, use Complex.

public static double Sqrt(double s)

Parameters

s double

The input number. Must not be negative.

Returns

double

The square root of s.

Sqrt(float)

Returns the square root of s, where s is a non-negative number.

If you need negative inputs, use Complex.

public static float Sqrt(float s)

Parameters

s float

The input number. Must not be negative.

Returns

float

The square root of s.

StepDecimals(double)

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.

public static int StepDecimals(double step)

Parameters

step double

The input value.

Returns

int

The position of the first non-zero digit.

Tan(double)

Returns the tangent of angle s in radians.

public static double Tan(double s)

Parameters

s double

The angle in radians.

Returns

double

The tangent of that angle.

Tan(float)

Returns the tangent of angle s in radians.

public static float Tan(float s)

Parameters

s float

The angle in radians.

Returns

float

The tangent of that angle.

Tanh(double)

Returns the hyperbolic tangent of angle s in radians.

public static double Tanh(double s)

Parameters

s double

The angle in radians.

Returns

double

The hyperbolic tangent of that angle.

Tanh(float)

Returns the hyperbolic tangent of angle s in radians.

public static float Tanh(float s)

Parameters

s float

The angle in radians.

Returns

float

The hyperbolic tangent of that angle.

Wrap(double, double, double)

Wraps value between min and max. Usable for creating loop-alike behavior or infinite surfaces. If min is 0, this is equivalent to PosMod(double, double), so prefer using that instead.

public static double Wrap(double value, double min, double max)

Parameters

value double

The value to wrap.

min double

The minimum allowed value and lower bound of the range.

max double

The maximum allowed value and upper bound of the range.

Returns

double

The wrapped value.

Wrap(int, int, int)

Wraps value between min and max. Usable for creating loop-alike behavior or infinite surfaces. If min is 0, this is equivalent to PosMod(int, int), so prefer using that instead.

public static int Wrap(int value, int min, int max)

Parameters

value int

The value to wrap.

min int

The minimum allowed value and lower bound of the range.

max int

The maximum allowed value and upper bound of the range.

Returns

int

The wrapped value.

Wrap(float, float, float)

Wraps value between min and max. Usable for creating loop-alike behavior or infinite surfaces. If min is 0, this is equivalent to PosMod(float, float), so prefer using that instead.

public static float Wrap(float value, float min, float max)

Parameters

value float

The value to wrap.

min float

The minimum allowed value and lower bound of the range.

max float

The maximum allowed value and upper bound of the range.

Returns

float

The wrapped value.