Class MathX
- Namespace
- AlgorithmsSW
- Assembly
- AlgorithmsSW.dll
Provides math-related utility methods.
public static class MathX
- Inheritance
-
MathX
- Inherited Members
Methods
ApproximatelyEqual<T>(T, T)
Checks whether two numbers are approximately equal.
public static bool ApproximatelyEqual<T>(T a, T b) where T : IFloatingPointIeee754<T>
Parameters
a
Tb
T
Returns
Type Parameters
T
ApproximatelyEqual<T>(T, T, T)
Checks whether two numbers are approximately equal.
public static bool ApproximatelyEqual<T>(T a, T b, T tolerance) where T : INumber<T>
Parameters
a
Tb
Ttolerance
T
Returns
Type Parameters
T
Cube<T>(T)
Computes the cube of a number.
public static T Cube<T>(T n) where T : INumber<T>
Parameters
n
T
Returns
- T
Type Parameters
T
IntegerCeilLog2(int)
Computes the floor of the base-2 logarithm of a number.
public static int IntegerCeilLog2(int n)
Parameters
n
intThe number whose logarithm is to be computed.
Returns
- int
0 if
n
is 1 or smaller (including negative); otherwise, the floor of the base-2 logarithm ofn
.
MinMax<T>(T, T)
Returns the given numbers as a tuple where the smallest one is first.
public static (T min, T max) MinMax<T>(T a, T b) where T : IComparisonOperators<T, T, bool>
Parameters
a
TThe first number to compare.
b
TThe second number to compare.
Returns
Type Parameters
T
The type of the numbers.
Mod(int, int)
Computes the modulus of a number, ensuring a non-negative result.
public static int Mod(int dividend, int divisor)
Parameters
dividend
intThe dividend, which can be a negative or positive integer.
divisor
intThe divisor, which can be a negative or positive integer, but not zero.
Returns
- int
The modulus of
dividend
divided by the absolute value ofdivisor
. Unlike the standard modulus operator, this function ensures that the result is always non-negative.
Exceptions
- ArgumentException
Thrown when
divisor
is 0.
Sqr<T>(T)
Computes the square of a number.
public static T Sqr<T>(T n) where T : INumber<T>
Parameters
n
T
Returns
- T
Type Parameters
T