Class NumberExtensions
Provides extension methods for numeric types that expose the static methods of NumberUtil
in a fluent, instance-method style. This allows chained usage on literals and local variables without
requiring the full NumberUtil.Method(value, ...) call syntax.
Inherited Members
Namespace: Scylla.Core.Util
Assembly: ScyllaCore.dll
Syntax
public static class NumberExtensions
Remarks
All methods delegate directly to their counterpart in NumberUtil and carry identical semantics. Consult the documentation on each NumberUtil method for full details, including edge cases and special floating-point handling.
Covered categories:
- Clamp / Range:
Clamp,Clamp01,IsBetween - Float hygiene:
Approximately,IsNearlyZero - Rounding / Snapping:
RoundToDecimals,Snap - Modulo / Wrap:
Mod,Repeat,Wrap
Methods
Approximately(double, double, double)
Returns true if the absolute difference between this float and
other is less than or equal to epsilon. Use this instead
of the == operator when comparing floats that may accumulate rounding error.
The default epsilon is EPSILON (1e-6).
Declaration
public static bool Approximately(this double value, double other, double epsilon = 1E-12)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | |
| double | other | |
| double | epsilon | The maximum difference allowed for the two numbers to be considered equal. Defaults to EPSILON. |
Returns
| Type | Description |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
Approximately(float, float, float)
Returns true if the absolute difference between this float and
other is less than or equal to epsilon. Use this instead
of the == operator when comparing floats that may accumulate rounding error.
The default epsilon is EPSILON (1e-6).
Declaration
public static bool Approximately(this float value, float other, float epsilon = 1E-06)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | |
| float | other | |
| float | epsilon | The maximum difference allowed for the two numbers to be considered equal. Defaults to EPSILON. |
Returns
| Type | Description |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
Clamp(decimal, decimal, decimal)
Clamps this int value to the inclusive range
[min, max]. When min is greater than
max, the behavior is undefined and may return an out-of-range value.
Declaration
public static decimal Clamp(this decimal value, decimal min, decimal max)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | value | The value to clamp. |
| decimal | min | The inclusive lower bound of the range. |
| decimal | max | The inclusive upper bound of the range. |
Returns
| Type | Description |
|---|---|
| decimal | The clamped value in the range [ |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when |
Clamp(double, double, double)
Clamps this int value to the inclusive range
[min, max]. When min is greater than
max, the behavior is undefined and may return an out-of-range value.
Declaration
public static double Clamp(this double value, double min, double max)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to clamp. |
| double | min | The inclusive lower bound of the range. |
| double | max | The inclusive upper bound of the range. |
Returns
| Type | Description |
|---|---|
| double | The clamped value in the range [ |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when |
Clamp(int, int, int)
Clamps this int value to the inclusive range
[min, max]. When min is greater than
max, the behavior is undefined and may return an out-of-range value.
Declaration
public static int Clamp(this int value, int min, int max)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value to clamp. |
| int | min | The inclusive lower bound of the range. |
| int | max | The inclusive upper bound of the range. |
Returns
| Type | Description |
|---|---|
| int | The clamped value in the range [ |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when |
Clamp(long, long, long)
Clamps this int value to the inclusive range
[min, max]. When min is greater than
max, the behavior is undefined and may return an out-of-range value.
Declaration
public static long Clamp(this long value, long min, long max)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The value to clamp. |
| long | min | The inclusive lower bound of the range. |
| long | max | The inclusive upper bound of the range. |
Returns
| Type | Description |
|---|---|
| long | The clamped value in the range [ |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when |
Clamp(float, float, float)
Clamps this int value to the inclusive range
[min, max]. When min is greater than
max, the behavior is undefined and may return an out-of-range value.
Declaration
public static float Clamp(this float value, float min, float max)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The value to clamp. |
| float | min | The inclusive lower bound of the range. |
| float | max | The inclusive upper bound of the range. |
Returns
| Type | Description |
|---|---|
| float | The clamped value in the range [ |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when |
Clamp(uint, uint, uint)
Clamps this int value to the inclusive range
[min, max]. When min is greater than
max, the behavior is undefined and may return an out-of-range value.
Declaration
public static uint Clamp(this uint value, uint min, uint max)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | The value to clamp. |
| uint | min | The inclusive lower bound of the range. |
| uint | max | The inclusive upper bound of the range. |
Returns
| Type | Description |
|---|---|
| uint | The clamped value in the range [ |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when |
Clamp(ulong, ulong, ulong)
Clamps this int value to the inclusive range
[min, max]. When min is greater than
max, the behavior is undefined and may return an out-of-range value.
Declaration
public static ulong Clamp(this ulong value, ulong min, ulong max)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | value | The value to clamp. |
| ulong | min | The inclusive lower bound of the range. |
| ulong | max | The inclusive upper bound of the range. |
Returns
| Type | Description |
|---|---|
| ulong | The clamped value in the range [ |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when |
Clamp01(double)
Clamps this float value to the normalized range [0, 1]. Values below 0 are returned as 0; values above 1 are returned as 1.
Declaration
public static double Clamp01(this double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to clamp. |
Returns
| Type | Description |
|---|---|
| double | The clamped value, which will be within the range [0, 1]. |
Clamp01(float)
Clamps this float value to the normalized range [0, 1]. Values below 0 are returned as 0; values above 1 are returned as 1.
Declaration
public static float Clamp01(this float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The value to clamp. |
Returns
| Type | Description |
|---|---|
| float | The clamped value, which will be within the range [0, 1]. |
IsBetween(decimal, decimal, decimal, bool)
Returns true if this int value falls within the range defined by
min and max. When inclusive is
true (default), both endpoints are considered part of the range ([min,
max]). When false, endpoints are excluded ((min,
max)).
Declaration
public static bool IsBetween(this decimal value, decimal min, decimal max, bool inclusive = true)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | value | The value to evaluate. |
| decimal | min | The lower boundary of the range. |
| decimal | max | The upper boundary of the range. |
| bool | inclusive | Specifies whether the boundaries are inclusive. If true, the range is inclusive of the boundaries; otherwise, the range is exclusive. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is within the specified range, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the min value is greater than the max value. |
IsBetween(double, double, double, bool)
Returns true if this int value falls within the range defined by
min and max. When inclusive is
true (default), both endpoints are considered part of the range ([min,
max]). When false, endpoints are excluded ((min,
max)).
Declaration
public static bool IsBetween(this double value, double min, double max, bool inclusive = true)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to evaluate. |
| double | min | The lower boundary of the range. |
| double | max | The upper boundary of the range. |
| bool | inclusive | Specifies whether the boundaries are inclusive. If true, the range is inclusive of the boundaries; otherwise, the range is exclusive. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is within the specified range, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the min value is greater than the max value. |
IsBetween(int, int, int, bool)
Returns true if this int value falls within the range defined by
min and max. When inclusive is
true (default), both endpoints are considered part of the range ([min,
max]). When false, endpoints are excluded ((min,
max)).
Declaration
public static bool IsBetween(this int value, int min, int max, bool inclusive = true)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value to evaluate. |
| int | min | The lower boundary of the range. |
| int | max | The upper boundary of the range. |
| bool | inclusive | Specifies whether the boundaries are inclusive. If true, the range is inclusive of the boundaries; otherwise, the range is exclusive. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is within the specified range, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the min value is greater than the max value. |
IsBetween(long, long, long, bool)
Returns true if this int value falls within the range defined by
min and max. When inclusive is
true (default), both endpoints are considered part of the range ([min,
max]). When false, endpoints are excluded ((min,
max)).
Declaration
public static bool IsBetween(this long value, long min, long max, bool inclusive = true)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The value to evaluate. |
| long | min | The lower boundary of the range. |
| long | max | The upper boundary of the range. |
| bool | inclusive | Specifies whether the boundaries are inclusive. If true, the range is inclusive of the boundaries; otherwise, the range is exclusive. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is within the specified range, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the min value is greater than the max value. |
IsBetween(float, float, float, bool)
Returns true if this int value falls within the range defined by
min and max. When inclusive is
true (default), both endpoints are considered part of the range ([min,
max]). When false, endpoints are excluded ((min,
max)).
Declaration
public static bool IsBetween(this float value, float min, float max, bool inclusive = true)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The value to evaluate. |
| float | min | The lower boundary of the range. |
| float | max | The upper boundary of the range. |
| bool | inclusive | Specifies whether the boundaries are inclusive. If true, the range is inclusive of the boundaries; otherwise, the range is exclusive. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is within the specified range, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the min value is greater than the max value. |
IsBetween(uint, uint, uint, bool)
Returns true if this int value falls within the range defined by
min and max. When inclusive is
true (default), both endpoints are considered part of the range ([min,
max]). When false, endpoints are excluded ((min,
max)).
Declaration
public static bool IsBetween(this uint value, uint min, uint max, bool inclusive = true)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | The value to evaluate. |
| uint | min | The lower boundary of the range. |
| uint | max | The upper boundary of the range. |
| bool | inclusive | Specifies whether the boundaries are inclusive. If true, the range is inclusive of the boundaries; otherwise, the range is exclusive. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is within the specified range, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the min value is greater than the max value. |
IsBetween(ulong, ulong, ulong, bool)
Returns true if this int value falls within the range defined by
min and max. When inclusive is
true (default), both endpoints are considered part of the range ([min,
max]). When false, endpoints are excluded ((min,
max)).
Declaration
public static bool IsBetween(this ulong value, ulong min, ulong max, bool inclusive = true)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | value | The value to evaluate. |
| ulong | min | The lower boundary of the range. |
| ulong | max | The upper boundary of the range. |
| bool | inclusive | Specifies whether the boundaries are inclusive. If true, the range is inclusive of the boundaries; otherwise, the range is exclusive. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is within the specified range, otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the min value is greater than the max value. |
IsNearlyZero(double, double)
Returns true if the absolute value of this float is less than or equal to
epsilon. Equivalent to calling Approximately(value, 0f, epsilon).
The default epsilon is EPSILON (1e-6).
Declaration
public static bool IsNearlyZero(this double value, double epsilon = 1E-12)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to evaluate. |
| double | epsilon | The permissible range for the value to be considered nearly zero. Must be greater than or equal to zero. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is within the specified epsilon range of zero; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when the |
IsNearlyZero(float, float)
Returns true if the absolute value of this float is less than or equal to
epsilon. Equivalent to calling Approximately(value, 0f, epsilon).
The default epsilon is EPSILON (1e-6).
Declaration
public static bool IsNearlyZero(this float value, float epsilon = 1E-06)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The value to evaluate. |
| float | epsilon | The permissible range for the value to be considered nearly zero. Must be greater than or equal to zero. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is within the specified epsilon range of zero; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when the |
Mod(decimal, decimal)
Computes a mathematically correct modulo of this float divided by
m, always returning a non-negative result in [0, m).
Unlike C#'s % operator, negative inputs produce a positive remainder.
Declaration
public static decimal Mod(this decimal value, decimal m)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | value | The value to compute the modulo for. |
| decimal | m | The divisor, which must be greater than 0. |
Returns
| Type | Description |
|---|---|
| decimal | The result of the modulo operation, always within the range [0, m). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
Mod(double, double)
Computes a mathematically correct modulo of this float divided by
m, always returning a non-negative result in [0, m).
Unlike C#'s % operator, negative inputs produce a positive remainder.
Declaration
public static double Mod(this double value, double m)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to compute the modulo for. |
| double | m | The divisor, which must be greater than 0. |
Returns
| Type | Description |
|---|---|
| double | The result of the modulo operation, always within the range [0, m). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
Mod(int, int)
Computes a mathematically correct modulo of this int divided by m,
always returning a non-negative result in [0, m). Unlike C#'s %
operator, which returns a negative remainder for negative dividends, this method follows the
mathematical definition: (-1).Mod(5) returns 4.
Declaration
public static int Mod(this int value, int m)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The integer value to compute the modulo for. |
| int | m | The divisor, which must be greater than 0. |
Returns
| Type | Description |
|---|---|
| int | The result of the modulo operation, always in the range [0, m). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
Mod(long, long)
Computes a mathematically correct modulo of this int divided by m,
always returning a non-negative result in [0, m). Unlike C#'s %
operator, which returns a negative remainder for negative dividends, this method follows the
mathematical definition: (-1).Mod(5) returns 4.
Declaration
public static long Mod(this long value, long m)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The integer value to compute the modulo for. |
| long | m | The divisor, which must be greater than 0. |
Returns
| Type | Description |
|---|---|
| long | The result of the modulo operation, always in the range [0, m). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
Mod(float, float)
Computes a mathematically correct modulo of this float divided by
m, always returning a non-negative result in [0, m).
Unlike C#'s % operator, negative inputs produce a positive remainder.
Declaration
public static float Mod(this float value, float m)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The value to compute the modulo for. |
| float | m | The divisor, which must be greater than 0. |
Returns
| Type | Description |
|---|---|
| float | The result of the modulo operation, always within the range [0, m). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
Repeat(double, double)
Loops this float so that it always falls within [0, length).
When the value equals or exceeds length, it wraps back to near zero. This
is analogous to a sawtooth function and is useful for cyclic animations, texture tiling
offsets, and angle wrapping. Negative inputs also wrap correctly into the positive range.
Declaration
public static double Repeat(this double value, double length)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | |
| double | length | The length of the range. Must be greater than 0. |
Returns
| Type | Description |
|---|---|
| double | A value in the range [0, |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
Repeat(float, float)
Loops this float so that it always falls within [0, length).
When the value equals or exceeds length, it wraps back to near zero. This
is analogous to a sawtooth function and is useful for cyclic animations, texture tiling
offsets, and angle wrapping. Negative inputs also wrap correctly into the positive range.
Declaration
public static float Repeat(this float value, float length)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | |
| float | length | The length of the range. Must be greater than 0. |
Returns
| Type | Description |
|---|---|
| float | A value in the range [0, |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
RoundToDecimals(decimal, int)
Rounds this float to decimals decimal places using
midpoint-rounding-away-from-zero semantics. Passing 0 rounds to the nearest whole number;
negative values for decimals are not supported and may produce unexpected results.
Declaration
public static decimal RoundToDecimals(this decimal value, int decimals)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | value | The float value to round. |
| int | decimals | The number of decimal places to round to. Must be greater than or equal to zero. |
Returns
| Type | Description |
|---|---|
| decimal | The rounded float value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
RoundToDecimals(double, int)
Rounds this float to decimals decimal places using
midpoint-rounding-away-from-zero semantics. Passing 0 rounds to the nearest whole number;
negative values for decimals are not supported and may produce unexpected results.
Declaration
public static double RoundToDecimals(this double value, int decimals)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The float value to round. |
| int | decimals | The number of decimal places to round to. Must be greater than or equal to zero. |
Returns
| Type | Description |
|---|---|
| double | The rounded float value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
RoundToDecimals(float, int)
Rounds this float to decimals decimal places using
midpoint-rounding-away-from-zero semantics. Passing 0 rounds to the nearest whole number;
negative values for decimals are not supported and may produce unexpected results.
Declaration
public static float RoundToDecimals(this float value, int decimals)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The float value to round. |
| int | decimals | The number of decimal places to round to. Must be greater than or equal to zero. |
Returns
| Type | Description |
|---|---|
| float | The rounded float value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
Snap(decimal, decimal)
Rounds this float to the nearest multiple of step.
Useful for grid snapping, quantizing audio levels, or aligning values to fixed increments.
For example, 1.7f.Snap(0.5f) returns 1.5f.
Declaration
public static decimal Snap(this decimal value, decimal step)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | value | The value to be rounded. |
| decimal | step | The step size to which the value will be rounded. Must be greater than 0. |
Returns
| Type | Description |
|---|---|
| decimal | The rounded value, as a multiple of the specified step. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if the step is less than or equal to 0. |
Snap(double, double)
Rounds this float to the nearest multiple of step.
Useful for grid snapping, quantizing audio levels, or aligning values to fixed increments.
For example, 1.7f.Snap(0.5f) returns 1.5f.
Declaration
public static double Snap(this double value, double step)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to be rounded. |
| double | step | The step size to which the value will be rounded. Must be greater than 0. |
Returns
| Type | Description |
|---|---|
| double | The rounded value, as a multiple of the specified step. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if the step is less than or equal to 0. |
Snap(float, float)
Rounds this float to the nearest multiple of step.
Useful for grid snapping, quantizing audio levels, or aligning values to fixed increments.
For example, 1.7f.Snap(0.5f) returns 1.5f.
Declaration
public static float Snap(this float value, float step)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The value to be rounded. |
| float | step | The step size to which the value will be rounded. Must be greater than 0. |
Returns
| Type | Description |
|---|---|
| float | The rounded value, as a multiple of the specified step. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if the step is less than or equal to 0. |
Wrap(int, int, int)
Wraps this int into the half-open interval
[minInclusive, maxExclusive). When the value falls below
minInclusive or reaches maxExclusive, it is folded back
into range. This is the ranged equivalent of Mod(int, int) and is useful for
circular array indexing, sprite frame looping, and menu navigation wrap-around.
Declaration
public static int Wrap(this int value, int minInclusive, int maxExclusive)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The value to be wrapped. |
| int | minInclusive | The inclusive lower bound of the interval. |
| int | maxExclusive | The exclusive upper bound of the interval. |
Returns
| Type | Description |
|---|---|
| int | The wrapped value, constrained within the interval [minInclusive, maxExclusive). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown if |
Wrap(long, long, long)
Wraps this int into the half-open interval
[minInclusive, maxExclusive). When the value falls below
minInclusive or reaches maxExclusive, it is folded back
into range. This is the ranged equivalent of Mod(int, int) and is useful for
circular array indexing, sprite frame looping, and menu navigation wrap-around.
Declaration
public static long Wrap(this long value, long minInclusive, long maxExclusive)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The value to be wrapped. |
| long | minInclusive | The inclusive lower bound of the interval. |
| long | maxExclusive | The exclusive upper bound of the interval. |
Returns
| Type | Description |
|---|---|
| long | The wrapped value, constrained within the interval [minInclusive, maxExclusive). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown if |
Wrap(uint, uint, uint)
Wraps this int into the half-open interval
[minInclusive, maxExclusive). When the value falls below
minInclusive or reaches maxExclusive, it is folded back
into range. This is the ranged equivalent of Mod(int, int) and is useful for
circular array indexing, sprite frame looping, and menu navigation wrap-around.
Declaration
public static uint Wrap(this uint value, uint minInclusive, uint maxExclusive)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | The value to be wrapped. |
| uint | minInclusive | The inclusive lower bound of the interval. |
| uint | maxExclusive | The exclusive upper bound of the interval. |
Returns
| Type | Description |
|---|---|
| uint | The wrapped value, constrained within the interval [minInclusive, maxExclusive). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown if |
Wrap(ulong, ulong, ulong)
Wraps this int into the half-open interval
[minInclusive, maxExclusive). When the value falls below
minInclusive or reaches maxExclusive, it is folded back
into range. This is the ranged equivalent of Mod(int, int) and is useful for
circular array indexing, sprite frame looping, and menu navigation wrap-around.
Declaration
public static ulong Wrap(this ulong value, ulong minInclusive, ulong maxExclusive)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | value | The value to be wrapped. |
| ulong | minInclusive | The inclusive lower bound of the interval. |
| ulong | maxExclusive | The exclusive upper bound of the interval. |
Returns
| Type | Description |
|---|---|
| ulong | The wrapped value, constrained within the interval [minInclusive, maxExclusive). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown if |