Class MathUtils
Contains helper math-related methods.
public static class MathUtils
- Inheritance
-
MathUtils
- Inherited Members
Methods
BigDivU128(ulong, ulong, uint)
Divides a 128-bit unsigned value by uint value.
[Pure]
public static (ulong QuotientHigh, ulong QuotientLow, ulong Remainder) BigDivU128(ulong leftHigh, ulong leftLow, uint right)
Parameters
leftHigh
ulongHigh 64 bits of the dividend.
leftLow
ulongLow 64 bits of the dividend.
right
uint32-bit divisor.
Returns
- (ulong QuotientHigh, ulong QuotientLow, ulong Remainder)
Tuple representing division result as quotient and remainder.
Exceptions
- DivideByZeroException
When the divisor is equal to 0.
BigDivU128(ulong, ulong, ulong)
Divides a 128-bit unsigned value by ulong value.
[Pure]
public static (ulong QuotientHigh, ulong QuotientLow, ulong Remainder) BigDivU128(ulong leftHigh, ulong leftLow, ulong right)
Parameters
leftHigh
ulongHigh 64 bits of the dividend.
leftLow
ulongLow 64 bits of the dividend.
right
ulong64-bit divisor.
Returns
- (ulong QuotientHigh, ulong QuotientLow, ulong Remainder)
Tuple representing division result as quotient and remainder.
Exceptions
- DivideByZeroException
When the divisor is equal to 0.
BigMulU128(ulong, ulong)
Multiples two ulong values.
[Pure]
public static (ulong High, ulong Low) BigMulU128(ulong left, ulong right)
Parameters
Returns
Remarks
See BigMul(ulong, ulong, out ulong) for more information.
ConvertToFractions(IEnumerable<Percent>, Fraction)
Converts the provided range of percentages
into an equivalent range of fractions,
whose sum is equal to the specified targetSum
and whose denominators
are all equal to the targetSum
Denominator.
[Pure]
public static Fraction[] ConvertToFractions(IEnumerable<Percent> percentages, Fraction targetSum)
Parameters
percentages
IEnumerable<Percent>Range of percentages to convert into fractions.
targetSum
FractionExpected sum of resulting fractions and their Denominator definition.
Returns
- Fraction[]
Range of fractions whose number is equal to the number of the provided
percentages
and whose sum is equal to thetargetSum
.
Exceptions
- ArgumentOutOfRangeException
When
targetSum
is less than 0 or any of the providedpercentages
is less than or equal to 0.
Gcd(ulong, ulong)
Calculates the GCD (greatest common divisor) of two ulong values.
[Pure]
public static ulong Gcd(ulong a, ulong b)
Parameters
Returns
- ulong
Greatest common divisor.
Remarks
When the second value is equal to 0, then this method will return the first value.
Lcm(ulong, ulong)
Calculates the LCM (least common multiple) of two ulong values.
[Pure]
public static ulong Lcm(ulong a, ulong b)
Parameters
Returns
- ulong
Least common multiple.
ToSigned(ulong, int)
[Pure]
public static long ToSigned(ulong value, int sign)
Parameters
Returns
- long
Provided
value
converted to long. Result will be negated when the providedsign
is less than 0.
Exceptions
- OverflowException
When the result causes an arithmetic overflow.
ToUnsigned(long, ref int)
public static ulong ToUnsigned(long value, ref int sign)
Parameters
value
longValue to convert.
sign
intref parameter that gets negated when the provided
value
is negative.
Returns
UnsignedAbs(long)
Calculates an absolute value from the given parameter and converts it to ulong.
[Pure]
public static ulong UnsignedAbs(long value)
Parameters
value
longValue to calculate an absolute value from.