Class XInteger
- Namespace
- Prefrontal.Common.Extensions
- Assembly
- Prefrontal.Core.dll
Provides extension methods for integer types.
public static class XInteger
- Inheritance
-
XInteger
- Inherited Members
Methods
Abs(int)
Returns the absolute value of a 32-bit signed integer.
public static int Abs(this int value)
Parameters
value
intA number that is greater than Int32.MinValue, but less than or equal to Int32.MaxValue.
Returns
- int
A 32-bit signed integer, x, such that 0 ≤ x ≤ Int32.MaxValue.
Exceptions
- OverflowException
value
equals Int32.MinValue.
Clamp<T>(T, T, T)
Clamps the value between min
and max
(inclusive).
public static T Clamp<T>(this T value, T min, T max) where T : IBinaryInteger<T>
Parameters
value
TThe value to clamp.
min
TThe minimum value.
max
TThe maximum value.
Returns
- T
The clamped value.
Type Parameters
T
The type of the value.
OrAtLeast(int, int)
Returns value
if it is greater than lowerLimit
,
otherwise returns lowerLimit
.
This is a shorthand for Math.Max(value, lowerLimit)
.
public static int OrAtLeast(this int value, int lowerLimit)
Parameters
Returns
- int
The value or the lower limit.
Remarks
In case of floating-point values, if either parameter is NaN,
the result will be lowerLimit
.
OrAtLeast0(int)
Returns value if it is less than 0, otherwise returns 0.
This is a highly optimized alternative to Math.Max(value, 0)
public static int OrAtLeast0(this int value)
Parameters
value
int
Returns
OrAtLeast1(int)
Returns value if it is greater than 1, otherwise returns 1.
This is a highly optimized alternative to Math.Max(value, 1)
public static int OrAtLeast1(this int value)
Parameters
value
int
Returns
OrAtMost(int, int)
Returns value
if it is less than upperLimit
,
otherwise returns upperLimit
.
This is a shorthand for Math.Min(value, upperLimit)
.
public static int OrAtMost(this int value, int upperLimit)
Parameters
Returns
- int
The value or the upper limit.
Remarks
In case of floating-point values, if either parameter is NaN,
the result will be upperLimit
.
OrAtMost0(int)
Returns value if it is less than 0, otherwise returns 0.
This is a highly optimized alternative to Math.Min(value, 0)
public static int OrAtMost0(this int value)
Parameters
value
int