Skip to content

Algebra

Tav edited this page Jul 1, 2016 · 21 revisions

###Namespace: RedMath

This class is meant to handle all of the common mathematical functions that one may need. It handles the simpler functions in mathematics e.g. Power, Root, Log, Floor, etc.

Power(double b, double x)

Returns b raised to the x power.

Parameters:

  • double b : The base of the power
  • double x : The power to raise b to

Example:

Algebra.Power(2, 3)
The result is 8


Factorial(ulong x)

Returns the factorial of x.

Parameters:

  • uint x : The value to get the factorial of

Example:

Algebra.Factorial(5)
The result is 120


Exponent(double x)

Returns e raised to the x power.

Parameters:

  • double x : The power to raise e to

Example:

Algebra.Exponent(5)
The result is 148.4131...


Exponent(Complex z)

Returns e raised to the complex z power.

Parameters:

  • double z : The complex power to raise e to

Example:

Algebra.Exponent(new Complex(2, 3))
The result is -7.315+1.043i


IntExponent(int x)

Returns e raised to the x power. Faster then calculating the real exponent - Meant to be used in highly optimised environments.

Parameters:

  • int x : The integer power to raise e to

Example:

Algebra.IntExponent(5)
The result is 148.4131...


NaturalLogarithm(double x)

Returns the natural logarithem of x (ln(x)).

Parameters:

  • double x : The value to solve the natural logarithem for

Example:

Algebra.NaturalLogarithem(Algebra.E)
The result is 1


Sign(double x)

Returns the sign of x :

  • x > 0 Returns 1
  • x < 0 Returns -1
  • x = 0 Returns 0

Parameters:

  • double x : The number to get it's sign

Example:

Algebra.Sign(-7)
The result is -1


Max(double a, double b)

Returns the larger number of the two.

Parameters:

  • double a : The first number to compare
  • double b : The second number to compare

Example:

Algebra.Max(-3, 8)
The result is 8


Min(double a, double b)

Returns the smaller number of the two.

Parameters:

  • double a : The first number to compare
  • double b : The second number to compare

Example:

Algebra.Min(-3, 8)
The result is -3


AGM(double x, double y)

Returns the Arithmetic–Geometric Mean.

Parameters:

  • double x : The first number to use for the computation
  • double y : The second number to use for the computation

Example:

Algebra.AGM(10, 20)
The result is 14.4275


Round(double x)

Returns the number rounded.

Parameters:

  • double x : The number to round

Example:

Algebra.Round(3.2)
The result is 3


Ceiling(double x)

Returns the number rounded up.

Parameters:

  • double x : The number to round

Example:

Algebra.Ceiling(3.2)
The result is 4


Floor(double x)

Returns the number rounded down.

Parameters:

  • double x : The number to round

Example:

Algebra.Floor(3.2)
The result is 3


Absolute(double x)

Returns the absolute value of the given number.

Parameters:

  • double x : The number to get the absolute value of

Example:

Algebra.Absolute(-5)
The result is 5


IsPowerOfTwo(ulong x)

Returns a boolean that determines if the given number is a power of two.

Parameters:

  • ulong x : The number to test

Example:

Algebra.IsPowerOfTwo(8)
The result is 'true'


NextGreaterPowerOfTwo(int x)

Returns the next greater power of two. If the x is already a power of two, returns x.

Parameters:

  • int x : The number to get it's next greater power of two

Example:

Algebra.NextGreaterPowerOfTwo(29)
The result is 32


SquareRoot(double a)

Returns the square root of a. Faster then NthRoot.

Parameters:

  • double a : The number to get it's square root

Example:

Algebra.SquareRoot(16)
The result is 4


NthRoot(double a, double n)

Returns the n-th root of a.

Parameters:

  • double a : The number to get it's n-th root
  • double n : The degree of the root

Example:

Algebra.NthRoot(27, 3)
The result is 3


IntPower(double b, int n)

Returns b to the n power

Parameters:

  • double b : The number to raise to the n power
  • double n : The power to raise b to

Example:

Algebra.IntPower(4, 3)
The result is 64


IntPower(Complex b, int n)

Returns b to the n power

Parameters:

  • double b : The complex number to raise to the n power
  • double n : The power to raise b to

Example:

Algebra.IntPower(new Complex(2, 3), 2)
The result is -5+12i