Table of Contents

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 T
b T

Returns

bool

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 T
b T
tolerance T

Returns

bool

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 int

The 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 of n.

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 T

The first number to compare.

b T

The second number to compare.

Returns

(T min, T max)

A tuple of the two given numbers where the smallest number is first.

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 int

The dividend, which can be a negative or positive integer.

divisor int

The divisor, which can be a negative or positive integer, but not zero.

Returns

int

The modulus of dividend divided by the absolute value of divisor. 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