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
leftHighulongHigh 64 bits of the dividend.
leftLowulongLow 64 bits of the dividend.
rightuint32-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
leftHighulongHigh 64 bits of the dividend.
leftLowulongLow 64 bits of the dividend.
rightulong64-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 targetSumDenominator.
[Pure]
public static Fraction[] ConvertToFractions(IEnumerable<Percent> percentages, Fraction targetSum)
Parameters
percentagesIEnumerable<Percent>Range of percentages to convert into fractions.
targetSumFractionExpected sum of resulting fractions and their Denominator definition.
Returns
- Fraction[]
Range of fractions whose number is equal to the number of the provided
percentagesand whose sum is equal to thetargetSum.
Exceptions
- ArgumentOutOfRangeException
When
targetSumis less than 0 or any of the providedpercentagesis 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
valueconverted to long. Result will be negated when the providedsignis 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
valuelongValue to convert.
signintref parameter that gets negated when the provided
valueis 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
valuelongValue to calculate an absolute value from.