Class GorgonMathExtensions
Fluent extensions for mathematical operations on various numeric types.
Inherited Members
Namespace: Gorgon.Math
Assembly: Gorgon.Core.dll
Syntax
public static class GorgonMathExtensions
Remarks
This provides a fluent interface to numeric types (e.g. float, double, int, etc...) that will expose common mathematical functions without relying on methods from Math. This makes it easy to chain together several functions to retrieve a result, for example:
int myValueTooBig = 150;
int myValueTooSmall = 5;
// Ensure the value does not exceed 100, but is greater than 10.
Console.WriteLine($"{myValueTooBig.Min(100).Max(10)}, {myValueTooSmall.Min(100).Max(10)}");
// Outputs: 100, 10
Other mathematical functions are included, such as Sin(float), Cos(float), Tan(float), etc...
Fields
| Edit this page View SourcePI
Constant value for π.
Declaration
public const float PI = 3.141593
Field Value
Type | Description |
---|---|
float |
Methods
| Edit this page View SourceACos(decimal)
Function to return the inverse cosine value of a decimal value representing an angle, in radians.
Declaration
public static decimal ACos(this decimal cosine)
Parameters
Type | Name | Description |
---|---|---|
decimal | cosine | The cosine value. |
Returns
Type | Description |
---|---|
decimal | The inverse cosine value of the |
ACos(double)
Function to return the inverse cosine value of a double value representing an angle, in radians.
Declaration
public static double ACos(this double cosine)
Parameters
Type | Name | Description |
---|---|---|
double | cosine | The cosine value. |
Returns
Type | Description |
---|---|
double | The inverse cosine value of the |
ACos(float)
Function to return the inverse cosine value of a float value representing an angle, in radians.
Declaration
public static float ACos(this float cosine)
Parameters
Type | Name | Description |
---|---|---|
float | cosine | The cosine value. |
Returns
Type | Description |
---|---|
float | The inverse cosine value of the |
ASin(decimal)
Function to return the inverse sine value of a decimal value representing an angle, in radians.
Declaration
public static decimal ASin(this decimal sine)
Parameters
Type | Name | Description |
---|---|---|
decimal | sine | The sine value. |
Returns
Type | Description |
---|---|
decimal | The inverse sine value of the |
ASin(double)
Function to return the inverse sine value of a double value representing an angle, in radians.
Declaration
public static double ASin(this double sine)
Parameters
Type | Name | Description |
---|---|---|
double | sine | The sine value. |
Returns
Type | Description |
---|---|
double | The inverse sine value of the |
ASin(float)
Function to return the inverse sine value of a float value representing an angle, in radians.
Declaration
public static float ASin(this float sine)
Parameters
Type | Name | Description |
---|---|---|
float | sine | The sine value. |
Returns
Type | Description |
---|---|
float | The inverse sine value of the |
ATan(decimal)
Function to return the inverse tangent value of a decimal value representing an angle, in radians.
Declaration
public static decimal ATan(this decimal tangent)
Parameters
Type | Name | Description |
---|---|---|
decimal | tangent | The tangent value. |
Returns
Type | Description |
---|---|
decimal | The tangent sine value of the |
ATan(decimal, decimal)
Function to return the inverse tangent of two decimal values representing the horizontal and vertical offset of a slope.
Declaration
public static decimal ATan(this decimal y, decimal x)
Parameters
Type | Name | Description |
---|---|---|
decimal | y | Vertical slope value to retrieve the inverse tangent from. |
decimal | x | Horizontal slope value to retrieve the inverse tangent from. |
Returns
Type | Description |
---|---|
decimal | The inverse tangent of the slope. |
ATan(double)
Function to return the inverse tangent value of a double value representing an angle, in radians.
Declaration
public static double ATan(this double tangent)
Parameters
Type | Name | Description |
---|---|---|
double | tangent | The tangent value. |
Returns
Type | Description |
---|---|
double | The tangent sine value of the |
ATan(double, double)
Function to return the inverse tangent of two double values representing the horizontal and vertical offset of a slope.
Declaration
public static double ATan(this double y, double x)
Parameters
Type | Name | Description |
---|---|---|
double | y | Vertical slope value to retrieve the inverse tangent from. |
double | x | Horizontal slope value to retrieve the inverse tangent from. |
Returns
Type | Description |
---|---|
double | The inverse tangent of the slope. |
ATan(float)
Function to return the inverse tangent value of a float value representing an angle, in radians.
Declaration
public static float ATan(this float tangent)
Parameters
Type | Name | Description |
---|---|---|
float | tangent | The tangent value. |
Returns
Type | Description |
---|---|
float | The tangent sine value of the |
ATan(float, float)
Function to return the inverse tangent of two float values representing the horizontal and vertical offset of a slope.
Declaration
public static float ATan(this float y, float x)
Parameters
Type | Name | Description |
---|---|---|
float | y | Vertical slope value to retrieve the inverse tangent from. |
float | x | Horizontal slope value to retrieve the inverse tangent from. |
Returns
Type | Description |
---|---|
float | The inverse tangent of the slope. |
Abs(decimal)
Function to return the absolute value of a decimal value.
Declaration
public static decimal Abs(this decimal value)
Parameters
Type | Name | Description |
---|---|---|
decimal | value | Value to evaluate. |
Returns
Type | Description |
---|---|
decimal | The absolute value of |
Abs(double)
Function to return the absolute value of a double value.
Declaration
public static double Abs(this double value)
Parameters
Type | Name | Description |
---|---|---|
double | value | Value to evaluate. |
Returns
Type | Description |
---|---|
double | The absolute value of |
Abs(short)
Function to return the absolute value of a float value.
Declaration
public static short Abs(this short value)
Parameters
Type | Name | Description |
---|---|---|
short | value | Value to evaluate. |
Returns
Type | Description |
---|---|
short | The absolute value of |
Abs(int)
Function to return the absolute value of an int value.
Declaration
public static int Abs(this int value)
Parameters
Type | Name | Description |
---|---|---|
int | value | Value to evaluate. |
Returns
Type | Description |
---|---|
int | The absolute value of |
Abs(long)
Function to return the absolute value of a long value.
Declaration
public static long Abs(this long value)
Parameters
Type | Name | Description |
---|---|---|
long | value | Value to evaluate. |
Returns
Type | Description |
---|---|
long | The absolute value of |
Abs(float)
Function to return the absolute value of a float value.
Declaration
public static float Abs(this float value)
Parameters
Type | Name | Description |
---|---|---|
float | value | Value to evaluate. |
Returns
Type | Description |
---|---|
float | The absolute value of |
Clamp(byte, byte, byte)
Function to clamp a value to the range specified by the minimum and maximum value.
Declaration
public static byte Clamp(this byte value, byte minValue, byte maxValue)
Parameters
Type | Name | Description |
---|---|---|
byte | value | The value to clamp. |
byte | minValue | The minimum value. |
byte | maxValue | The maximum value. |
Returns
Type | Description |
---|---|
byte | The clamped value. |
Clamp(decimal, decimal, decimal)
Function to clamp a value to the range specified by the minimum and maximum value.
Declaration
public static decimal Clamp(this decimal value, decimal minValue, decimal maxValue)
Parameters
Type | Name | Description |
---|---|---|
decimal | value | The value to clamp. |
decimal | minValue | The minimum value. |
decimal | maxValue | The maximum value. |
Returns
Type | Description |
---|---|
decimal | The clamped value. |
Clamp(double, double, double)
Function to clamp a value to the range specified by the minimum and maximum value.
Declaration
public static double Clamp(this double value, double minValue, double maxValue)
Parameters
Type | Name | Description |
---|---|---|
double | value | The value to clamp. |
double | minValue | The minimum value. |
double | maxValue | The maximum value. |
Returns
Type | Description |
---|---|
double | The clamped value. |
Clamp(short, short, short)
Function to clamp a value to the range specified by the minimum and maximum value.
Declaration
public static short Clamp(this short value, short minValue, short maxValue)
Parameters
Type | Name | Description |
---|---|---|
short | value | The value to clamp. |
short | minValue | The minimum value. |
short | maxValue | The maximum value. |
Returns
Type | Description |
---|---|
short | The clamped value. |
Clamp(int, int, int)
Function to clamp a value to the range specified by the minimum and maximum value.
Declaration
public static int Clamp(this int value, int minValue, int maxValue)
Parameters
Type | Name | Description |
---|---|---|
int | value | The value to clamp. |
int | minValue | The minimum value. |
int | maxValue | The maximum value. |
Returns
Type | Description |
---|---|
int | The clamped value. |
Clamp(long, long, long)
Function to clamp a value to the range specified by the minimum and maximum value.
Declaration
public static long Clamp(this long value, long minValue, long maxValue)
Parameters
Type | Name | Description |
---|---|---|
long | value | The value to clamp. |
long | minValue | The minimum value. |
long | maxValue | The maximum value. |
Returns
Type | Description |
---|---|
long | The clamped value. |
Clamp(float, float, float)
Function to clamp a value to the range specified by the minimum and maximum value.
Declaration
public static float Clamp(this float value, float minValue, float maxValue)
Parameters
Type | Name | Description |
---|---|---|
float | value | The value to clamp. |
float | minValue | The minimum value. |
float | maxValue | The maximum value. |
Returns
Type | Description |
---|---|
float | The clamped value. |
Clamp(ushort, ushort, ushort)
Function to clamp a value to the range specified by the minimum and maximum value.
Declaration
public static ushort Clamp(this ushort value, ushort minValue, ushort maxValue)
Parameters
Type | Name | Description |
---|---|---|
ushort | value | The value to clamp. |
ushort | minValue | The minimum value. |
ushort | maxValue | The maximum value. |
Returns
Type | Description |
---|---|
ushort | The clamped value. |
Clamp(uint, uint, uint)
Function to clamp a value to the range specified by the minimum and maximum value.
Declaration
public static uint Clamp(this uint value, uint minValue, uint maxValue)
Parameters
Type | Name | Description |
---|---|---|
uint | value | The value to clamp. |
uint | minValue | The minimum value. |
uint | maxValue | The maximum value. |
Returns
Type | Description |
---|---|
uint | The clamped value. |
Clamp(ulong, ulong, ulong)
Function to clamp a value to the range specified by the minimum and maximum value.
Declaration
public static ulong Clamp(this ulong value, ulong minValue, ulong maxValue)
Parameters
Type | Name | Description |
---|---|---|
ulong | value | The value to clamp. |
ulong | minValue | The minimum value. |
ulong | maxValue | The maximum value. |
Returns
Type | Description |
---|---|
ulong | The clamped value. |
Cos(decimal)
Function to return the cosine value of a decimal value representing an angle, in radians.
Declaration
public static decimal Cos(this decimal angle)
Parameters
Type | Name | Description |
---|---|---|
decimal | angle | The angle, in radians. |
Returns
Type | Description |
---|---|
decimal | The cosine value of the |
Cos(double)
Function to return the cosine value of a double value representing an angle, in radians.
Declaration
public static double Cos(this double angle)
Parameters
Type | Name | Description |
---|---|---|
double | angle | The angle, in radians. |
Returns
Type | Description |
---|---|
double | The cosine value of the |
Cos(float)
Function to return the cosine value of a float value representing an angle, in radians.
Declaration
public static float Cos(this float angle)
Parameters
Type | Name | Description |
---|---|---|
float | angle | The angle, in radians. |
Returns
Type | Description |
---|---|
float | The cosine value of the |
EqualsEpsilon(double, double, double)
Function to determine if a double value is equal to another within a given tolerance.
Declaration
public static bool EqualsEpsilon(this double left, double right, double epsilon = 1E-12)
Parameters
Type | Name | Description |
---|---|---|
double | left | The left value to compare. |
double | right | The right value to compare. |
double | epsilon | [Optional] The epsilon representing the error tolerance. |
Returns
Type | Description |
---|---|
bool | true if equal, false if not. |
Remarks
Floating point values are prone to error buildup due to their limited precision. Therefore, when performing a comparison between two floating point values: 4.23212f == 4.23212f
may
actually be 4.232120000005422f == 4.232120000005433f
. Obviously, the result will not be true when the values are actually considered equal. This method ensures that the comparison will
return true by removing the error through the epsilon
parameter.
EqualsEpsilon(float, float, float)
Function to determine if a float value is equal to another within a given tolerance.
Declaration
public static bool EqualsEpsilon(this float left, float right, float epsilon = 1E-06)
Parameters
Type | Name | Description |
---|---|---|
float | left | The left value to compare. |
float | right | The right value to compare. |
float | epsilon | [Optional] The epsilon representing the error tolerance. |
Returns
Type | Description |
---|---|
bool | true if equal, false if not. |
Remarks
Floating point values are prone to error buildup due to their limited precision. Therefore, when performing a comparison between two floating point values: 4.23212f == 4.23212f
may
actually be 4.232120000005422f == 4.232120000005433f
. Obviously, the result will not be true when the values are actually considered equal. This method ensures that the comparison will
return true by removing the error through the epsilon
parameter.
Exp(decimal)
Function to return e raised to a decimal value as the power.
Declaration
public static decimal Exp(this decimal power)
Parameters
Type | Name | Description |
---|---|---|
decimal | power | The value representing a power to raise to. |
Returns
Type | Description |
---|---|
decimal |
e
raised to the power specified.
|
Remarks
e is a constant value of ~2.71828.
Exp(double)
Function to return e raised to a double value as the power.
Declaration
public static double Exp(this double power)
Parameters
Type | Name | Description |
---|---|---|
double | power | The value representing a power to raise to. |
Returns
Type | Description |
---|---|
double |
e
raised to the power specified.
|
Remarks
e is a constant value of ~2.71828.
Exp(float)
Function to return e raised to a float value as the power.
Declaration
public static float Exp(this float power)
Parameters
Type | Name | Description |
---|---|---|
float | power | The value representing a power to raise to. |
Returns
Type | Description |
---|---|
float |
e
raised to the power specified.
|
Remarks
e is a constant value of ~2.71828.
FastCeiling(double)
Function to return the largest integer greater than or equal to the specified double value.
Declaration
public static float FastCeiling(this double value)
Parameters
Type | Name | Description |
---|---|---|
double | value | The value to find the ceiling for. |
Returns
Type | Description |
---|---|
float | The largest integer greater than or equal to |
FastCeiling(float)
Function to return the largest integer greater than or equal to the specified float value.
Declaration
public static float FastCeiling(this float value)
Parameters
Type | Name | Description |
---|---|---|
float | value | The value to find the ceiling for. |
Returns
Type | Description |
---|---|
float | The largest integer greater than or equal to |
FastCos(float)
Function to perform an approximation of a cosine calculation.
Declaration
public static float FastCos(this float rads)
Parameters
Type | Name | Description |
---|---|---|
float | rads | The angle, in radians. |
Returns
Type | Description |
---|---|
float | The cosine value for the angle. |
Remarks
This method will produce an approximation of the value returned by Cos(float). Because this is an approximation, this method should not be used when accuracy is important.
This version of the cosine function has better performance than the Cos(float) method, and as such, should be used in performance intensive situations.
This code was adapted from the GameDev.Net post by L.Spiro found here: http://www.gamedev.net/topic/681723-faster-sin-and-cos/.
FastFloor(double)
Function to return the largest integer less than or equal to the specified float value.
Declaration
public static float FastFloor(this double value)
Parameters
Type | Name | Description |
---|---|---|
double | value | The value to find the floor for. |
Returns
Type | Description |
---|---|
float | The largest integer less than or equal to |
FastFloor(float)
Function to return the largest integer less than or equal to the specified float value.
Declaration
public static float FastFloor(this float value)
Parameters
Type | Name | Description |
---|---|---|
float | value | The value to find the floor for. |
Returns
Type | Description |
---|---|
float | The largest integer less than or equal to |
FastSin(float)
Function to perform an approximation of a sine calculation.
Declaration
public static float FastSin(this float rads)
Parameters
Type | Name | Description |
---|---|---|
float | rads | The angle, in radians. |
Returns
Type | Description |
---|---|
float | The sine value for the angle. |
Remarks
This method will produce an approximation of the value returned by Sin(float). Because this is an approximation, this method should not be used when accuracy is important.
This version of the sine function has better performance than the Sin(float) method, and as such, should be used in performance intensive situations.
This code was adapted from the GameDev.Net post by L.Spiro found here: http://www.gamedev.net/topic/681723-faster-sin-and-cos/.
InverseSqrt(double)
Function to return the inverse of the square root for a double value.
Declaration
public static double InverseSqrt(this double value)
Parameters
Type | Name | Description |
---|---|---|
double | value | The value to get the inverse square root of. |
Returns
Type | Description |
---|---|
double | The inverted square root of the value. |
InverseSqrt(float)
Function to return the inverse of the square root for a float value.
Declaration
public static float InverseSqrt(this float value)
Parameters
Type | Name | Description |
---|---|---|
float | value | The value to get the inverse square root of. |
Returns
Type | Description |
---|---|
float | The inverted square root of the value. |
Lerp(decimal, decimal, decimal)
Function to linearly interpolate between two values given a weight amount.
Declaration
public static decimal Lerp(this decimal from, decimal to, decimal amount)
Parameters
Type | Name | Description |
---|---|---|
decimal | from | The value to start from. |
decimal | to | The ending value. |
decimal | amount | The weighting amount. |
Returns
Type | Description |
---|---|
decimal | The linearly interpolated value. |
Lerp(double, double, double)
Function to linearly interpolate between two values given a weight amount.
Declaration
public static double Lerp(this double from, double to, double amount)
Parameters
Type | Name | Description |
---|---|---|
double | from | The value to start from. |
double | to | The ending value. |
double | amount | The weighting amount. |
Returns
Type | Description |
---|---|
double | The linearly interpolated value. |
Lerp(float, float, float)
Function to linearly interpolate between two values given a weight amount.
Declaration
public static float Lerp(this float from, float to, float amount)
Parameters
Type | Name | Description |
---|---|---|
float | from | The value to start from. |
float | to | The ending value. |
float | amount | The weighting amount. |
Returns
Type | Description |
---|---|
float | The linearly interpolated value. |
LimitAngle(decimal, decimal, decimal)
Function to limit an angle to the specified minimum and maximum.
Declaration
public static decimal LimitAngle(this decimal angle, decimal min = 0, decimal max = 360)
Parameters
Type | Name | Description |
---|---|---|
decimal | angle | The angle to limit. |
decimal | min | [Optional] The minimum value for the angle. |
decimal | max | [Optional] The maxmum value for the angle. |
Returns
Type | Description |
---|---|
decimal | The limited angle value. |
LimitAngle(double, double, double)
Function to limit an angle to the specified minimum and maximum.
Declaration
public static double LimitAngle(this double angle, double min = 0, double max = 360)
Parameters
Type | Name | Description |
---|---|---|
double | angle | The angle to limit. |
double | min | [Optional] The minimum value for the angle. |
double | max | [Optional] The maxmum value for the angle. |
Returns
Type | Description |
---|---|
double | The limited angle value. |
LimitAngle(short, short, short)
Function to limit an angle to the specified minimum and maximum.
Declaration
public static short LimitAngle(this short angle, short min = 0, short max = 360)
Parameters
Type | Name | Description |
---|---|---|
short | angle | The angle to limit. |
short | min | [Optional] The minimum value for the angle. |
short | max | [Optional] The maxmum value for the angle. |
Returns
Type | Description |
---|---|
short | The limited angle value. |
LimitAngle(int, int, int)
Function to limit an angle to the specified minimum and maximum.
Declaration
public static int LimitAngle(this int angle, int min = 0, int max = 360)
Parameters
Type | Name | Description |
---|---|---|
int | angle | The angle to limit. |
int | min | [Optional] The minimum value for the angle. |
int | max | [Optional] The maxmum value for the angle. |
Returns
Type | Description |
---|---|
int | The limited angle value. |
LimitAngle(long, long, long)
Function to limit an angle to the specified minimum and maximum.
Declaration
public static long LimitAngle(this long angle, long min = 0, long max = 360)
Parameters
Type | Name | Description |
---|---|---|
long | angle | The angle to limit. |
long | min | [Optional] The minimum value for the angle. |
long | max | [Optional] The maxmum value for the angle. |
Returns
Type | Description |
---|---|
long | The limited angle value. |
LimitAngle(float, float, float)
Function to limit an angle to the specified minimum and maximum.
Declaration
public static float LimitAngle(this float angle, float min = 0, float max = 360)
Parameters
Type | Name | Description |
---|---|---|
float | angle | The angle to limit. |
float | min | [Optional] The minimum value for the angle. |
float | max | [Optional] The maxmum value for the angle. |
Returns
Type | Description |
---|---|
float | The limited angle value. |
Log(decimal, decimal)
Function to compute the logarithim of a value.
Declaration
public static decimal Log(this decimal value, decimal power)
Parameters
Type | Name | Description |
---|---|---|
decimal | value | The value to compute the logarithim from. |
decimal | power | The new base for the logarithm. |
Returns
Type | Description |
---|---|
decimal | The logarithim value. |
Log(double, double)
Function to compute the logarithim of a value.
Declaration
public static double Log(this double value, double power)
Parameters
Type | Name | Description |
---|---|---|
double | value | The value to compute the logarithim from. |
double | power | The new base for the logarithm. |
Returns
Type | Description |
---|---|
double | The logarithim value. |
Log(float, float)
Function to compute the logarithim of a value.
Declaration
public static float Log(this float value, float power)
Parameters
Type | Name | Description |
---|---|---|
float | value | The value to compute the logarithim from. |
float | power | The new base for the logarithm. |
Returns
Type | Description |
---|---|
float | The logarithim value. |
Max(byte, byte)
Function to return the maximum value between two byte values.
Declaration
public static byte Max(this byte value1, byte value2)
Parameters
Type | Name | Description |
---|---|---|
byte | value1 | The first value to test. |
byte | value2 | The second value to test. |
Returns
Type | Description |
---|---|
byte | The larger of the two values. |
Max(decimal, decimal)
Function to return the maximum value between two decimal values.
Declaration
public static decimal Max(this decimal value1, decimal value2)
Parameters
Type | Name | Description |
---|---|---|
decimal | value1 | The first value to test. |
decimal | value2 | The second value to test. |
Returns
Type | Description |
---|---|
decimal | The larger of the two values. |
Max(double, double)
Function to return the maximum value between two double values.
Declaration
public static double Max(this double value1, double value2)
Parameters
Type | Name | Description |
---|---|---|
double | value1 | The first value to test. |
double | value2 | The second value to test. |
Returns
Type | Description |
---|---|
double | The larger of the two values. |
Max(short, short)
Function to return the maximum value between two short values.
Declaration
public static short Max(this short value1, short value2)
Parameters
Type | Name | Description |
---|---|---|
short | value1 | The first value to test. |
short | value2 | The second value to test. |
Returns
Type | Description |
---|---|
short | The larger of the two values. |
Max(int, int)
Function to return the maximum value between two int values.
Declaration
public static int Max(this int value1, int value2)
Parameters
Type | Name | Description |
---|---|---|
int | value1 | The first value to test. |
int | value2 | The second value to test. |
Returns
Type | Description |
---|---|
int | The larger of the two values. |
Max(long, long)
Function to return the maximum value between two long values.
Declaration
public static long Max(this long value1, long value2)
Parameters
Type | Name | Description |
---|---|---|
long | value1 | The first value to test. |
long | value2 | The second value to test. |
Returns
Type | Description |
---|---|
long | The larger of the two values. |
Max(float, float)
Function to return the maximum value between two float values.
Declaration
public static float Max(this float value1, float value2)
Parameters
Type | Name | Description |
---|---|---|
float | value1 | The first value to test. |
float | value2 | The second value to test. |
Returns
Type | Description |
---|---|
float | The larger of the two values. |
Max(ushort, ushort)
Function to return the maximum value between two ushort values.
Declaration
public static ushort Max(this ushort value1, ushort value2)
Parameters
Type | Name | Description |
---|---|---|
ushort | value1 | The first value to test. |
ushort | value2 | The second value to test. |
Returns
Type | Description |
---|---|
ushort | The larger of the two values. |
Max(uint, uint)
Function to return the maximum value between two uint values.
Declaration
public static uint Max(this uint value1, uint value2)
Parameters
Type | Name | Description |
---|---|---|
uint | value1 | The first value to test. |
uint | value2 | The second value to test. |
Returns
Type | Description |
---|---|
uint | The larger of the two values. |
Max(ulong, ulong)
Function to return the maximum value between two ulong values.
Declaration
public static ulong Max(this ulong value1, ulong value2)
Parameters
Type | Name | Description |
---|---|---|
ulong | value1 | The first value to test. |
ulong | value2 | The second value to test. |
Returns
Type | Description |
---|---|
ulong | The larger of the two values. |
Min(byte, byte)
Function to return the minimum value between two byte values.
Declaration
public static byte Min(this byte value1, byte value2)
Parameters
Type | Name | Description |
---|---|---|
byte | value1 | The first value to test. |
byte | value2 | The second value to test. |
Returns
Type | Description |
---|---|
byte | The smaller of the two values. |
Min(decimal, decimal)
Function to return the minimum value between two decimal values.
Declaration
public static decimal Min(this decimal value1, decimal value2)
Parameters
Type | Name | Description |
---|---|---|
decimal | value1 | The first value to test. |
decimal | value2 | The second value to test. |
Returns
Type | Description |
---|---|
decimal | The smaller of the two values. |
Min(double, double)
Function to return the minimum value between two double values.
Declaration
public static double Min(this double value1, double value2)
Parameters
Type | Name | Description |
---|---|---|
double | value1 | The first value to test. |
double | value2 | The second value to test. |
Returns
Type | Description |
---|---|
double | The smaller of the two values. |
Min(short, short)
Function to return the minimum value between two short values.
Declaration
public static short Min(this short value1, short value2)
Parameters
Type | Name | Description |
---|---|---|
short | value1 | The first value to test. |
short | value2 | The second value to test. |
Returns
Type | Description |
---|---|
short | The smaller of the two values. |
Min(int, int)
Function to return the minimum value between two int values.
Declaration
public static int Min(this int value1, int value2)
Parameters
Type | Name | Description |
---|---|---|
int | value1 | The first value to test. |
int | value2 | The second value to test. |
Returns
Type | Description |
---|---|
int | The smaller of the two values. |
Min(long, long)
Function to return the minimum value between two long values..
Declaration
public static long Min(this long value1, long value2)
Parameters
Type | Name | Description |
---|---|---|
long | value1 | The first value to test. |
long | value2 | The second value to test. |
Returns
Type | Description |
---|---|
long | The smaller of the two values. |
Min(float, float)
Function to return the minimum value between two float values.
Declaration
public static float Min(this float value1, float value2)
Parameters
Type | Name | Description |
---|---|---|
float | value1 | The first value to test. |
float | value2 | The second value to test. |
Returns
Type | Description |
---|---|
float | The smaller of the two values. |
Min(ushort, ushort)
Function to return the minimum value between two ushort values.
Declaration
public static ushort Min(this ushort value1, ushort value2)
Parameters
Type | Name | Description |
---|---|---|
ushort | value1 | The first value to test. |
ushort | value2 | The second value to test. |
Returns
Type | Description |
---|---|
ushort | The smaller of the two values. |
Min(uint, uint)
Function to return the minimum value between two uint values.
Declaration
public static uint Min(this uint value1, uint value2)
Parameters
Type | Name | Description |
---|---|---|
uint | value1 | The first value to test. |
uint | value2 | The second value to test. |
Returns
Type | Description |
---|---|
uint | The smaller of the two values. |
Min(ulong, ulong)
Function to return the minimum value between two ulong values.
Declaration
public static ulong Min(this ulong value1, ulong value2)
Parameters
Type | Name | Description |
---|---|---|
ulong | value1 | The first value to test. |
ulong | value2 | The second value to test. |
Returns
Type | Description |
---|---|
ulong | The smaller of the two values. |
Pow(decimal, decimal)
Function to raise a decimal to a specified power.
Declaration
public static decimal Pow(this decimal value, decimal power)
Parameters
Type | Name | Description |
---|---|---|
decimal | value | The value to raise. |
decimal | power | The value representing a power to raise to. |
Returns
Type | Description |
---|---|
decimal | The |
Pow(double, double)
Function to raise a double to a specified power.
Declaration
public static double Pow(this double value, double power)
Parameters
Type | Name | Description |
---|---|---|
double | value | The value to raise. |
double | power | The value representing a power to raise to. |
Returns
Type | Description |
---|---|
double | The |
Pow(float, float)
Function to raise a float to a specified power.
Declaration
public static float Pow(this float value, float power)
Parameters
Type | Name | Description |
---|---|---|
float | value | The value to raise. |
float | power | The value representing a power to raise to. |
Returns
Type | Description |
---|---|
float | The |
Round(decimal, int, MidpointRounding)
Function to round a decimal value to the nearest whole or fractional number.
Declaration
public static decimal Round(this decimal value, int decimalCount = 0, MidpointRounding rounding = MidpointRounding.ToEven)
Parameters
Type | Name | Description |
---|---|---|
decimal | value | The value to round. |
int | decimalCount | [Optional] The number of decimal places to round to. |
MidpointRounding | rounding | [Optional] The type of rounding to perform. |
Returns
Type | Description |
---|---|
decimal | The float value rounded to the nearest whole number. |
Remarks
See Round(decimal, int, MidpointRounding) for more information.
Round(double, int, MidpointRounding)
Function to round a double value to the nearest whole or fractional number.
Declaration
public static double Round(this double value, int decimalCount = 0, MidpointRounding rounding = MidpointRounding.ToEven)
Parameters
Type | Name | Description |
---|---|---|
double | value | The value to round. |
int | decimalCount | [Optional] The number of decimal places to round to. |
MidpointRounding | rounding | [Optional] The type of rounding to perform. |
Returns
Type | Description |
---|---|
double | The float value rounded to the nearest whole number. |
Remarks
See Round(double, int, MidpointRounding) for more information.
Round(float, int, MidpointRounding)
Function to round a float value to the nearest whole or fractional number.
Declaration
public static float Round(this float value, int decimalCount = 0, MidpointRounding rounding = MidpointRounding.ToEven)
Parameters
Type | Name | Description |
---|---|---|
float | value | The value to round. |
int | decimalCount | [Optional] The number of decimal places to round to. |
MidpointRounding | rounding | [Optional] The type of rounding to perform. |
Returns
Type | Description |
---|---|
float | The float value rounded to the nearest whole number. |
Remarks
See Round(double, int, MidpointRounding) for more information.
Sign(decimal)
Function to return the sign of a decimal value.
Declaration
public static int Sign(this decimal value)
Parameters
Type | Name | Description |
---|---|---|
decimal | value | The value to evaluate. |
Returns
Type | Description |
---|---|
int | 0 if the value is 0, -1 if the value is less than 0, and 1 if the value is greater than 0. |
Sign(double)
Function to return the sign of a double value.
Declaration
public static int Sign(this double value)
Parameters
Type | Name | Description |
---|---|---|
double | value | The value to evaluate. |
Returns
Type | Description |
---|---|
int | 0 if the value is 0, -1 if the value is less than 0, and 1 if the value is greater than 0. |
Sign(short)
Function to return the sign of a short value.
Declaration
public static int Sign(this short value)
Parameters
Type | Name | Description |
---|---|---|
short | value | The value to evaluate. |
Returns
Type | Description |
---|---|
int | 0 if the value is 0, -1 if the value is less than 0, and 1 if the value is greater than 0. |
Sign(int)
Function to return the sign of an int value.
Declaration
public static int Sign(this int value)
Parameters
Type | Name | Description |
---|---|---|
int | value | The value to evaluate. |
Returns
Type | Description |
---|---|
int | 0 if the value is 0, -1 if the value is less than 0, and 1 if the value is greater than 0. |
Sign(long)
Function to return the sign of a long value.
Declaration
public static int Sign(this long value)
Parameters
Type | Name | Description |
---|---|---|
long | value | The value to evaluate. |
Returns
Type | Description |
---|---|
int | 0 if the value is 0, -1 if the value is less than 0, and 1 if the value is greater than 0. |
Sign(sbyte)
Function to return the sign of a sbyte value.
Declaration
public static int Sign(this sbyte value)
Parameters
Type | Name | Description |
---|---|---|
sbyte | value | The value to evaluate. |
Returns
Type | Description |
---|---|
int | 0 if the value is 0, -1 if the value is less than 0, and 1 if the value is greater than 0. |
Sign(float)
Function to return the sign of a float value.
Declaration
public static int Sign(this float value)
Parameters
Type | Name | Description |
---|---|---|
float | value | The value to evaluate. |
Returns
Type | Description |
---|---|
int | 0 if the value is 0, -1 if the value is less than 0, and 1 if the value is greater than 0. |
Sin(decimal)
Function to return the sine value of a decimal value representing an angle, in radians.
Declaration
public static decimal Sin(this decimal angle)
Parameters
Type | Name | Description |
---|---|---|
decimal | angle | The angle, in radians. |
Returns
Type | Description |
---|---|
decimal | The sine value of the |
Sin(double)
Function to return the sine value of a double value representing an angle, in radians.
Declaration
public static double Sin(this double angle)
Parameters
Type | Name | Description |
---|---|---|
double | angle | The angle, in radians. |
Returns
Type | Description |
---|---|
double | The sine value of the |
Sin(float)
Function to return the sine value of a float value representing an angle, in radians.
Declaration
public static float Sin(this float angle)
Parameters
Type | Name | Description |
---|---|---|
float | angle | The angle, in radians. |
Returns
Type | Description |
---|---|
float | The sine value of the |
Sqrt(double)
Function to return the square root for a double value.
Declaration
public static double Sqrt(this double value)
Parameters
Type | Name | Description |
---|---|---|
double | value | The value to get the square root of. |
Returns
Type | Description |
---|---|
double | The square root of the value. |
Sqrt(float)
Function to return the square root for a float value.
Declaration
public static float Sqrt(this float value)
Parameters
Type | Name | Description |
---|---|---|
float | value | The value to get the square root of. |
Returns
Type | Description |
---|---|
float | The square root of the value. |
Tan(decimal)
Function to return the tangent value of a decimal value representing an angle, in radians.
Declaration
public static decimal Tan(this decimal angle)
Parameters
Type | Name | Description |
---|---|---|
decimal | angle | The angle, in radians. |
Returns
Type | Description |
---|---|
decimal | The tangent value of the |
Tan(double)
Function to return the tangent value of a double value representing an angle, in radians.
Declaration
public static double Tan(this double angle)
Parameters
Type | Name | Description |
---|---|---|
double | angle | The angle, in radians. |
Returns
Type | Description |
---|---|
double | The tangent value of the |
Tan(float)
Function to return the tangent value of a float value representing an angle, in radians.
Declaration
public static float Tan(this float angle)
Parameters
Type | Name | Description |
---|---|---|
float | angle | The angle, in radians. |
Returns
Type | Description |
---|---|
float | The tangent value of the |
ToDegrees(decimal)
Function to convert a decimal value representing a radian into an angle in degrees.
Declaration
public static decimal ToDegrees(this decimal radians)
Parameters
Type | Name | Description |
---|---|---|
decimal | radians | The value to convert. |
Returns
Type | Description |
---|---|
decimal | The angle in degrees. |
ToDegrees(double)
Function to convert a double value representing a radian into an angle in degrees.
Declaration
public static double ToDegrees(this double radians)
Parameters
Type | Name | Description |
---|---|---|
double | radians | The value to convert. |
Returns
Type | Description |
---|---|
double | The angle in degrees. |
ToDegrees(float)
Function to convert a float value representing a radian into an angle in degrees.
Declaration
public static float ToDegrees(this float radians)
Parameters
Type | Name | Description |
---|---|---|
float | radians | The value to convert. |
Returns
Type | Description |
---|---|
float | The angle in degrees. |
ToRadians(decimal)
Function to convert a decimal value representing an angle in degrees into a radian value.
Declaration
public static decimal ToRadians(this decimal degrees)
Parameters
Type | Name | Description |
---|---|---|
decimal | degrees | The angle value to convert. |
Returns
Type | Description |
---|---|
decimal | The angle in radians. |
ToRadians(double)
Function to convert a double value representing an angle in degrees into a radian value.
Declaration
public static double ToRadians(this double degrees)
Parameters
Type | Name | Description |
---|---|---|
double | degrees | The angle value to convert. |
Returns
Type | Description |
---|---|
double | The angle in radians. |
ToRadians(float)
Function to convert a float value representing an angle in degrees into a radian value.
Declaration
public static float ToRadians(this float degrees)
Parameters
Type | Name | Description |
---|---|---|
float | degrees | The angle value to convert. |
Returns
Type | Description |
---|---|
float | The angle in radians. |