MathHelper Class
Provides math routines not found in Math class as well as additional helper methods.
public static class MathHelper
- Inheritance:
- object object
Methods
Max(params double[])
Returns the largest value from the specified numbers.
public static double Max(params double[] values)
| Parameter | Type | Description |
|---|---|---|
| values | double[] | The values to compare. |
Returns
Max(params int[])
Returns the largest value from the specified numbers.
public static int Max(params int[] values)
| Parameter | Type | Description |
|---|---|---|
| values | int[] | The values to compare. |
Returns
Min(params double[])
Returns the smallest value from the specified numbers.
public static double Min(params double[] values)
| Parameter | Type | Description |
|---|---|---|
| values | double[] | The values to compare. |
Returns
Min(params int[])
Returns the smallest value from the specified numbers.
public static int Min(params int[] values)
| Parameter | Type | Description |
|---|---|---|
| values | int[] | The values to compare. |
Returns
Range(decimal, decimal, decimal)
Returns the specified value constrained to the specified minimum and maximum values.
public static decimal Range(decimal value, decimal minValue, decimal maxValue)
| Parameter | Type | Description |
|---|---|---|
| value | decimal | The value. |
| minValue | decimal | The minimum value. |
| maxValue | decimal | The maximum value. |
Returns
Remarks
This method always returns a value between minValue and maxValue,
even if minValue is greater than maxValue.
Range(double, double, double)
Returns the specified value constrained to the specified minimum and maximum values.
public static double Range(double value, double minValue, double maxValue)
| Parameter | Type | Description |
|---|---|---|
| value | double | The value. |
| minValue | double | The minimum value. |
| maxValue | double | The maximum value. |
Returns
Remarks
This method always returns a value between minValue and maxValue,
even if minValue is greater than maxValue.
Use ClampToRange(double, double, double) if an exception should be
thrown when minValue is greater than maxValue.
Range(int, int, int)
Returns the specified value constrained to the specified minimum and maximum values.
public static int Range(int value, int minValue, int maxValue)
| Parameter | Type | Description |
|---|---|---|
| value | int | The value. |
| minValue | int | The minimum value. |
| maxValue | int | The maximum value. |
Returns
Remarks
This method always returns a value between minValue and maxValue,
even if minValue is greater than maxValue.
Use ClampToRange(int, int, int) if an exception should be
thrown when minValue is greater than maxValue.
Round(RoundMode, double)
Returns a rounded number using the specified RoundMode.
public static double Round(RoundMode mode, double value)
| Parameter | Type | Description |
|---|---|---|
| mode | RoundMode | The RoundMode to use. |
| value | double | The value to round. |