Gorgon
Show / Hide Table of Contents

Class GorgonMathExtensions

Fluent extensions for mathematical operations on various numeric types.

Inheritance
object
GorgonMathExtensions
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
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 Source

PI

Constant value for π.

Declaration
public const float PI = 3.141593
Field Value
Type Description
float

Methods

| Edit this page View Source

ACos(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 cosine.

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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.

| Edit this page View Source

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

| Edit this page View Source

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.

| Edit this page View Source

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

| Edit this page View Source

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.

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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 value raised to the specified power.

| Edit this page View Source

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 value raised to the specified power.

| Edit this page View Source

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 value raised to the specified power.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author