Skip to content

Math Extensions

Adrian Gabor edited this page Nov 20, 2021 · 19 revisions

AddExt

Description
Adds n number of integers to the target integer.

Parameters
add (params int[])

Usage

int a = 5;
int b = 3;
int c = a.AddExt(b);

AddExt

Description
Adds n number of doubles to the target double.

Parameters
add (params double[])

Usage

double a = 5.1;
double b = 3.8;
double c = a.AddExt(b);

AddExt

Description
Adds n number of decimals to the target double.

Parameters
add (params decimal[])

Usage

decimal a = 5.1M;
decimal b = 3.8M;
decimal c = a.AddExt(b);

SubtractExt

Description
Subtracts n number of integers to the target integer.

Parameters
sub (params int[])

Usage

int a = 5;
int b = 3;
int c = 1;
int d = a.SubtractExt(b, c);

SubtractExt

Description
Subtracts n number of doubles to the target integer.

Parameters
sub (params double[])

Usage

double a = 5.1;
double b = 3.8;
double c = 1.9;
double d = a.SubtractExt(b, c);

SubtractExt

Description
Subtracts n number of decimals to the target integer.

Parameters
sub (params decimal[])

Usage

decimal a = 5.1M;
decimal b = 3.8M;
decimal c = 1.9M;
decimal d = a.SubtractExt(b, c);

MultiplyExt

Description
Multiplies n number of integers to the target integer.

Parameters
mul (params int[])

Usage

int a = 5;
int b = 3;
int d = a.MultiplyExt(b);

MultiplyExt

Description
Multiplies n number of doubles to the target integer.

Parameters
mul (params double[])

Usage

double a = 5.1;
double b = 3.8;
double c = a.MultiplyExt(b);

MultiplyExt

Description
Multiplies n number of decimals to the target integer.

Parameters
mul (params decimal[])

Usage

decimal a = 5.1M;
decimal b = 3.8M;
decimal c = a.MultiplyExt(b);

DivideExt

Description
Divides n number of integers to the target integer.
Return is int representing the number of times can be divided into or the floor.

Parameters
div (params int[])

Usage

int a = 5;
int b = 3;
int d = a.DivideExt(b);

DivideExt

Description
Divides n number of doubles to the target integer.
Return is double representing the number of times can be divided into or the floor.

Parameters
div (params double[])

Usage

double a = 5.1;
double b = 3.8;
double d = a.DivideExt(b);

DivideExt

Description
Divides n number of decimals to the target integer.
Return is decimal representing the number of times can be divided into or the floor.

Parameters
div (params decimal[])

Usage

decimal a = 5.1M;
decimal b = 3.8M;
decimal d = a.DivideExt(b);

AbsExt

Description
Maps to Math.Abs
Absolute Value.
Types available: decimal, double, short, int, long, sbyte, float

Parameters
None

Usage

float f = float.MinValue;
float absVal = f.AbsExt();

AcosExt

Description
Maps to Math.Acos
MSDN: "Returns the angle whose cosine is the specified number."

Parameters
None

Usage

double dou = double.MaxValue;
double angleCos = dou.AcosExt();

AsinExt

Description
Maps to Math.Asin
MSDN: "Returns the angle whose sine is the specified number."

Parameters
None

Usage

double dou = double.MaxValue;
double angleSine = dou.AsinExt();

AtanExt

Description
Maps to Math.Atan
MSDN: "Returns the angle whose tangent is the specified number."

Parameters
None

Usage

double dou = double.MaxValue;
double angleTan = dou.AtanExt();

Atan2Ext

Description
Maps to Math.Atan2
MSDN: "Returns the angle whose tangent is the quotient of two specified numbers."

Parameters
x (double)

Usage

double x = double.MaxValue;
double y = double.MinValue;
double angleTan2 = x.Atan2Ext(y);

CeilingExt

Description
Maps to Math.Ceiling
Returns a double or decimal that is the smallest integral value larger than the source double or decimal.

Parameters
None

Usage

double dou = 123.456;
double ceiling = dou.CeilingExt();

CosExt

Description
Maps to Math.Cos
Returns the cosine of the source angle.

Parameters
None

Usage

double dou = 123.456;
double cosine = dou.CosExt();

CoshExt

Description
Maps to Math.Cosh
Returns the hyperbolic cosine of the source angle.

Parameters
None

Usage

double dou = 123.456;
double hyperbolicCosine = dou.CoshExt();

ExpExt

Description
Maps to Math.Exp
Returns e raised to the power of the source double. e represents Euler's number.

Parameters
None

Usage

double dou = 123.456;
double e = dou.ExpExt();

FloorExt

Description
Maps to Math.Floor
Returns a double or decimal that is the first integral value larger than the source double or decimal.

Parameters
None

Usage

decimal dec = 123.456M;
decimal flr = dec.FloorExt();

IEEERemainderExt

Description
Maps to Math.IEEERemainder
Returns the remainder resulting from the division of x/y.

Parameters
y (double)

Usage

double x = 9;
double y = 7;
double z ieeeRemainder = x.IEEERemainderExt(y);

LogExt

Description
Maps to Math.Log
Returns the natural logarithm of the source number.

Parameters
None

Usage

double dou = 123.456;
double log = dou.LogExt();

LogExt (New Base)

Description
Maps to Math.Log
Returns the logarithm of the source number in a new base.

Parameters
newBase (double)

Usage

double dou = 123.456;
double newBase = 5;
double log = dou.LogExt(newBase);

Log10Ext

Description
Maps to Math.Log10
Returns base 10 logarith of the source number.

Parameters
none

Usage

double dou = 123.456;
double log10 = dou.Log10Ext();

MaxExt

Description
Maps to Math.Max
Returns the larger of the source number and the parameter number.
Types available: int, double, decimal, byte, sbyte, uint, ushort, float, long, ulong, short

Parameters
val2 (see available types)

Usage

long val1 = 100;
long val2 = 101;
long maxOfl1Orl2 = val1.MaxExt(val2);'

MinExt

Description
Maps to Math.Min
Returns the smaller of the source number and the parameter number.
Types available: int, double, decimal, byte, sbyte, uint, ushort, float, long, ulong, short

Parameters
val2 (see available types)

Usage

double val1 = 100.1;
double val2 = 50.2;
double minOfl1Orl2 = val1.MinExt(val2);'

PowExt

Description
Maps to Math.Pow
Raises the source double to the power of the parameter double.

Parameters
y (double)

Usage

double x = 9;
double y = 7;
double powxy = x.PowExt(y);'

RoundExt

Description
Maps to Math.Round
Rounds to the nearest integral value. Two overloads available that allow you to pass in an integer that sets the number of decimal places to round and MidPointRounding parameter that determines whether rounding up or down if the value is in the middle. Types available: double, decimal

Parameters
None - Base decimals (int) - Overload mode (MidpointRounding) - Overload

Usage

decimal dec = 12.345M;
MidpointRounding mr = MidpointRounding.AwayFromZero;
int decimals = 2;

decimal dec2 = dou.RoundExt();
decimal dec3 = dou.RoundExt(decimals);
decimal dec4 = dou.RoundExt(mr);
decimal dec5 = dou.RoundExt(decimals, mr);

SignExt

Description
Maps to Math.Sign
Returns -1 if number is negative, 1 if the number is positive, or 0 if the number is 0.
Types available: int, float, long, double, decimal, sbyte, short

Parameters
None

Usage

short sh = 100;
int sign = sh.SignExt();

SinExt

Description
Maps to Math.Sin
Returns the sine of the source double (angle).

Parameters
None

Usage

double d = 123.456;
double sine = d.SinExt();

SinhExt

Description
Maps to Math.Sinh
Returns the hyperbolic sine of the source double (angle).

Parameters
None

Usage

double d = 123.456;
double sineH = d.SinhExt();

SqrtExt

Description
Maps to Math.Sqrt
Returns the square root of the source double.

Parameters
None

Usage

double d = 100;
if (d.SqrtExt() == 100) { ... }

TanExt

Description
Maps to Math.Tan
Returns the tangent of the source double (angle).

Parameters
None

Usage

double d = 123.456;
double tangent = d.TanExt();

TanhExt

Description
Maps to Math.Tanh
Returns the hyperbolic tangent of the source double (angle).

Parameters
None

Usage

double d = 123.456;
double tangentH = d.TanhExt();

TruncateExt

Description
Maps to Math.Truncate
Returns the integer part of the source decimal (the part to the left of the decimal point).
Types available: double, decimal

Parameters
None

Usage

double d = 123.456;
double truncated = d.TruncateExt();

AreaOfCircleExt

Description
Calculates the area of a circle when the extended number is the radius.
Types supported: int, double

Parameters
None

Usage

double radius = 5.2;
double areaOfCircle = AreaOfCircleExt();

AreaOfTriangleExt

Description
Calculates the area of a triangle wher the extended double is the base, and the double parameter is the height.
Types supported: int, double

Parameters
height (int) OR height (double)

Usage

double theBase = 10;
double height = 5;
double areaOfTriangle = theBase.AreaOfTriangleExt(height);

AreaOfRectangleExt

Description
Calculates the area of a rectangle where the extended number is the length and the parameter is the width, or reversed.
Types supported: int, double

Parameters
length (int) OR width (int)

Usage

int length = 3; // (or double length = 3.5;)
int width = 4; // (or double width = 4.3;)
double areaOfRectangle = length.AreaOfRectangleExt(width);
double areaOfRectangle = width.AreaOfRectangleExt(length);

CircumferenceOfCircleExt

Description
Calculates the circumference of a circle when the extended number is the radius.
Types supported: int, double

Parameters
None

Usage

double radius = 3.5;
double circumference = radius.CircumferenceOfCircleExt();

ArcLengthExt

Description
Calculates the length of a circle arc where the extended value is the radius and the paramater is the central angle.
Types supported: int, double

Parameters
centralAngle (int) OR centralAngle (double)

Usage

double radius = 5;
double centralAngle = 75;
double arc = radius.ArcLengthExt(centralAngle);

HypotenuseExt

Description
Calculates the hypotenus of a triangle where leg1 is the extended value and leg2 is the parameter.
Types supported: int, double

Parameters
leg2 (int) OR leg2 (double)

Usage

double a = 5;
double b = 4.5;
double hypotenuse = a.HypotenuseExt(b);

VolumeOfCylinderExt

Description
Calculates the volume of a cylinder.
Extended value is the radius of the base and parameter is the height of the cylinder.
Types supported: int, double

Parameters
height (int) OR height (double)

Usage

int radius = 2;
int height = 6;
double volumeCylinder = radius.VolumeOfCylinderExt(height);

OR

double radius = 2.5;
double height = 6.3;
double volumeCylinder = radius.VolumeOfCylinderExt(height);

VolumeOfSphereExt

Description
Calculates the volume of a sphere where the extended value is the radius.
Types supported: int, double

Parameters
None

Usage

int radius = 2;
double volumeSphere = radius.VolumeOfSphereExt();

OR

double radius = 2.5;
double volumeSphere = radius.VolumeOfSphereExt();

VolumeOfConeExt

Description
Calculates the volume of a cone where the entended number is the radius and the paramater is the height.
Types supported: int, double

Parameters
height (int) OR height (double)

Usage

int radius = 2;
int height = 6;
double volumeCone = radius.VolumeOfConeExt();

OR

double radius = 2.5;
double height = 6.3;
double volumeCone = radius.VolumeOfConeExt();

AreaOfTrapezoidExt

Description
Calculates the area of a trapezoid where the extended value is the height and paramaters a & b are the bases.
Types supported: int, double

Parameters
a (int) OR a (double)
b (int) OR b (double)

Usage

int a = 3;
int b = 4;
int height = 5;
double areaTrapezoid = height.AreaOfTrapezoidExt(a, b);

OR

double a = 3.2;
double b = 4.5;
double height = 5.1;
double areaTrapezoid = height.AreaOfTrapezoidExt(a, b);

VolumeOfPyramidExt

Description
Returns the volume of a pyramid where the extended value is one side of the pyramid and the parameters are the other side and the height.
Also works when the width is the extended value and the length is the first parameter.
Types supported: int, double

Parameters
side2 (int) OR side2 (double)
side3 (int) OR side3 (double)

Usage

int length = 3;
int width = 4;
int height = 5;
double volPyramid = length.VolumeOfPyramidExt(width, height);

OR

double length = 3.2;
double width = 4.5;
double height = 5.1;
double volPyramid = length.VolumeOfPyramidExt(width, height);

VolumeOfCubeExt

Description
Calculates the edge of a cube.
Types supported: int, double

Parameters
None

Usage

int edge = 3;
double volCube = edge.VolumeOfCubeExt();

OR

double edge = 3.2;
double volCube = edge.VolumeOfCubeExt();

AreaOfCylinderExt

Description
Returns the area of a cylinder where the extended value is the radius and the parameter is the height.
Types supported: int, double

Parameters
height (int) OR height (double)

Usage

int radius = 5;
int height = 7;
double areaCylinder = radius.AreaOfCylinderExt(height);

OR

double radius = 5.75;
double height = 7.5;
double areaCylinder = radius.AreaOfCylinderExt(height);
Clone this wiki locally