DoubleExtensions Class
Provides extension methods for the double type.
public static class DoubleExtensions
- Inheritance:
- object object
Methods
ClampToNonnegative(double)
Clamps a value to nonnegative number between 0.0..MaxValue.
public static double ClampToNonnegative(this double value)
| Parameter | Type | Description |
|---|---|---|
| value | double | The value to examine. |
Returns
- double:
The clamped value.
ClampToPercentage(double)
Clamps a value to a percentage between 0.0..1.0.
public static double ClampToPercentage(this double value)
| Parameter | Type | Description |
|---|---|---|
| value | double | The value to examine. |
Returns
- double:
The clamped value.
ClampToRange(double, double, double)
Clamps a value between the specified minimum and maximum.
public static double ClampToRange(this double value, double minimum, double maximum)
| Parameter | Type | Description |
|---|---|---|
| value | double | The value to examine. |
| minimum | double | The minimum value. |
| maximum | double | The maximum value. |
Returns
- double:
The clamped value.
IsBetween(double, double, double, bool)
Returns whether a value is between the specified minimum and maximum.
public static bool IsBetween(this double value, double minimum, double maximum, bool isInclusive = true)
| Parameter | Type | Description |
|---|---|---|
| value | double | The value to examine. |
| minimum | double | The number that the value must be greater than, or equal to if inclusive. |
| maximum | double | The number that the value must be less than, or equal to if inclusive. |
| isInclusive | bool | Whether the check considers |
Returns
- bool:
trueif the value is between the specified minimum and maximum; otherwise,false.
IsCloseTo(double, double)
Returns whether a value is close enough with another value to be considered equal.
public static bool IsCloseTo(this double value, double comparison)
| Parameter | Type | Description |
|---|---|---|
| value | double | The base value. |
| comparison | double | The value to be compared. |
Returns
- bool:
trueif the two values are close enough to be considered equal; otherwise,false.
IsGreaterThan(double, double)
Determines whether the value is effectively greater than the comparison value.
public static bool IsGreaterThan(this double value, double comparison)
| Parameter | Type | Description |
|---|---|---|
| value | double | The base value. |
| comparison | double | The value to be compared. |
Returns
- bool:
trueif the value is effectively greater than the comparison value; otherwise,false.
IsGreaterThanOrCloseTo(double, double)
Determines whether the value is effectively greater than or equal to the comparison value.
public static bool IsGreaterThanOrCloseTo(this double value, double comparison)
| Parameter | Type | Description |
|---|---|---|
| value | double | The base value. |
| comparison | double | The value to be compared. |
Returns
- bool:
trueif the value is effectively greater than or equal to the comparison value; otherwise,false.
IsLessThan(double, double)
Determines whether the value is effectively less than the comparison value.
public static bool IsLessThan(this double value, double comparison)
| Parameter | Type | Description |
|---|---|---|
| value | double | The base value. |
| comparison | double | The value to be compared. |
Returns
- bool:
trueif the value is effectively less than the comparison value; otherwise,false.
IsLessThanOrCloseTo(double, double)
Determines whether the value is effectively less than or equal to the comparison value.
public static bool IsLessThanOrCloseTo(this double value, double comparison)
| Parameter | Type | Description |
|---|---|---|
| value | double | The base value. |
| comparison | double | The value to be compared. |
Returns
- bool:
trueif the value is effectively less than or equal to the comparison value; otherwise,false.
IsNonnegative(double)
Returns whether a value is inclusively between 0.0..MaxValue.
public static bool IsNonnegative(this double value)
| Parameter | Type | Description |
|---|---|---|
| value | double | The value to examine. |
Returns
IsPercentage(double)
Returns whether a value is a percentage inclusively between 0.0..1.0.
public static bool IsPercentage(this double value)
| Parameter | Type | Description |
|---|---|---|
| value | double | The value to examine. |
Returns
- bool:
trueif the value is a percentage inclusively between0.0..1.0; otherwise,false.
IsZero(double)
Determines whether the specified value is close enough to zero to be considered equal.
public static bool IsZero(this double value)
| Parameter | Type | Description |
|---|---|---|
| value | double | The value to compare with zero. |
Returns
- bool:
trueif the specified value is close enough to zero to be considered equal; otherwise,false.
NormalizeDegreeAngle(double)
Normalizes a degree angle to a value between 0.0..360.0.
public static double NormalizeDegreeAngle(this double degreeAngle)
| Parameter | Type | Description |
|---|---|---|
| degreeAngle | double | The value to normalize. |
Returns
- double:
The normalized value.
Remarks
Values higher than 360.0 will wrap back to zero (e.g. 540.0 becomes 180.0).
A negative degree angle will be translated to its positive equivalent (e.g. -90.0 becomes 270.0).
Round(double, RoundMode)
Returns a number rounded to zero digits using the specified RoundMode.
public static double Round(this double value, RoundMode mode = RoundMode.Nearest)
| Parameter | Type | Description |
|---|---|---|
| value | double | The value to round. |
| mode | RoundMode |
Returns
Round(double, int, RoundMode)
Returns a number rounded to the specified number of digits using the specified RoundMode.
public static double Round(this double value, int digits, RoundMode mode = RoundMode.Nearest)
| Parameter | Type | Description |
|---|---|---|
| value | double | The value to round. |
| digits | int | The number of digits in the result. |
| mode | RoundMode |
Returns
RoundToMultiple(double, double)
Returns a number rounded to the nearest multiple of another number.
public static double RoundToMultiple(this double value, double multipleOf)
| Parameter | Type | Description |
|---|---|---|
| value | double | The value to round. |
| multipleOf | double | The number that defines the multiple. |