Class MathHelper
Contains common mathematical functions and constants.
Inherited Members
Namespace: OpenTK.Mathematics
Assembly: OpenTK.Mathematics.dll
Syntax
public static class MathHelper
Fields
E
Defines the value of E as a float.
Declaration
public const float E = 2.7182817
Field Value
Type | Description |
---|---|
float |
Log10E
Defines the base-10 logarithm of E.
Declaration
public const float Log10E = 0.4342945
Field Value
Type | Description |
---|---|
float |
Log2E
Defines the base-2 logarithm of E.
Declaration
public const float Log2E = 1.442695
Field Value
Type | Description |
---|---|
float |
Pi
Defines the value of Pi as a float.
Declaration
public const float Pi = 3.1415927
Field Value
Type | Description |
---|---|
float |
PiOver2
Defines the value of Pi divided by two as a float.
Declaration
public const float PiOver2 = 1.5707964
Field Value
Type | Description |
---|---|
float |
PiOver3
Defines the value of Pi divided by three as a float.
Declaration
public const float PiOver3 = 1.0471976
Field Value
Type | Description |
---|---|
float |
PiOver4
Defines the value of Pi divided by four as a float.
Declaration
public const float PiOver4 = 0.7853982
Field Value
Type | Description |
---|---|
float |
PiOver6
Defines the value of Pi divided by six as a float.
Declaration
public const float PiOver6 = 0.5235988
Field Value
Type | Description |
---|---|
float |
ThreePiOver2
Defines the value of Pi multiplied by 3 and divided by two as a float.
Declaration
public const float ThreePiOver2 = 4.712389
Field Value
Type | Description |
---|---|
float |
TwoPi
Defines the value of Pi multiplied by two as a float.
Declaration
public const float TwoPi = 6.2831855
Field Value
Type | Description |
---|---|
float |
Methods
Abs(decimal)
Returns the absolute value of a decimal number.
Declaration
[Pure]
public static decimal Abs(decimal n)
Parameters
Type | Name | Description |
---|---|---|
decimal | n | A number that is greater than or equal to MinValue, but less than or equal to MaxValue. |
Returns
Type | Description |
---|---|
decimal | A decimal number, x, such that 0 ≤ x ≤ MaxValue. |
Abs(double)
Returns the absolute value of a double number.
Declaration
[Pure]
public static double Abs(double n)
Parameters
Type | Name | Description |
---|---|---|
double | n | A number that is greater than or equal to MinValue, but less than or equal to MaxValue. |
Returns
Type | Description |
---|---|
double | A double number, x, such that 0 ≤ x ≤ MaxValue. |
Abs(short)
Returns the absolute value of a short number.
Declaration
[Pure]
public static short Abs(short n)
Parameters
Type | Name | Description |
---|---|---|
short | n | A number that is greater than or equal to MinValue, but less than or equal to MaxValue. |
Returns
Type | Description |
---|---|
short | A short number, x, such that 0 ≤ x ≤ MaxValue. |
Abs(int)
Returns the absolute value of a int number.
Declaration
[Pure]
public static int Abs(int n)
Parameters
Type | Name | Description |
---|---|---|
int | n | A number that is greater than or equal to MinValue, but less than or equal to MaxValue. |
Returns
Type | Description |
---|---|
int | A int number, x, such that 0 ≤ x ≤ MaxValue. |
Abs(long)
Returns the absolute value of a long number.
Declaration
[Pure]
public static long Abs(long n)
Parameters
Type | Name | Description |
---|---|---|
long | n | A number that is greater than or equal to MinValue, but less than or equal to MaxValue. |
Returns
Type | Description |
---|---|
long | A long number, x, such that 0 ≤ x ≤ MaxValue. |
Abs(sbyte)
Returns the absolute value of a sbyte number.
Declaration
[Pure]
public static sbyte Abs(sbyte n)
Parameters
Type | Name | Description |
---|---|---|
sbyte | n | A number that is greater than or equal to MinValue, but less than or equal to MaxValue. |
Returns
Type | Description |
---|---|
sbyte | A sbyte number, x, such that 0 ≤ x ≤ MaxValue. |
Abs(float)
Returns the absolute value of a float number.
Declaration
[Pure]
public static float Abs(float n)
Parameters
Type | Name | Description |
---|---|---|
float | n | A number that is greater than or equal to MinValue, but less than or equal to MaxValue. |
Returns
Type | Description |
---|---|
float | A float number, x, such that 0 ≤ x ≤ MaxValue. |
Acos(double)
Returns the arc sine of the specified angle.
Declaration
[Pure]
public static double Acos(double radians)
Parameters
Type | Name | Description |
---|---|---|
double | radians | The specified angle. |
Returns
Type | Description |
---|---|
double | Arc sine of the specified angle. If radians is equal to NaN, NegativeInfinity, or PositiveInfinity, this method returns NaN. |
ApproximatelyEqual(float, float, int)
Approximates floating point equality with a maximum number of different bits. This is typically used in place of an epsilon comparison. see: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ see: https://stackoverflow.com/questions/3874627/floating-point-comparison-functions-for-c-sharp.
Declaration
[Pure]
public static bool ApproximatelyEqual(float a, float b, int maxDeltaBits)
Parameters
Type | Name | Description |
---|---|---|
float | a | the first value to compare. |
float | b |
|
int | maxDeltaBits | the number of floating point bits to check. |
Returns
Type | Description |
---|---|
bool | true if the values are approximately equal; otherwise, false. |
ApproximatelyEqualEpsilon(double, double, double)
Approximates double-precision floating point equality by an epsilon (maximum error) value. This method is designed as a "fits-all" solution and attempts to handle as many cases as possible.
Declaration
[Pure]
public static bool ApproximatelyEqualEpsilon(double a, double b, double epsilon)
Parameters
Type | Name | Description |
---|---|---|
double | a | The first float. |
double | b | The second float. |
double | epsilon | The maximum error between the two. |
Returns
Type | Description |
---|---|
bool |
ApproximatelyEqualEpsilon(float, float, float)
Approximates single-precision floating point equality by an epsilon (maximum error) value. This method is designed as a "fits-all" solution and attempts to handle as many cases as possible.
Declaration
[Pure]
public static bool ApproximatelyEqualEpsilon(float a, float b, float epsilon)
Parameters
Type | Name | Description |
---|---|---|
float | a | The first float. |
float | b | The second float. |
float | epsilon | The maximum error between the two. |
Returns
Type | Description |
---|---|
bool |
ApproximatelyEquivalent(double, double, double)
Approximates equivalence between two double-precision floating-point numbers on a direct human scale. It is important to note that this does not approximate equality - instead, it merely checks whether or not two numbers could be considered equivalent to each other within a certain tolerance. The tolerance is inclusive.
Declaration
[Pure]
public static bool ApproximatelyEquivalent(double a, double b, double tolerance)
Parameters
Type | Name | Description |
---|---|---|
double | a | The first value to compare. |
double | b | The second value to compare. |
double | tolerance | The tolerance within which the two values would be considered equivalent. |
Returns
Type | Description |
---|---|
bool | Whether or not the values can be considered equivalent within the tolerance. |
ApproximatelyEquivalent(float, float, float)
Approximates equivalence between two single-precision floating-point numbers on a direct human scale. It is important to note that this does not approximate equality - instead, it merely checks whether or not two numbers could be considered equivalent to each other within a certain tolerance. The tolerance is inclusive.
Declaration
[Pure]
public static bool ApproximatelyEquivalent(float a, float b, float tolerance)
Parameters
Type | Name | Description |
---|---|---|
float | a | The first value to compare. |
float | b | The second value to compare. |
float | tolerance | The tolerance within which the two values would be considered equivalent. |
Returns
Type | Description |
---|---|
bool | Whether or not the values can be considered equivalent within the tolerance. |
Asin(double)
Returns the arc sine of the specified angle.
Declaration
[Pure]
public static double Asin(double radians)
Parameters
Type | Name | Description |
---|---|---|
double | radians | The specified angle. |
Returns
Type | Description |
---|---|
double | Arc sine of the specified angle. If radians is equal to NaN, NegativeInfinity, or PositiveInfinity, this method returns NaN. |
Atan(double)
Returns the arc tangent of the specified angle.
Declaration
[Pure]
public static double Atan(double radians)
Parameters
Type | Name | Description |
---|---|---|
double | radians | The specified angle. |
Returns
Type | Description |
---|---|
double | Arc tangent of the specified angle. If radians is equal to NaN, NegativeInfinity, or PositiveInfinity, this method returns NaN. |
Atan2(double, double)
Returns the angle whose tangent is the quotient of two specified numbers.
Declaration
[Pure]
public static double Atan2(double y, double x)
Parameters
Type | Name | Description |
---|---|---|
double | y | The y coordinate of a point. |
double | x | The x coordinate of a point. |
Returns
Type | Description |
---|---|
double | An angle, θ, measured in radians, such that -π ≤ θ ≤ π, and tan(θ) = y / x, where (x, y) is a point in the Cartesian plane. |
BigMul(int, int)
Produces the full product of two 32-bit numbers.
Declaration
[Pure]
public static long BigMul(int a, int b)
Parameters
Type | Name | Description |
---|---|---|
int | a | The first number to multiply. |
int | b | The second number to multiply. |
Returns
Type | Description |
---|---|
long | The number containing the product of the specified numbers. |
BinomialCoefficient(int, int)
Calculates the binomial coefficient n
above k
.
Declaration
[Pure]
public static long BinomialCoefficient(int n, int k)
Parameters
Type | Name | Description |
---|---|---|
int | n | The n. |
int | k | The k. |
Returns
Type | Description |
---|---|
long | n! / (k! * (n - k)!). |
Ceiling(decimal)
Returns the smallest integral value greater than or equal to the specified number.
Declaration
[Pure]
public static decimal Ceiling(decimal n)
Parameters
Type | Name | Description |
---|---|---|
decimal | n | A decimal number. |
Returns
Type | Description |
---|---|
decimal | The smallest integral value that is greater than or equal to n. Note that this method returns a Decimal instead of an integral type. |
Ceiling(double)
Returns the smallest integral value greater than or equal to the specified number.
Declaration
[Pure]
public static double Ceiling(double n)
Parameters
Type | Name | Description |
---|---|---|
double | n | A double-precision floating-point number. |
Returns
Type | Description |
---|---|
double | The smallest integral value that is greater than or equal to n. If n is equal to NaN, NegativeInfinity, or PositiveInfinity, that value is returned. Note that this method returns a Double instead of an integral type. |
Clamp(double, double, double)
Clamps a number between a minimum and a maximum.
Declaration
[Pure]
public static double Clamp(double n, double min, double max)
Parameters
Type | Name | Description |
---|---|---|
double | n | The number to clamp. |
double | min | The minimum allowed value. |
double | max | The maximum allowed value. |
Returns
Type | Description |
---|---|
double | min, if n is lower than min; max, if n is higher than max; n otherwise. |
Clamp(int, int, int)
Clamps a number between a minimum and a maximum.
Declaration
[Pure]
public static int Clamp(int n, int min, int max)
Parameters
Type | Name | Description |
---|---|---|
int | n | The number to clamp. |
int | min | The minimum allowed value. |
int | max | The maximum allowed value. |
Returns
Type | Description |
---|---|
int | min, if n is lower than min; max, if n is higher than max; n otherwise. |
Clamp(float, float, float)
Clamps a number between a minimum and a maximum.
Declaration
[Pure]
public static float Clamp(float n, float min, float max)
Parameters
Type | Name | Description |
---|---|---|
float | n | The number to clamp. |
float | min | The minimum allowed value. |
float | max | The maximum allowed value. |
Returns
Type | Description |
---|---|
float | min, if n is lower than min; max, if n is higher than max; n otherwise. |
ClampAngle(double)
Clamps an angle to the range [0, 360).
Declaration
public static double ClampAngle(double angle)
Parameters
Type | Name | Description |
---|---|---|
double | angle | The angle to clamp in degrees. |
Returns
Type | Description |
---|---|
double | The clamped angle in the range [0, 360). |
ClampAngle(float)
Clamps an angle to the range [0, 360).
Declaration
public static float ClampAngle(float angle)
Parameters
Type | Name | Description |
---|---|---|
float | angle | The angle to clamp in degrees. |
Returns
Type | Description |
---|---|
float | The clamped angle in the range [0, 360). |
ClampRadians(double)
Clamps an angle to the range [0, 2π).
Declaration
public static double ClampRadians(double angle)
Parameters
Type | Name | Description |
---|---|---|
double | angle | The angle to clamp in radians. |
Returns
Type | Description |
---|---|
double | The clamped angle in the range [0, 2π). |
ClampRadians(float)
Clamps an angle to the range [0, 2π).
Declaration
public static float ClampRadians(float angle)
Parameters
Type | Name | Description |
---|---|---|
float | angle | The angle to clamp in radians. |
Returns
Type | Description |
---|---|
float | The clamped angle in the range [0, 2π). |
Cos(double)
Returns the cosine of the specified angle.
Declaration
[Pure]
public static double Cos(double radians)
Parameters
Type | Name | Description |
---|---|---|
double | radians | The specified angle. |
Returns
Type | Description |
---|---|
double | Cosine of the angle. If radians is equal to NaN, NegativeInfinity, or PositiveInfinity, this method returns NaN. |
Cosh(double)
Returns the hyperbolic cosine of the specified angle.
Declaration
[Pure]
public static double Cosh(double radians)
Parameters
Type | Name | Description |
---|---|---|
double | radians | The specified angle. |
Returns
Type | Description |
---|---|
double | Hyperbolic cosine of the specified angle. If radians is equal to NaN, NegativeInfinity, or PositiveInfinity, this method returns NaN. |
DegreesToRadians(double)
Convert degrees to radians.
Declaration
[Pure]
public static double DegreesToRadians(double degrees)
Parameters
Type | Name | Description |
---|---|---|
double | degrees | An angle in degrees. |
Returns
Type | Description |
---|---|
double | The angle expressed in radians. |
DegreesToRadians(float)
Convert degrees to radians.
Declaration
[Pure]
public static float DegreesToRadians(float degrees)
Parameters
Type | Name | Description |
---|---|---|
float | degrees | An angle in degrees. |
Returns
Type | Description |
---|---|
float | The angle expressed in radians. |
DivRem(int, int, out int)
Calculates the quotient of two integers and also returns the remainder in an output parameter.
Declaration
[Pure]
public static int DivRem(int a, int b, out int result)
Parameters
Type | Name | Description |
---|---|---|
int | a | The dividend. |
int | b | The divisor. |
int | result | The remainder. |
Returns
Type | Description |
---|---|
int | The quotient of the specified numbers. |
Exceptions
Type | Condition |
---|---|
DivideByZeroException | b is zero. |
DivRem(long, long, out long)
Calculates the quotient of two longs and also returns the remainder in an output parameter.
Declaration
[Pure]
public static long DivRem(long a, long b, out long result)
Parameters
Type | Name | Description |
---|---|---|
long | a | The dividend. |
long | b | The divisor. |
long | result | The remainder. |
Returns
Type | Description |
---|---|
long | The quotient of the specified numbers. |
Exceptions
Type | Condition |
---|---|
DivideByZeroException | b is zero. |
Exp(double)
Returns e raised to the specified power.
Declaration
[Pure]
public static double Exp(double n)
Parameters
Type | Name | Description |
---|---|---|
double | n | The specified power. |
Returns
Type | Description |
---|---|
double | The number e raised to the power n. If n equals NaN or PositiveInfinity, that value is returned. If n equals NegativeInfinity, 0 is returned. |
Factorial(int)
Calculates the factorial of a given natural number.
Declaration
[Pure]
public static long Factorial(int n)
Parameters
Type | Name | Description |
---|---|---|
int | n | The number. |
Returns
Type | Description |
---|---|
long | The factorial of |
Floor(decimal)
Returns the largest integral value less than or equal to the specified number.
Declaration
[Pure]
public static decimal Floor(decimal n)
Parameters
Type | Name | Description |
---|---|---|
decimal | n | A decimal number. |
Returns
Type | Description |
---|---|
decimal | Returns the largest integral value less than or equal to the specified decimal number. |
Floor(double)
Returns the largest integral value less than or equal to the specified number.
Declaration
[Pure]
public static double Floor(double n)
Parameters
Type | Name | Description |
---|---|---|
double | n | A double-precision floating-point number. |
Returns
Type | Description |
---|---|
double | Returns the largest integral value less than or equal to the specified double-precision floating-point number. |
IEEERemainder(double, double)
Returns the remainder resulting from the division of a specified number by another specified number.
Declaration
[Pure]
public static double IEEERemainder(double a, double b)
Parameters
Type | Name | Description |
---|---|---|
double | a | A dividend. |
double | b | A divisor. |
Returns
Type | Description |
---|---|
double | A number equal to a - (b Q), where Q is the quotient of a / b rounded to the nearest integer (if a / b falls halfway between two integers, the even integer is returned). If a - (b Q) is zero, the value +0 is returned if a is positive, or -0 if a is negative. If b = 0, NaN is returned. |
InverseSqrtFast(double)
Returns an approximation of the inverse square root of left number.
Declaration
[Pure]
public static double InverseSqrtFast(double x)
Parameters
Type | Name | Description |
---|---|---|
double | x | A number. |
Returns
Type | Description |
---|---|
double | An approximation of the inverse square root of the specified number, with an upper error bound of 0.001. |
Remarks
This is an improved implementation of the the method known as Carmack's inverse square root which is found in the Quake III source code. This implementation comes from http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see http://www.beyond3d.com/content/articles/8/. double magic number from: https://cs.uwaterloo.ca/~m32rober/rsqrt.pdf chapter 4.8.
InverseSqrtFast(float)
Returns an approximation of the inverse square root of left number.
Declaration
[Pure]
public static float InverseSqrtFast(float x)
Parameters
Type | Name | Description |
---|---|---|
float | x | A number. |
Returns
Type | Description |
---|---|
float | An approximation of the inverse square root of the specified number, with an upper error bound of 0.001. |
Remarks
This is an improved implementation of the the method known as Carmack's inverse square root which is found in the Quake III source code. This implementation comes from http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see http://www.beyond3d.com/content/articles/8/.
Lerp(double, double, double)
Linearly interpolates between a and b by t.
Declaration
[Pure]
public static double Lerp(double start, double end, double t)
Parameters
Type | Name | Description |
---|---|---|
double | start | Start value. |
double | end | End value. |
double | t | Value of the interpollation between a and b. Clamped to [0, 1]. |
Returns
Type | Description |
---|---|
double | The interpolated result between the a and b values. |
Lerp(float, float, float)
Linearly interpolates between a and b by t.
Declaration
[Pure]
public static float Lerp(float start, float end, float t)
Parameters
Type | Name | Description |
---|---|---|
float | start | Start value. |
float | end | End value. |
float | t | Value of the interpollation between a and b. Clamped to [0, 1]. |
Returns
Type | Description |
---|---|
float | The interpolated result between the a and b values. |
Log(double, double)
Returns the logarithm of a specified number in a specified base.
Declaration
[Pure]
public static double Log(double n, double newBase)
Parameters
Type | Name | Description |
---|---|---|
double | n | The specified number. |
double | newBase | The specified base. |
Returns
Type | Description |
---|---|
double | The base newBase logarithm of n. |
Log(double)
Returns the natural (base e) logarithm of a specified number.
Declaration
[Pure]
public static double Log(double n)
Parameters
Type | Name | Description |
---|---|---|
double | n | A number whose logarithm is to be found. |
Returns
Type | Description |
---|---|
double | The natural logarithm of n. |
Log10(double)
Returns the base 10 logarithm of a specified number.
Declaration
[Pure]
public static double Log10(double n)
Parameters
Type | Name | Description |
---|---|---|
double | n | The specified number. |
Returns
Type | Description |
---|---|
double | The base 10 log of n. |
Log2(double)
Returns the base 2 logarithm of a specified number.
Declaration
[Pure]
public static double Log2(double n)
Parameters
Type | Name | Description |
---|---|---|
double | n | The specified number. |
Returns
Type | Description |
---|---|
double | The base 2 log of n. |
Remarks
This one will be implemented by System.Math from .netcore 3.0 and onwards.
MapRange(double, double, double, double, double)
Scales the specified number linearly between a minimum and a maximum.
Declaration
[Pure]
public static double MapRange(double value, double valueMin, double valueMax, double resultMin, double resultMax)
Parameters
Type | Name | Description |
---|---|---|
double | value | The number to scale. |
double | valueMin | The minimum expected number (inclusive). |
double | valueMax | The maximum expected number (inclusive). |
double | resultMin | The minimum output number (inclusive). |
double | resultMax | The maximum output number (inclusive). |
Returns
Type | Description |
---|---|
double | The number, scaled linearly between min and max. |
Remarks
If the value range is zero, this function will throw a divide by zero exception.
MapRange(int, int, int, int, int)
Scales the specified number linearly between a minimum and a maximum.
Declaration
[Pure]
public static int MapRange(int value, int valueMin, int valueMax, int resultMin, int resultMax)
Parameters
Type | Name | Description |
---|---|---|
int | value | The number to scale. |
int | valueMin | The minimum expected number (inclusive). |
int | valueMax | The maximum expected number (inclusive). |
int | resultMin | The minimum output number (inclusive). |
int | resultMax | The maximum output number (inclusive). |
Returns
Type | Description |
---|---|
int | The number, scaled linearly between min and max. |
Remarks
If the value range is zero, this function will throw a divide by zero exception.
MapRange(float, float, float, float, float)
Scales the specified number linearly between a minimum and a maximum.
Declaration
[Pure]
public static float MapRange(float value, float valueMin, float valueMax, float resultMin, float resultMax)
Parameters
Type | Name | Description |
---|---|---|
float | value | The number to scale. |
float | valueMin | The minimum expected number (inclusive). |
float | valueMax | The maximum expected number (inclusive). |
float | resultMin | The minimum output number (inclusive). |
float | resultMax | The maximum output number (inclusive). |
Returns
Type | Description |
---|---|
float | The number, scaled linearly between min and max. |
Remarks
If the value range is zero, this function will throw a divide by zero exception.
Max(byte, byte)
Returns the larger of two bytes.
Declaration
[Pure]
public static byte Max(byte a, byte b)
Parameters
Type | Name | Description |
---|---|---|
byte | a | The first of two bytes to compare. |
byte | b | The second of two bytes to compare. |
Returns
Type | Description |
---|---|
byte | Parameter a or b, whichever is larger. |
Max(decimal, decimal)
Returns the larger of two decimals.
Declaration
[Pure]
public static decimal Max(decimal a, decimal b)
Parameters
Type | Name | Description |
---|---|---|
decimal | a | The first of two decimals to compare. |
decimal | b | The second of two decimals to compare. |
Returns
Type | Description |
---|---|
decimal | Parameter a or b, whichever is larger. |
Max(short, short)
Returns the larger of two shorts.
Declaration
[Pure]
public static short Max(short a, short b)
Parameters
Type | Name | Description |
---|---|---|
short | a | The first of two shorts to compare. |
short | b | The second of two shorts to compare. |
Returns
Type | Description |
---|---|
short | Parameter a or b, whichever is larger. |
Max(int, int)
Returns the larger of two ints.
Declaration
[Pure]
public static int Max(int a, int b)
Parameters
Type | Name | Description |
---|---|---|
int | a | The first of two ints to compare. |
int | b | The second of two ints to compare. |
Returns
Type | Description |
---|---|
int | Parameter a or b, whichever is larger. |
Max(long, long)
Returns the larger of two longs.
Declaration
[Pure]
public static long Max(long a, long b)
Parameters
Type | Name | Description |
---|---|---|
long | a | The first of two longs to compare. |
long | b | The second of two longs to compare. |
Returns
Type | Description |
---|---|
long | Parameter a or b, whichever is larger. |
Max(sbyte, sbyte)
Returns the larger of two sbytes.
Declaration
[Pure]
public static sbyte Max(sbyte a, sbyte b)
Parameters
Type | Name | Description |
---|---|---|
sbyte | a | The first of two sbytes to compare. |
sbyte | b | The second of two sbytes to compare. |
Returns
Type | Description |
---|---|
sbyte | Parameter a or b, whichever is larger. |
Max(float, float)
Returns the larger of two floats.
Declaration
[Pure]
public static float Max(float a, float b)
Parameters
Type | Name | Description |
---|---|---|
float | a | The first of two floats to compare. |
float | b | The second of two floats to compare. |
Returns
Type | Description |
---|---|
float | Parameter a or b, whichever is larger. |
Max(ushort, ushort)
Returns the larger of two ushorts.
Declaration
[Pure]
public static ushort Max(ushort a, ushort b)
Parameters
Type | Name | Description |
---|---|---|
ushort | a | The first of two ushorts to compare. |
ushort | b | The second of two ushorts to compare. |
Returns
Type | Description |
---|---|
ushort | Parameter a or b, whichever is larger. |
Max(uint, uint)
Returns the larger of two uints.
Declaration
[Pure]
public static uint Max(uint a, uint b)
Parameters
Type | Name | Description |
---|---|---|
uint | a | The first of two uints to compare. |
uint | b | The second of two uints to compare. |
Returns
Type | Description |
---|---|
uint | Parameter a or b, whichever is larger. |
Max(ulong, ulong)
Returns the larger of two ulongs.
Declaration
[Pure]
public static ulong Max(ulong a, ulong b)
Parameters
Type | Name | Description |
---|---|---|
ulong | a | The first of two ulongs to compare. |
ulong | b | The second of two ulongs to compare. |
Returns
Type | Description |
---|---|
ulong | Parameter a or b, whichever is larger. |
Min(byte, byte)
Returns the smaller of two bytes.
Declaration
[Pure]
public static byte Min(byte a, byte b)
Parameters
Type | Name | Description |
---|---|---|
byte | a | The first of two bytes to compare. |
byte | b | The second of two bytes to compare. |
Returns
Type | Description |
---|---|
byte | Parameter a or b, whichever is smaller. |
Min(decimal, decimal)
Returns the smaller of two decimals.
Declaration
[Pure]
public static decimal Min(decimal a, decimal b)
Parameters
Type | Name | Description |
---|---|---|
decimal | a | The first of two decimals to compare. |
decimal | b | The second of two decimals to compare. |
Returns
Type | Description |
---|---|
decimal | Parameter a or b, whichever is smaller. |
Min(double, double)
Returns the smaller of two floats.
Declaration
[Pure]
public static double Min(double a, double b)
Parameters
Type | Name | Description |
---|---|---|
double | a | The first of two floats to compare. |
double | b | The second of two floats to compare. |
Returns
Type | Description |
---|---|
double | Parameter a or b, whichever is smaller. |
Min(short, short)
Returns the smaller of two shorts.
Declaration
[Pure]
public static short Min(short a, short b)
Parameters
Type | Name | Description |
---|---|---|
short | a | The first of two shorts to compare. |
short | b | The second of two shorts to compare. |
Returns
Type | Description |
---|---|
short | Parameter a or b, whichever is smaller. |
Min(int, int)
Returns the smaller of two ints.
Declaration
[Pure]
public static int Min(int a, int b)
Parameters
Type | Name | Description |
---|---|---|
int | a | The first of two ints to compare. |
int | b | The second of two ints to compare. |
Returns
Type | Description |
---|---|
int | Parameter a or b, whichever is smaller. |
Min(long, long)
Returns the smaller of two longs.
Declaration
[Pure]
public static long Min(long a, long b)
Parameters
Type | Name | Description |
---|---|---|
long | a | The first of two longs to compare. |
long | b | The second of two longs to compare. |
Returns
Type | Description |
---|---|
long | Parameter a or b, whichever is smaller. |
Min(sbyte, sbyte)
Returns the smaller of two sbytes.
Declaration
[Pure]
public static sbyte Min(sbyte a, sbyte b)
Parameters
Type | Name | Description |
---|---|---|
sbyte | a | The first of two sbytes to compare. |
sbyte | b | The second of two sbytes to compare. |
Returns
Type | Description |
---|---|
sbyte | Parameter a or b, whichever is smaller. |
Min(float, float)
Returns the smaller of two floats.
Declaration
[Pure]
public static float Min(float a, float b)
Parameters
Type | Name | Description |
---|---|---|
float | a | The first of two floats to compare. |
float | b | The second of two floats to compare. |
Returns
Type | Description |
---|---|
float | Parameter a or b, whichever is smaller. |
Min(ushort, ushort)
Returns the smaller of two ushorts.
Declaration
[Pure]
public static ushort Min(ushort a, ushort b)
Parameters
Type | Name | Description |
---|---|---|
ushort | a | The first of two ushorts to compare. |
ushort | b | The second of two ushorts to compare. |
Returns
Type | Description |
---|---|
ushort | Parameter a or b, whichever is smaller. |
Min(uint, uint)
Returns the smaller of two uints.
Declaration
[Pure]
public static uint Min(uint a, uint b)
Parameters
Type | Name | Description |
---|---|---|
uint | a | The first of two uints to compare. |
uint | b | The second of two uints to compare. |
Returns
Type | Description |
---|---|
uint | Parameter a or b, whichever is smaller. |
Min(ulong, ulong)
Returns the smaller of two ulongs.
Declaration
[Pure]
public static ulong Min(ulong a, ulong b)
Parameters
Type | Name | Description |
---|---|---|
ulong | a | The first of two ulongs to compare. |
ulong | b | The second of two ulongs to compare. |
Returns
Type | Description |
---|---|
ulong | Parameter a or b, whichever is smaller. |
NextPowerOfTwo(double)
Returns the next power of two that is greater than or equal to the specified number.
Declaration
[Pure]
public static double NextPowerOfTwo(double n)
Parameters
Type | Name | Description |
---|---|---|
double | n | The specified number. |
Returns
Type | Description |
---|---|
double | The next power of two. |
NextPowerOfTwo(int)
Returns the next power of two that is greater than or equal to the specified number.
Declaration
[Pure]
public static int NextPowerOfTwo(int n)
Parameters
Type | Name | Description |
---|---|---|
int | n | The specified number. |
Returns
Type | Description |
---|---|
int | The next power of two. |
NextPowerOfTwo(long)
Returns the next power of two that is greater than or equal to the specified number.
Declaration
[Pure]
public static long NextPowerOfTwo(long n)
Parameters
Type | Name | Description |
---|---|---|
long | n | The specified number. |
Returns
Type | Description |
---|---|
long | The next power of two. |
NextPowerOfTwo(float)
Returns the next power of two that is greater than or equal to the specified number.
Declaration
[Pure]
public static float NextPowerOfTwo(float n)
Parameters
Type | Name | Description |
---|---|---|
float | n | The specified number. |
Returns
Type | Description |
---|---|
float | The next power of two. |
NormalizeAngle(double)
Normalizes an angle to the range (-180, 180].
Declaration
public static double NormalizeAngle(double angle)
Parameters
Type | Name | Description |
---|---|---|
double | angle | The angle in degrees to normalize. |
Returns
Type | Description |
---|---|
double | The normalized angle in the range (-180, 180]. |
NormalizeAngle(float)
Normalizes an angle to the range (-180, 180].
Declaration
public static float NormalizeAngle(float angle)
Parameters
Type | Name | Description |
---|---|---|
float | angle | The angle in degrees to normalize. |
Returns
Type | Description |
---|---|
float | The normalized angle in the range (-180, 180]. |
NormalizeRadians(double)
Normalizes an angle to the range (-π, π].
Declaration
public static double NormalizeRadians(double angle)
Parameters
Type | Name | Description |
---|---|---|
double | angle | The angle in radians to normalize. |
Returns
Type | Description |
---|---|
double | The normalized angle in the range (-π, π]. |
NormalizeRadians(float)
Normalizes an angle to the range (-π, π].
Declaration
public static float NormalizeRadians(float angle)
Parameters
Type | Name | Description |
---|---|---|
float | angle | The angle in radians to normalize. |
Returns
Type | Description |
---|---|
float | The normalized angle in the range (-π, π]. |
Pow(double, double)
Returns a specified number raised to the specified power.
Declaration
[Pure]
public static double Pow(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
double | x | A double-precision floating-point number to be raised to a power. |
double | y | A double-precision floating-point number that specifies a power. |
Returns
Type | Description |
---|---|
double | The number x raised to the power y. |
RadiansToDegrees(double)
Convert radians to degrees.
Declaration
[Pure]
public static double RadiansToDegrees(double radians)
Parameters
Type | Name | Description |
---|---|---|
double | radians | An angle in radians. |
Returns
Type | Description |
---|---|
double | The angle expressed in degrees. |
RadiansToDegrees(float)
Convert radians to degrees.
Declaration
[Pure]
public static float RadiansToDegrees(float radians)
Parameters
Type | Name | Description |
---|---|---|
float | radians | An angle in radians. |
Returns
Type | Description |
---|---|
float | The angle expressed in degrees. |
Round(decimal, int, MidpointRounding)
Rounds a decimal value to a specified number of fractional digits, and uses the specified rounding convention for midpoint values.
Declaration
[Pure]
public static decimal Round(decimal d, int digits, MidpointRounding mode)
Parameters
Type | Name | Description |
---|---|---|
decimal | d | A decimal number to be rounded. |
int | digits | The number of decimal places in the return value. |
MidpointRounding | mode | Specification for how to round d if it is midway between two other numbers. |
Returns
Type | Description |
---|---|
decimal | The number nearest to d that contains a number of fractional digits equal to digits. If d has fewer fractional digits than digits, d is returned unchanged. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | digits is less than 0 or greater than 28. |
ArgumentException | mode is not a valid value of MidpointRounding. |
OverflowException | The result is outside the range of a Decimal. |
Round(decimal, int)
Rounds a decimal value to a specified number of fractional digits, and rounds midpoint values to the nearest even number.
Declaration
[Pure]
public static decimal Round(decimal d, int digits)
Parameters
Type | Name | Description |
---|---|---|
decimal | d | A decimal number to be rounded. |
int | digits | The number of fractional digits in the return value. |
Returns
Type | Description |
---|---|
decimal | The number nearest to d that contains a number of fractional digits equal to digits. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | digits is less than 0 or greater than 15. |
OverflowException | The result is outside the range of a Decimal. |
Round(decimal, MidpointRounding)
Rounds a decimal value to the nearest integer, and uses the specified rounding convention for midpoint values.
Declaration
[Pure]
public static decimal Round(decimal d, MidpointRounding mode)
Parameters
Type | Name | Description |
---|---|---|
decimal | d | A decimal number to be rounded. |
MidpointRounding | mode | Specification for how to round d if it is midway between two other numbers. |
Returns
Type | Description |
---|---|
decimal | The integer nearest d. If d is halfway between two numbers, one of which is even and the other odd, then mode determines which of the two is returned. Note that this method returns a Decimal instead of an integral type. |
Exceptions
Type | Condition |
---|---|
ArgumentException | mode is not a valid value of MidpointRounding. |
OverflowException | The result is outside the range of a Decimal. |
Round(decimal)
Rounds a decimal value to the nearest integral value, and rounds midpoint values to the nearest even number.
Declaration
[Pure]
public static decimal Round(decimal d)
Parameters
Type | Name | Description |
---|---|---|
decimal | d | A decimal number to be rounded. |
Returns
Type | Description |
---|---|
decimal | The integer nearest the d parameter. If the fractional component of d is halfway between two integers, one of which is even and the other odd, the even number is returned. Note that this method returns a Decimal instead of an integral type. |
Exceptions
Type | Condition |
---|---|
OverflowException | The result is outside the range of a Decimal. |
Round(double, int, MidpointRounding)
Rounds a double-precision floating-point value to a specified number of fractional digits, and uses the specified rounding convention for midpoint values.
Declaration
[Pure]
public static double Round(double d, int digits, MidpointRounding mode)
Parameters
Type | Name | Description |
---|---|---|
double | d | A double-precision floating-point number to be rounded. |
int | digits | The number of fractional digits in the return value. |
MidpointRounding | mode | Specification for how to round d if it is midway between two other numbers. |
Returns
Type | Description |
---|---|
double | The number nearest to d that has a number of fractional digits equal to digits. If d has fewer fractional digits than digits, d is returned unchanged. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | digits is less than 0 or greater than 15. |
ArgumentException | mode is not a valid value of MidpointRounding. |
Round(double, int)
Rounds a double-precision floating-point value to a specified number of fractional digits, and rounds midpoint values to the nearest even number.
Declaration
[Pure]
public static double Round(double d, int digits)
Parameters
Type | Name | Description |
---|---|---|
double | d | A double-precision floating-point number to be rounded. |
int | digits | The number of fractional digits in the return value. |
Returns
Type | Description |
---|---|
double | The number nearest to value that contains a number of fractional digits equal to digits. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | digits is less than 0 or greater than 15. |
Round(double, MidpointRounding)
Rounds a double-precision floating-point value to the nearest integer, and uses the specified rounding convention for midpoint values.
Declaration
[Pure]
public static double Round(double d, MidpointRounding mode)
Parameters
Type | Name | Description |
---|---|---|
double | d | A double-precision floating-point number to be rounded. |
MidpointRounding | mode | Specification for how to round d if it is midway between two other numbers. |
Returns
Type | Description |
---|---|
double | The integer nearest d. If d is halfway between two integers, one of which is even and the other odd, then mode determines which of the two is returned. Note that this method returns a Double instead of an integral type. |
Exceptions
Type | Condition |
---|---|
ArgumentException | mode is not a valid value of MidpointRounding. |
Round(double)
Rounds a double-precision floating-point value to the nearest integral value, and rounds midpoint values to the nearest even number.
Declaration
[Pure]
public static double Round(double d)
Parameters
Type | Name | Description |
---|---|---|
double | d | A double-precision floating-point number to be rounded. |
Returns
Type | Description |
---|---|
double | The integer nearest d. If the fractional component of d is halfway between two integers, one of which is even and the other odd, then the even number is returned. Note that this method returns a Double instead of an integral type. |
Sign(decimal)
Returns an integer that indicates the sign of a decimal.
Declaration
[Pure]
public static int Sign(decimal d)
Parameters
Type | Name | Description |
---|---|---|
decimal | d | A signed number. |
Returns
Type | Description |
---|---|
int | If d ≤ -1 returns -1, if 1 ≤ d returns 1 and if d = 0 returns 0. |
Sign(double)
Returns an integer that indicates the sign of a double.
Declaration
[Pure]
public static int Sign(double d)
Parameters
Type | Name | Description |
---|---|---|
double | d | A signed number. |
Returns
Type | Description |
---|---|
int | If d ≤ -1 returns -1, if 1 ≤ d returns 1 and if d = 0 returns 0. |
Sign(short)
Returns an integer that indicates the sign of a short.
Declaration
[Pure]
public static int Sign(short d)
Parameters
Type | Name | Description |
---|---|---|
short | d | A signed number. |
Returns
Type | Description |
---|---|
int | If d ≤ -1 returns -1, if 1 ≤ d returns 1 and if d = 0 returns 0. |
Sign(int)
Returns an integer that indicates the sign of a int.
Declaration
[Pure]
public static int Sign(int d)
Parameters
Type | Name | Description |
---|---|---|
int | d | A signed number. |
Returns
Type | Description |
---|---|
int | If d ≤ -1 returns -1, if 1 ≤ d returns 1 and if d = 0 returns 0. |
Sign(long)
Returns an integer that indicates the sign of a long.
Declaration
[Pure]
public static int Sign(long d)
Parameters
Type | Name | Description |
---|---|---|
long | d | A signed number. |
Returns
Type | Description |
---|---|
int | If d ≤ -1 returns -1, if 1 ≤ d returns 1 and if d = 0 returns 0. |
Sign(sbyte)
Returns an integer that indicates the sign of a sbyte.
Declaration
[Pure]
public static int Sign(sbyte d)
Parameters
Type | Name | Description |
---|---|---|
sbyte | d | A signed number. |
Returns
Type | Description |
---|---|
int | If d ≤ -1 returns -1, if 1 ≤ d returns 1 and if d = 0 returns 0. |
Sign(float)
Returns an integer that indicates the sign of a float.
Declaration
[Pure]
public static int Sign(float d)
Parameters
Type | Name | Description |
---|---|---|
float | d | A signed number. |
Returns
Type | Description |
---|---|
int | If d ≤ -1 returns -1, if 1 ≤ d returns 1 and if d = 0 returns 0. |
Sin(double)
Returns the sine of the specified angle.
Declaration
[Pure]
public static double Sin(double radians)
Parameters
Type | Name | Description |
---|---|---|
double | radians | The specified angle. |
Returns
Type | Description |
---|---|
double | Sine of the angle. If radians is equal to NaN, NegativeInfinity, or PositiveInfinity, this method returns NaN. |
Sinh(double)
Returns the hyperbolic sine of the specified angle.
Declaration
[Pure]
public static double Sinh(double radians)
Parameters
Type | Name | Description |
---|---|---|
double | radians | The specified angle. |
Returns
Type | Description |
---|---|
double | Hyperbolic sine of the specified angle. If radians is equal to NaN, NegativeInfinity, or PositiveInfinity, this method returns NaN. |
Sqrt(double)
Returns the square root of a specified number.
Declaration
[Pure]
public static double Sqrt(double n)
Parameters
Type | Name | Description |
---|---|---|
double | n | The number whose square root is to be found. |
Returns
Type | Description |
---|---|
double | The positive square root of n. |
Swap<T>(ref T, ref T)
Swaps two values.
Declaration
public static void Swap<T>(ref T a, ref T b)
Parameters
Type | Name | Description |
---|---|---|
T | a | The first value. |
T | b | The second value. |
Type Parameters
Name | Description |
---|---|
T | The type of the values to swap. |
Tan(double)
Returns the tangent of the specified angle.
Declaration
[Pure]
public static double Tan(double radians)
Parameters
Type | Name | Description |
---|---|---|
double | radians | The specified angle. |
Returns
Type | Description |
---|---|
double | Tangent of the specified angle. If radians is equal to NaN, NegativeInfinity, or PositiveInfinity, this method returns NaN. |
Tanh(double)
Returns the hyperbolic tangent of the specified angle.
Declaration
[Pure]
public static double Tanh(double radians)
Parameters
Type | Name | Description |
---|---|---|
double | radians | The specified angle. |
Returns
Type | Description |
---|---|
double | Hyperbolic tangent of the specified angle. If radians is equal to NaN, NegativeInfinity, or PositiveInfinity, this method returns NaN. |
Truncate(decimal)
Calculates the integral part of a specified decimal number.
Declaration
[Pure]
public static decimal Truncate(decimal d)
Parameters
Type | Name | Description |
---|---|---|
decimal | d | A number to truncate. |
Returns
Type | Description |
---|---|
decimal | The integral part of d; that is, the number that remains after any fractional digits have been discarded. |
Truncate(double)
Calculates the integral part of a specified double-precision floating-point number.
Declaration
[Pure]
public static double Truncate(double d)
Parameters
Type | Name | Description |
---|---|---|
double | d | A number to truncate. |
Returns
Type | Description |
---|---|
double | The integral part of d; that is, the number that remains after any fractional digits have been discarded, or one of the values listed in the following table. |