Class NumberUtil
Provides a comprehensive set of deterministic numeric utility methods covering clamping, range checks, floating-point comparisons, rounding, interpolation, modular arithmetic, safe division, power-of-two alignment, angle operations, and common math helpers across all standard numeric types.
Inherited Members
Namespace: Scylla.Core.Util
Assembly: ScyllaCore.dll
Syntax
public static class NumberUtil
Remarks
Float-based methods delegate to UnityEngine.Mathf where available, while
double and decimal overloads use Math
directly. This ensures identical results to Unity's built-in math on
float inputs.
All methods are deterministic and contain no randomness. For random number
generation see RandomUtil.
Floating-point equality comparisons use Approximately(float, float, float)
rather than == to avoid false negatives due to floating-point rounding.
The default tolerance constants are EPSILON (1e-6f) for
float and EPSILON_D (1e-12) for double.
Fields
EPSILON
Default tolerance used by float comparison helpers such as
Approximately(float, float, float) and
IsNearlyZero(float, float). Equal to 1e-6.
Declaration
public const float EPSILON = 1E-06
Field Value
| Type | Description |
|---|---|
| float |
Remarks
This value is significantly tighter than UnityEngine.Mathf.Epsilon (which is the smallest representable positive float) but loose enough to absorb typical single-precision rounding errors in game math. Increase the tolerance when comparing values that have accumulated over many arithmetic operations.
EPSILON_D
Default tolerance used by double comparison helpers such as
Approximately(double, double, double) and
IsNearlyZero(double, double). Equal to 1e-12.
Declaration
public const double EPSILON_D = 1E-12
Field Value
| Type | Description |
|---|---|
| double |
Remarks
This tolerance is appropriate for double-precision values where roughly 12 significant decimal digits of precision are expected. Tighten or loosen it per-call when the algorithm demands higher or lower accuracy.
Methods
AbsDiff(int, int)
Returns the absolute (unsigned) difference between two integers -
equivalent to Math.Abs(a - b) but without the risk of an intermediate
overflow when a and b have opposite signs
near the bounds of int.
Declaration
public static int AbsDiff(int a, int b)
Parameters
| Type | Name | Description |
|---|---|---|
| int | a | The first integer value. |
| int | b | The second integer value. |
Returns
| Type | Description |
|---|---|
| int | The absolute difference between the two integers. |
AbsDiff(long, long)
Calculates the absolute difference between two long integers.
Declaration
public static long AbsDiff(long a, long b)
Parameters
| Type | Name | Description |
|---|---|---|
| long | a | The first long integer. |
| long | b | The second long integer. |
Returns
| Type | Description |
|---|---|
| long | The absolute difference between the two long integers. |
AbsDiff(uint, uint)
Calculates the absolute difference between two unsigned integers.
Declaration
public static uint AbsDiff(uint a, uint b)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | a | The first unsigned integer. |
| uint | b | The second unsigned integer. |
Returns
| Type | Description |
|---|---|
| uint | The absolute difference between the two values. |
AbsDiff(ulong, ulong)
Calculates the absolute difference between two unsigned long integers.
Declaration
public static ulong AbsDiff(ulong a, ulong b)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | a | The first unsigned long integer. |
| ulong | b | The second unsigned long integer. |
Returns
| Type | Description |
|---|---|
| ulong | The absolute difference between the two values. |
AlignDown(uint, uint)
Aligns the given value down to the nearest multiple of the specified alignment.
Declaration
public static uint AlignDown(uint value, uint alignment)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | The value to be aligned down. |
| uint | alignment | The alignment value, which must be greater than 0. |
Returns
| Type | Description |
|---|---|
| uint | The largest multiple of the alignment that is less than or equal to the value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if the alignment is 0. |
AlignDown(ulong, ulong)
Aligns a value down to the nearest multiple of a specified alignment.
Declaration
public static ulong AlignDown(ulong value, ulong alignment)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | value | The value to align down. |
| ulong | alignment | The alignment value, which must be greater than 0. |
Returns
| Type | Description |
|---|---|
| ulong | The largest multiple of the alignment less than or equal to the original value. |
AlignUp(uint, uint)
Aligns a value up to the nearest multiple of the specified alignment.
Declaration
public static uint AlignUp(uint value, uint alignment)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | The value to align. |
| uint | alignment | The alignment boundary to which the value will be aligned. |
Returns
| Type | Description |
|---|---|
| uint | The value aligned to the nearest multiple of the alignment. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
| OverflowException | Thrown if the aligned value would overflow. |
AlignUp(ulong, ulong)
Aligns a value up to the nearest multiple of the specified alignment.
Declaration
public static ulong AlignUp(ulong value, ulong alignment)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | value | The value to align. |
| ulong | alignment | The alignment boundary. Must be greater than 0. |
Returns
| Type | Description |
|---|---|
| ulong | The aligned value, which is the smallest multiple of the alignment greater than or equal to the input value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
| OverflowException | Thrown if the aligned value exceeds the range of ulong. |
Approximately(double, double, double)
Determines whether two double precision floating-point numbers are approximately equal within a specified tolerance.
Declaration
public static bool Approximately(double a, double b, double epsilon = 1E-12)
Parameters
| Type | Name | Description |
|---|---|---|
| double | a | The first double value to compare. |
| double | b | The second double value to compare. |
| double | epsilon | The maximum difference between the two values for them to be considered approximately equal. Must be non-negative. |
Returns
| Type | Description |
|---|---|
| bool | True if the absolute difference between |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
Approximately(float, float, float)
Determines whether two floating-point numbers are approximately equal, within a specified tolerance.
Declaration
public static bool Approximately(float a, float b, float epsilon = 1E-06)
Parameters
| Type | Name | Description |
|---|---|---|
| float | a | The first floating-point number to compare. |
| float | b | The second floating-point number to compare. |
| 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 |
CeilToInt(double)
Rounds the specified floating-point value up to the nearest higher integer.
Declaration
public static int CeilToInt(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The floating-point value to ceil. |
Returns
| Type | Description |
|---|---|
| int | The smallest integer value greater than or equal to the specified value. |
CeilToInt(float)
Rounds the specified floating-point value to the smallest integer greater than or equal to it.
Declaration
public static int CeilToInt(float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The floating-point value to be rounded up. |
Returns
| Type | Description |
|---|---|
| int | The smallest integer greater than or equal to the specified value. |
Clamp(decimal, decimal, decimal)
Clamps an integer value to the inclusive range [min, max].
If value is below the minimum, the minimum is returned;
if it is above the maximum, the maximum is returned; otherwise the value is
returned unchanged.
Declaration
public static decimal Clamp(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 a double-precision floating-point value to the inclusive range
[min, max].
Declaration
public static double Clamp(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 an integer value to the inclusive range [min, max].
If value is below the minimum, the minimum is returned;
if it is above the maximum, the maximum is returned; otherwise the value is
returned unchanged.
Declaration
public static int Clamp(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 a 64-bit signed integer value to the inclusive range
[min, max].
Declaration
public static long Clamp(long value, long min, long max)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The 64-bit signed integer 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 a single-precision floating-point value to the inclusive range
[min, max].
Declaration
public static float Clamp(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 an unsigned 32-bit integer value to the inclusive range
[min, max].
Declaration
public static uint Clamp(uint value, uint min, uint max)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | The unsigned integer 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 an unsigned 64-bit integer value to the inclusive range
[min, max].
Declaration
public static ulong Clamp(ulong value, ulong min, ulong max)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | value | The unsigned 64-bit integer 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 a double-precision floating-point value to the inclusive range [0, 1].
Declaration
public static double Clamp01(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 a given value to the inclusive range of [0, 1].
Declaration
public static float Clamp01(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]. |
Cube(decimal)
Returns the cube of the specified decimal value (value * value * value).
Declaration
public static decimal Cube(decimal value)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | value | The decimal value to cube. The sign is preserved in the result. |
Returns
| Type | Description |
|---|---|
| decimal |
|
Cube(double)
Returns the cube of the specified double value (value * value * value).
Declaration
public static double Cube(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The double-precision value to cube. The sign is preserved in the result. |
Returns
| Type | Description |
|---|---|
| double |
|
Cube(int)
Returns the cube of the specified int value (value * value * value).
Useful as a concise alternative to Math.Pow(value, 3) without a cast or
allocation.
Declaration
public static int Cube(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The integer value to cube. The sign is preserved in the result. |
Returns
| Type | Description |
|---|---|
| int |
|
Cube(long)
Returns the cube of the specified long value (value * value * value).
Declaration
public static long Cube(long value)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The 64-bit integer value to cube. The sign is preserved in the result. |
Returns
| Type | Description |
|---|---|
| long |
|
Cube(float)
Returns the cube of the specified float value (value * value * value).
Declaration
public static float Cube(float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The float value to cube. The sign is preserved in the result. |
Returns
| Type | Description |
|---|---|
| float |
|
DegToRad(float)
Converts an angle from degrees to radians.
Declaration
public static float DegToRad(float degrees)
Parameters
| Type | Name | Description |
|---|---|---|
| float | degrees | The angle in degrees. |
Returns
| Type | Description |
|---|---|
| float | The equivalent angle in radians. |
DeltaAngleDeg(float, float)
Calculates the shortest signed angle difference (in degrees) from the current angle to the target angle. The result is normalized to the range [-180, 180).
Declaration
public static float DeltaAngleDeg(float current, float target)
Parameters
| Type | Name | Description |
|---|---|---|
| float | current | The current angle in degrees. |
| float | target | The target angle in degrees. |
Returns
| Type | Description |
|---|---|
| float | The shortest signed angle difference (in degrees) from the current angle to the target angle, within the range [-180, 180). |
DeltaAngleRad(float, float)
Calculates the shortest signed angle difference, in radians, between the specified current and target angles. The returned angle will be within the range [-π, π).
Declaration
public static float DeltaAngleRad(float current, float target)
Parameters
| Type | Name | Description |
|---|---|---|
| float | current | The current angle in radians. |
| float | target | The target angle in radians. |
Returns
| Type | Description |
|---|---|
| float | The shortest signed angle difference in radians, within the range [-π, π). |
EnsureFinite(double, string)
Ensures that the provided value is finite (neither NaN nor infinity).
Declaration
public static double EnsureFinite(double value, string name)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to validate as finite. |
| string | name | The name of the parameter being validated, used in exception messages. |
Returns
| Type | Description |
|---|---|
| double | The original value if it is finite. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when the value is NaN or infinity, indicating that it is not a finite number. |
EnsureFinite(float, string)
Ensures that the provided value is finite (neither NaN nor infinity).
Declaration
public static float EnsureFinite(float value, string name)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The value to validate as finite. |
| string | name | The name of the parameter being validated, used in exception messages. |
Returns
| Type | Description |
|---|---|
| float | The original value if it is finite. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when the value is NaN or infinity, indicating that it is not a finite number. |
EnsureFiniteNonNegative(double, string)
Ensures that the provided value is finite and non-negative.
Declaration
public static double EnsureFiniteNonNegative(double value, string name)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to validate. |
| string | name | The name of the parameter being validated, used in exception messages. |
Returns
| Type | Description |
|---|---|
| double | The validated value, if it is both finite and non-negative. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if the value is NaN, infinity, or less than 0. |
EnsureFiniteNonNegative(float, string)
Ensures that the provided value is finite and non-negative.
Declaration
public static float EnsureFiniteNonNegative(float value, string name)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The value to validate. |
| string | name | The name of the parameter being validated, used in exception messages. |
Returns
| Type | Description |
|---|---|
| float | The validated value, if it is both finite and non-negative. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if the value is NaN, infinity, or less than 0. |
FloorToInt(double)
Floors the specified float value to the nearest lower integer.
Declaration
public static int FloorToInt(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The float value to floor. |
Returns
| Type | Description |
|---|---|
| int | The largest integer less than or equal to the specified float value. |
FloorToInt(float)
Floors the specified float value to the nearest lower integer.
Declaration
public static int FloorToInt(float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The float value to floor. |
Returns
| Type | Description |
|---|---|
| int | The largest integer less than or equal to the specified value. |
InverseLerp(double, double, double)
Calculates the normalized interpolation factor for a value within a specified range, clamped to the range [0, 1].
Declaration
public static double InverseLerp(double a, double b, double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | a | The start of the range. |
| double | b | The end of the range. |
| double | value | The value to calculate the interpolation factor for. |
Returns
| Type | Description |
|---|---|
| double | The normalized interpolation factor, clamped to the range [0, 1]. |
InverseLerp(float, float, float)
Computes a clamped interpolation factor t in the range [0, 1] such that Lerp(a, b, t) equals the specified value. Returns 0 when a is equal to b.
Declaration
public static float InverseLerp(float a, float b, float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | a | The start value of the range. |
| float | b | The end value of the range. |
| float | value | The value for which the interpolation factor is computed. |
Returns
| Type | Description |
|---|---|
| float | The interpolated factor t in the range [0, 1]. |
InverseLerpUnclamped(double, double, double)
Calculates the linear parameter t that produces the interpolant value within an unclamped range. Returns 0 when a is approximately equal to b.
Declaration
public static double InverseLerpUnclamped(double a, double b, double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | a | The start of the range. |
| double | b | The end of the range. |
| double | value | The value for which to calculate the parameter t within the range. |
Returns
| Type | Description |
|---|---|
| double | The linear parameter t that corresponds to the value within the range [a, b]. |
InverseLerpUnclamped(float, float, float)
Computes an unclamped interpolation factor t such that LerpUnclamped(a, b, t) == value. Returns 0 when a is approximately equal to b.
Declaration
public static float InverseLerpUnclamped(float a, float b, float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | a | The start value, corresponding to t = 0. |
| float | b | The end value, corresponding to t = 1. |
| float | value | The value to map between a and b. |
Returns
| Type | Description |
|---|---|
| float | The unclamped interpolation factor t. |
IsBetween(decimal, decimal, decimal, bool)
Determines whether a value lies within the specified range, optionally including the boundaries.
Declaration
public static bool IsBetween(decimal value, decimal min, decimal max, bool inclusive = true)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | value | The value to check. |
| decimal | min | The lower bound of the range. |
| decimal | max | The upper bound of the range. |
| bool | inclusive | Specifies whether the boundaries should be included in the range. Defaults to true. |
Returns
| Type | Description |
|---|---|
| bool | True if the value lies within the range; otherwise, false. |
IsBetween(double, double, double, bool)
Determines whether a value is within the specified range.
Declaration
public static bool IsBetween(double value, double min, double max, bool inclusive = true)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to check. |
| double | min | The lower bound of the range. |
| double | max | The upper bound of the range. |
| bool | inclusive | Specifies whether the bounds are inclusive. If true, the range is [min, max]. If false, the range is (min, max). |
Returns
| Type | Description |
|---|---|
| bool | True if the value is within the range; otherwise, false. |
IsBetween(int, int, int, bool)
Determines if a value is within a specified range, either inclusive or exclusive of the boundaries.
Declaration
public static bool IsBetween(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)
Determines whether a value is within the range defined by the specified minimum and maximum values.
Declaration
public static bool IsBetween(long value, long min, long max, bool inclusive = true)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The value to check. |
| long | min | The minimum value of the range. |
| long | max | The maximum value of the range. |
| bool | inclusive | Indicates whether the check should include the boundary values. If true, the range is inclusive; otherwise, it is exclusive. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is within the specified range; otherwise, false. |
IsBetween(float, float, float, bool)
Determines whether a value lies within the specified range, with an option to include or exclude the boundaries.
Declaration
public static bool IsBetween(float value, float min, float max, bool inclusive = true)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The value to test. |
| float | min | The lower bound of the range. |
| float | max | The upper bound of the range. |
| bool | inclusive | Determines if the boundary values should be included in the range. If true, the range is inclusive; otherwise, it is exclusive. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is within the specified range; otherwise, false. |
IsBetween(uint, uint, uint, bool)
Determines if a value lies within the specified range, with an option to include or exclude the boundaries.
Declaration
public static bool IsBetween(uint value, uint min, uint max, bool inclusive = true)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | The value to check. |
| uint | min | The minimum value of the range. |
| uint | max | The maximum value of the range. |
| bool | inclusive | Indicates whether the range includes the boundaries. Defaults to true. |
Returns
| Type | Description |
|---|---|
| bool | True if the value lies within the range; otherwise, false. |
IsBetween(ulong, ulong, ulong, bool)
Determines whether a value is within the range defined by the specified minimum and maximum values.
Declaration
public static bool IsBetween(ulong value, ulong min, ulong max, bool inclusive = true)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | value | The value to check. |
| ulong | min | The minimum value of the range. |
| ulong | max | The maximum value of the range. |
| bool | inclusive | Determines if the boundaries are inclusive. If true, the range includes min and max; otherwise, it excludes them. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is within the specified range; otherwise, false. |
IsEven(int)
Returns true if the specified int value is even (divisible by 2
with no remainder). Uses a bitwise AND for a branchless, allocation-free check.
Correctly handles negative values.
Declaration
public static bool IsEven(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The integer to evaluate. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsEven(long)
Returns true if the specified long value is even.
Correctly handles negative values.
Declaration
public static bool IsEven(long value)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The 64-bit integer to evaluate. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsEven(uint)
Returns true if the specified uint value is even.
Declaration
public static bool IsEven(uint value)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | The unsigned integer to evaluate. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsEven(ulong)
Returns true if the specified ulong value is even.
Declaration
public static bool IsEven(ulong value)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | value | The unsigned 64-bit integer to evaluate. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsFinite(double)
Determines whether the specified double-precision floating-point value is finite.
Declaration
public static bool IsFinite(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The double value to check for finiteness. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is finite (neither NaN nor infinity); otherwise, false. |
IsFinite(float)
Determines whether the specified floating-point value is finite (not NaN and not ±Infinity).
Declaration
public static bool IsFinite(float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The floating-point value to evaluate. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is finite; otherwise, false. |
IsNearlyZero(double, double)
Determines whether a given double-precision floating-point value is nearly zero, within a specified margin of error.
Declaration
public static bool IsNearlyZero(double value, double epsilon = 1E-12)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to check. |
| double | epsilon | The allowable margin of error to consider the value as nearly zero. Must be greater than or equal to 0. |
Returns
| Type | Description |
|---|---|
| bool | True if the absolute value is less than or equal to the specified epsilon; otherwise, false. |
IsNearlyZero(float, float)
Determines whether the specified value is within a defined epsilon range of zero.
Declaration
public static bool IsNearlyZero(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 |
IsOdd(int)
Returns true if the specified int value is odd (not divisible by 2
without a remainder). Uses a bitwise AND for a branchless, allocation-free check.
Correctly handles negative values.
Declaration
public static bool IsOdd(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The integer value to evaluate. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsOdd(long)
Returns true if the specified long value is odd.
Correctly handles negative values.
Declaration
public static bool IsOdd(long value)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The 64-bit integer to evaluate. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsOdd(uint)
Returns true if the specified uint value is odd.
Declaration
public static bool IsOdd(uint value)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | The unsigned integer to evaluate. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsOdd(ulong)
Returns true if the specified ulong value is odd.
Declaration
public static bool IsOdd(ulong value)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | value | The unsigned 64-bit integer to evaluate. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsPowerOfTwo(uint)
Determines whether the specified value is a power of two.
Declaration
public static bool IsPowerOfTwo(uint value)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | The value to check. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is a power of two; otherwise, false. |
IsPowerOfTwo(ulong)
Determines whether the specified value is a power of two.
Declaration
public static bool IsPowerOfTwo(ulong value)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | value | The value to check. |
Returns
| Type | Description |
|---|---|
| bool | True if the value is a power of two; otherwise, false. |
Lerp(double, double, double)
Linearly interpolates between two values based on a weight parameter t.
Declaration
public static double Lerp(double a, double b, double t)
Parameters
| Type | Name | Description |
|---|---|---|
| double | a | The starting value. |
| double | b | The target value. |
| double | t | The interpolation factor, typically in the range [0, 1]. |
Returns
| Type | Description |
|---|---|
| double | The interpolated value, which is a combination of a and b based on t. |
Lerp(float, float, float)
Linearly interpolates between two values based on a parameter t, while clamping t to the range [0, 1].
Declaration
public static float Lerp(float a, float b, float t)
Parameters
| Type | Name | Description |
|---|---|---|
| float | a | The starting value of the interpolation. |
| float | b | The ending value of the interpolation. |
| float | t | The parameter that determines the interpolation factor. It is clamped to the range [0, 1]. |
Returns
| Type | Description |
|---|---|
| float | The interpolated value between a and b. |
LerpAngleDeg(float, float, float)
Interpolates between two angles in degrees, taking into account angle wrapping (e.g., -180° to 180° or 0° to 360°) and clamping the interpolation factor to the range [0, 1].
Declaration
public static float LerpAngleDeg(float a, float b, float t)
Parameters
| Type | Name | Description |
|---|---|---|
| float | a | The starting angle in degrees. |
| float | b | The target angle in degrees. |
| float | t | The interpolation factor, where 0 represents the starting angle and 1 represents the target angle. |
Returns
| Type | Description |
|---|---|
| float | The interpolated angle in degrees. |
LerpUnclamped(double, double, double)
Interpolates between two values without clamping the interpolation factor.
Declaration
public static double LerpUnclamped(double a, double b, double t)
Parameters
| Type | Name | Description |
|---|---|---|
| double | a | The starting value of the interpolation. |
| double | b | The ending value of the interpolation. |
| double | t | The interpolation factor. This value is not clamped and can extend beyond the range [0, 1]. |
Returns
| Type | Description |
|---|---|
| double | The interpolated value. |
LerpUnclamped(float, float, float)
Linearly interpolates between two values without clamping the interpolation factor.
Declaration
public static float LerpUnclamped(float a, float b, float t)
Parameters
| Type | Name | Description |
|---|---|---|
| float | a | The start value of the interpolation. |
| float | b | The end value of the interpolation. |
| float | t | The interpolation factor, which is not clamped. Values less than 0 will extrapolate below |
Returns
| Type | Description |
|---|---|
| float | The interpolated value between |
Mod(decimal, decimal)
Computes the modulus of the given value and divisor, ensuring the result is always non-negative.
Declaration
public static decimal Mod(decimal value, decimal m)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | value | The value to compute the modulus for. |
| decimal | m | The divisor. Must be greater than zero. |
Returns
| Type | Description |
|---|---|
| decimal | The modulus result, which is always a non-negative value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when the divisor is less than or equal to zero. |
Mod(double, double)
Computes the remainder of a division operation, ensuring the result is always non-negative.
Declaration
public static double Mod(double value, double m)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The dividend in the division operation. |
| double | m | The divisor in the division operation. Must be greater than 0. |
Returns
| Type | Description |
|---|---|
| double | The remainder of the division operation, always in the range [0, m). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when the divisor ( |
Mod(int, int)
Computes the true modulo (always in the range [0, m)) for the specified integer value and divisor.
Declaration
public static int Mod(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)
Calculates the modulus of a value, ensuring the result is always non-negative.
Declaration
public static long Mod(long value, long m)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The value to calculate the modulus for. |
| long | m | The modulus base, which must be greater than 0. |
Returns
| Type | Description |
|---|---|
| long | The non-negative remainder of the division of the value by the modulus base. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when the modulus base is less than or equal to 0. |
Mod(float, float)
Computes the modulo of a value, ensuring the result is always within the range [0, m).
Declaration
public static float Mod(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 |
NextPowerOfTwo(uint)
Returns the next power of two greater than or equal to the specified value.
Declaration
public static uint NextPowerOfTwo(uint value)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | The value to compute the next power of two for. |
Returns
| Type | Description |
|---|---|
| uint | The next power of two greater than or equal to the specified value. |
Exceptions
| Type | Condition |
|---|---|
| OverflowException | Thrown if the next power of two exceeds the maximum value of the type. |
NextPowerOfTwo(ulong)
Calculates the next power of two greater than or equal to the specified value.
Declaration
public static ulong NextPowerOfTwo(ulong value)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | value | The value for which to calculate the next power of two. |
Returns
| Type | Description |
|---|---|
| ulong | The next power of two greater than or equal to the specified value. |
Exceptions
| Type | Condition |
|---|---|
| OverflowException | Thrown if the next power of two would exceed the maximum value of ulong. |
NormalizeAngleDeg180(float)
Normalizes an angle in degrees to the range [-180, 180).
Declaration
public static float NormalizeAngleDeg180(float angle)
Parameters
| Type | Name | Description |
|---|---|---|
| float | angle | The angle in degrees to normalize. |
Returns
| Type | Description |
|---|---|
| float | The normalized angle, which will be within the range [-180, 180). |
NormalizeAngleDeg360(float)
Normalizes an angle in degrees to the range [0, 360).
Declaration
public static float NormalizeAngleDeg360(float angle)
Parameters
| Type | Name | Description |
|---|---|---|
| float | angle | The angle in degrees to normalize. |
Returns
| Type | Description |
|---|---|
| float | The normalized angle within the range [0, 360). |
NormalizeAngleRad2Pi(float)
Normalizes an angle in radians to the range [0, 2π).
Declaration
public static float NormalizeAngleRad2Pi(float angle)
Parameters
| Type | Name | Description |
|---|---|---|
| float | angle | The angle in radians to normalize. |
Returns
| Type | Description |
|---|---|
| float | The normalized angle in the range [0, 2π). |
NormalizeAngleRadPi(float)
Normalizes an angle in radians to the range [-π, π).
Declaration
public static float NormalizeAngleRadPi(float angle)
Parameters
| Type | Name | Description |
|---|---|---|
| float | angle | The angle in radians to normalize. |
Returns
| Type | Description |
|---|---|
| float | The normalized angle within the range [-π, π). |
RadToDeg(float)
Converts a value from radians to degrees.
Declaration
public static float RadToDeg(float radians)
Parameters
| Type | Name | Description |
|---|---|---|
| float | radians | The angle in radians to convert. |
Returns
| Type | Description |
|---|---|
| float | The equivalent angle in degrees. |
Remap(double, double, double, double, double, bool)
Remaps a value from one range to another, with an option to clamp the result to the target range.
Declaration
public static double Remap(double value, double inMin, double inMax, double outMin, double outMax, bool clamp = false)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to remap. |
| double | inMin | The lower bound of the input range. |
| double | inMax | The upper bound of the input range. |
| double | outMin | The lower bound of the output range. |
| double | outMax | The upper bound of the output range. |
| bool | clamp | Indicates whether the output value should be clamped to the output range. |
Returns
| Type | Description |
|---|---|
| double | The remapped value, scaled to the range [outMin, outMax]. |
Remap(float, float, float, float, float, bool)
Remaps a specified value from one range to another.
Declaration
public static float Remap(float value, float inMin, float inMax, float outMin, float outMax, bool clamp = false)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The value to be remapped. |
| float | inMin | The lower bound of the input range. |
| float | inMax | The upper bound of the input range. |
| float | outMin | The lower bound of the output range. |
| float | outMax | The upper bound of the output range. |
| bool | clamp | Determines whether the interpolation factor should be clamped to the output range. |
Returns
| Type | Description |
|---|---|
| float | The value remapped to the output range. |
Repeat(double, double)
Repeats a value within the range [0, length). Effectively, it wraps the input value to stay within the specified range.
Declaration
public static double Repeat(double t, double length)
Parameters
| Type | Name | Description |
|---|---|---|
| double | t | The value to repeat. |
| double | length | The length of the range. Must be greater than 0. |
Returns
| Type | Description |
|---|---|
| double | The value wrapped within the range [0, length). |
Repeat(float, float)
Loops a given value so that it is constrained within the range [0, length).
Declaration
public static float Repeat(float t, float length)
Parameters
| Type | Name | Description |
|---|---|---|
| float | t | The value to loop. |
| 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 a decimal value to the specified number of decimal places.
Declaration
public static decimal RoundToDecimals(decimal value, int decimals)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | value | The decimal value to be rounded. |
| int | decimals | The number of decimal places to round to. Must be greater than or equal to 0. |
Returns
| Type | Description |
|---|---|
| decimal | The rounded decimal value. |
RoundToDecimals(double, int)
Rounds a double-precision floating-point value to the specified number of fractional decimal places.
Declaration
public static double RoundToDecimals(double value, int decimals)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The double value to round. |
| int | decimals | The number of decimal places to round to. Must be 0 or greater. |
Returns
| Type | Description |
|---|---|
| double | The rounded double value, rounded to the specified number of decimal places. |
RoundToDecimals(float, int)
Rounds the specified value to the given number of decimal places using midpoint rounding away from zero.
Declaration
public static float RoundToDecimals(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 |
RoundToInt(double)
Rounds a double value to the nearest integer, with midpoint values rounding away from zero.
Declaration
public static int RoundToInt(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The double value to be rounded. |
Returns
| Type | Description |
|---|---|
| int | The rounded integer value. |
Exceptions
| Type | Condition |
|---|---|
| OverflowException | Thrown if the rounded value exceeds the range of the |
RoundToInt(float)
Rounds the specified floating-point value to the nearest integer, with midpoint values rounded away from zero.
Declaration
public static int RoundToInt(float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The floating-point value to round. |
Returns
| Type | Description |
|---|---|
| int | The rounded integer value. |
SafeDivide(decimal, decimal, decimal)
Safely divides a numerator by a denominator, returning a fallback value if the denominator is zero.
Declaration
public static decimal SafeDivide(decimal numerator, decimal denominator, decimal fallback = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | numerator | The value to be divided. |
| decimal | denominator | The value to divide the numerator by. |
| decimal | fallback | The value to return if the denominator is zero. |
Returns
| Type | Description |
|---|---|
| decimal | The result of the division if the denominator is non-zero; otherwise, the fallback value. |
SafeDivide(double, double, double)
Safely divides a numerator by a denominator, returning a fallback value if the denominator is zero.
Declaration
public static double SafeDivide(double numerator, double denominator, double fallback = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| double | numerator | The value to be divided. |
| double | denominator | The value by which to divide the numerator. |
| double | fallback | The value to return if the denominator is zero. Defaults to 0. |
Returns
| Type | Description |
|---|---|
| double | The result of the division if the denominator is not zero; otherwise, the fallback value. |
SafeDivide(float, float, float)
Divides the specified numerator by the specified denominator. Returns the fallback value if the denominator is zero.
Declaration
public static float SafeDivide(float numerator, float denominator, float fallback = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| float | numerator | The value to be divided. |
| float | denominator | The value by which the numerator is divided. |
| float | fallback | The value to return if the denominator is zero. Defaults to 0. |
Returns
| Type | Description |
|---|---|
| float | The result of the division if the denominator is not zero, otherwise the fallback value. |
SignNonZero(double, double)
Returns -1 if the specified double value is strictly less than
-, or epsilon+1 for any value greater than or
equal to -epsilon. Values in the near-zero tolerance band are treated as
positive.
Declaration
public static int SignNonZero(double value, double epsilon = 1E-12)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The double-precision value to evaluate. |
| double | epsilon | The tolerance that defines the zero-band. Must be non-negative. Defaults to EPSILON_D. |
Returns
| Type | Description |
|---|---|
| int |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
SignNonZero(int)
Returns -1 if the specified integer value is negative, or +1 if
the value is zero or positive. Unlike Math.Sign(int), this method
never returns 0, making it safe to use as a divisor or direction multiplier
without an additional zero-check.
Declaration
public static int SignNonZero(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The integer value to evaluate. |
Returns
| Type | Description |
|---|---|
| int |
|
SignNonZero(long)
Returns -1 if the specified 64-bit integer value is negative, or +1
if the value is zero or positive. Unlike Math.Sign(long), this method
never returns 0.
Declaration
public static int SignNonZero(long value)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The 64-bit integer value to evaluate. |
Returns
| Type | Description |
|---|---|
| int |
|
SignNonZero(float, float)
Returns -1 if the specified float value is strictly less than
-, or epsilon+1 for any value greater than or
equal to -epsilon (including zero and near-zero values within the
tolerance band). This ensures zero and values within the epsilon band are always
treated as positive, making the result safe to use as a non-zero direction
multiplier.
Declaration
public static int SignNonZero(float value, float epsilon = 1E-06)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The float value to evaluate. |
| float | epsilon | The tolerance that defines the zero-band. Values in the range
|
Returns
| Type | Description |
|---|---|
| int |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
Snap(decimal, decimal)
Snaps a value to the nearest multiple of the specified step.
Declaration
public static decimal Snap(decimal value, decimal step)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | value | The value to be snapped. |
| decimal | step | The step size to which the value should be snapped. Must be greater than 0. |
Returns
| Type | Description |
|---|---|
| decimal | The value snapped to the nearest multiple of the step. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
Snap(double, double)
Rounds the given value to the nearest multiple of the specified step.
Declaration
public static double Snap(double value, double step)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to round. |
| double | step | The step size to which the value will be rounded. Must be greater than 0. |
Returns
| Type | Description |
|---|---|
| double | The value rounded to the nearest multiple of the specified step. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown if |
Snap(float, float)
Rounds the specified value to the nearest multiple of the specified step (midpoint rounds away from zero).
Declaration
public static float Snap(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. |
Sqr(decimal)
Returns the square of the specified decimal value (value * value).
Declaration
public static decimal Sqr(decimal value)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | value | The decimal value to square. May be negative; the result is always non-negative. |
Returns
| Type | Description |
|---|---|
| decimal |
|
Sqr(double)
Returns the square of the specified double value (value * value).
Declaration
public static double Sqr(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The double-precision value to square. May be negative; the result is always non-negative for finite inputs. |
Returns
| Type | Description |
|---|---|
| double |
|
Sqr(int)
Returns the square of the specified int value (value * value).
Useful as a concise alternative to Math.Pow(value, 2) without a cast or
allocation.
Declaration
public static int Sqr(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The integer value to square. May be negative; the result is always non-negative. |
Returns
| Type | Description |
|---|---|
| int |
|
Sqr(long)
Returns the square of the specified long value (value * value).
Declaration
public static long Sqr(long value)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The 64-bit integer value to square. May be negative; the result is always non-negative. |
Returns
| Type | Description |
|---|---|
| long |
|
Sqr(float)
Returns the square of the specified float value (value * value).
Declaration
public static float Sqr(float value)
Parameters
| Type | Name | Description |
|---|---|---|
| float | value | The float value to square. May be negative; the result is always non-negative for finite inputs. |
Returns
| Type | Description |
|---|---|
| float |
|
Wrap(int, int, int)
Wraps a value into the half-open interval defined by the specified minimum (inclusive) and maximum (exclusive) bounds.
Declaration
public static int Wrap(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 a given value such that it falls within the inclusive lower bound and exclusive upper bound, cycling back to the lower bound if it exceeds the upper bound.
Declaration
public static long Wrap(long value, long minInclusive, long maxExclusive)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The value to wrap. |
| long | minInclusive | The inclusive lower bound of the range. |
| long | maxExclusive | The exclusive upper bound of the range. |
Returns
| Type | Description |
|---|---|
| long | The wrapped value within the range [minInclusive, maxExclusive). |
Wrap(uint, uint, uint)
Wraps a value to fit within a specified range, ensuring that the resulting value lies within [minInclusive, maxExclusive).
Declaration
public static uint Wrap(uint value, uint minInclusive, uint maxExclusive)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | The value to wrap. |
| uint | minInclusive | The inclusive lower bound of the range. |
| uint | maxExclusive | The exclusive upper bound of the range. Must be greater than |
Returns
| Type | Description |
|---|---|
| uint | The wrapped value, guaranteed to be within the range [minInclusive, maxExclusive). |
Wrap(ulong, ulong, ulong)
Wraps a value such that it falls within the specified range [minInclusive, maxExclusive). If the value is outside the range, it is adjusted to "wrap around" within the range.
Declaration
public static ulong Wrap(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 range. |
| ulong | maxExclusive | The exclusive upper bound of the range. |
Returns
| Type | Description |
|---|---|
| ulong | The wrapped value, adjusted to lie within the range [minInclusive, maxExclusive). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when maxExclusive is less than or equal to minInclusive, or when the range is zero. |