Skip to main content

Mathf

A collection of common math functions.
Unity Mathf

Members

Static Properties

NameDescription
Mathf.Deg2RadDegrees-to-radians conversion constant (Read Only).
Mathf.EpsilonA tiny numerical value (Read Only). The smallest value that a number (i.e. double) can have different from zero.
Mathf.InfinityA representation of positive infinity (Read Only).
Mathf.NegativeInfinityA representation of negative infinity (Read Only).
Mathf.PIThe well-known 3.14159265358979... value (Read Only).
Mathf.Rad2DegRadians-to-degrees conversion constant (Read Only).

Static Methods

NameDescription
Mathf.Abs(value)Returns the absolute value of f.
Mathf.Acos(f)Returns the arc-cosine of f - the angle in radians whose cosine is f.
Mathf.Approximately(a, b)Compares two floating point values and returns true if they are similar.
Mathf.Asin(f)Returns the arc-sine of f - the angle in radians whose sine is f.
Mathf.Atan(f)Returns the arc-tangent of f - the angle in radians whose tangent is f.
Mathf.Atan2(y, x)Returns the angle in radians whose Tan is y/x.
Mathf.Ceil(f)Returns the smallest integer greater to or equal to f.
Mathf.Clamp(value, min, max)Clamps the given value between the given minimum float and maximum float values. Returns the given value if it is within the min and max range.
Mathf.Clamp01(value)Clamps value between 0 and 1 and returns value.
Mathf.ClosestPowerOfTwo(value)Returns the closest power of two value.
Mathf.CorrelatedColorTemperatureToRGB(Kelvin)Convert a color temperature in Kelvin to RGB color.
Mathf.Cos(f)Returns the cosine of angle f.
Mathf.DeltaAngle(current, target)Calculates the shortest difference between two given angles given in degrees.
Mathf.Exp(power)Returns e raised to the specified power.
Mathf.Floor(f)Returns the largest integer smaller than or equal to f.
Mathf.GammaToLinearSpace(value)Converts the given value from gamma (sRGB) to linear color space.
Mathf.InverseLerp(a, b, value)Calculates the linear parameter t that produces the interpolant value within the range [a, b].
Mathf.IsPowerOfTwo(value)Returns true if the value is power of two.
Mathf.Lerp(a, b, t)Linearly interpolates between a and b by t.
Mathf.LerpAngle(a, b, t)Same as Lerp but makes sure the values interpolate correctly when they wrap around 360 degrees.
Mathf.LerpUnclamped(a, b, t)Linearly interpolates between a and b by t with no limit to t.
Mathf.Log(f, p)Returns the logarithm of a specified number in a specified base.
Mathf.Log(f)Returns the natural (base e) logarithm of a specified number.
Mathf.Log10(f)Returns the base 10 logarithm of a specified number.
Mathf.Max(a, b)Returns largest of two or more values.
Mathf.Max( values[])Returns largest of two or more values.
Mathf.Min(a, b)Returns the smallest of two values.
Mathf.Min( values[])Returns the smallest of the values.
Mathf.MoveTowards(current, target, maxDelta)Moves a value current towards target.
Mathf.MoveTowardsAngle(current, target, maxDelta)Same as MoveTowards but makes sure the values interpolate correctly when they wrap around 360 degrees.
Mathf.NextPowerOfTwo(value)Returns the next power of two that is equal to, or greater than, the argument.
Mathf.PerlinNoise(x, y)Generate 2D Perlin noise.
Mathf.PingPong(t, length)PingPong returns a value that will increment and decrement between the value 0 and length.
Mathf.Pow(f, p)Returns f raised to power p.
Mathf.Repeat(t, length)Loops the value t, so that it is never larger than length and never smaller than 0.
Mathf.Round(f)Returns f rounded to the nearest integer.
Mathf.Sign(f)Returns the sign of f.
Mathf.Sin(f)Returns the sine of angle f.
Mathf.SmoothStep(from, to, t)Interpolates between min and max with smoothing at the limits.
Mathf.Sqrt(f)Returns square root of f.
Mathf.Tan(f)Returns the tangent of angle f in radians.