Class MathExtensions
Provides extension methods for trigonometric, logarithmic, and other common mathematical functions.
public static class MathExtensions
- Inheritance
-
MathExtensions
- Inherited Members
Methods
Abs(decimal)
Returns the absolute value of a decimal number.
public static decimal Abs(this decimal value)
Parameters
Returns
Abs(double)
Returns the absolute value of a double-precision floating-point number.
public static double Abs(this double value)
Parameters
Returns
Abs(short)
Returns the absolute value of a 16-bit signed integer.
public static short Abs(this short value)
Parameters
Returns
Exceptions
- OverflowException
value equals MinValue.
Abs(int)
Returns the absolute value of a 32-bit signed integer.
public static int Abs(this int value)
Parameters
Returns
Exceptions
- OverflowException
value equals MinValue.
Abs(long)
Returns the absolute value of a 64-bit signed integer.
public static long Abs(this long value)
Parameters
Returns
Exceptions
- OverflowException
value equals MinValue.
Abs(sbyte)
Returns the absolute value of an 8-bit signed integer.
public static sbyte Abs(this sbyte value)
Parameters
Returns
Exceptions
- OverflowException
value equals MinValue.
Abs(float)
Returns the absolute value of a single-precision floating-point number.
public static float Abs(this float value)
Parameters
Returns
Acos(double)
Returns the angle whose cosine is the specified number.
public static double Acos(this double value)
Parameters
value
doubleA number representing a cosine, where -1 ≤ value ≤ 1.
Returns
Asin(double)
Returns the angle whose sine is the specified number.
public static double Asin(this double value)
Parameters
value
doubleA number representing a sine, where -1 ≤ value ≤ 1.
Returns
- double
An angle, θ, measured in radians, such that -π/2 ≤ θ ≤ π/2 -or- NaN if value < -1 or value > 1.
AtLeast(byte, byte)
Returns the larger of two 8-bit unsigned integers.
public static byte AtLeast(this byte a, byte b)
Parameters
a
byteThe first of two 8-bit unsigned integers to compare.
b
byteThe second of two 8-bit unsigned integers to compare.
Returns
- byte
Parameter a or b, whichever is larger.
AtLeast(decimal, decimal)
Returns the larger of two decimal numbers.
public static decimal AtLeast(this decimal a, decimal b)
Parameters
a
decimalThe first of two decimal numbers to compare.
b
decimalThe second of two decimal numbers to compare.
Returns
- decimal
Parameter a or b, whichever is larger.
AtLeast(double, double)
Returns the larger of two double-precision floating-point numbers.
public static double AtLeast(this double a, double b)
Parameters
a
doubleThe first of two double-precision floating-point numbers to compare.
b
doubleThe second of two double-precision floating-point numbers to compare.
Returns
- double
Parameter a or b, whichever is larger. If a, b, or both a and b are equal to NaN, NaN is returned.
AtLeast(short, short)
Returns the larger of two 16-bit signed integers.
public static short AtLeast(this short a, short b)
Parameters
a
shortThe first of two 16-bit signed integers to compare.
b
shortThe second of two 16-bit signed integers to compare.
Returns
- short
Parameter a or b, whichever is larger.
AtLeast(int, int)
Returns the larger of two 32-bit signed integers.
public static int AtLeast(this int a, int b)
Parameters
a
intThe first of two 32-bit signed integers to compare.
b
intThe second of two 32-bit signed integers to compare.
Returns
- int
Parameter a or b, whichever is larger.
AtLeast(long, long)
Returns the larger of two 64-bit signed integers.
public static long AtLeast(this long a, long b)
Parameters
a
longThe first of two 64-bit signed integers to compare.
b
longThe second of two 64-bit signed integers to compare.
Returns
- long
Parameter a or b, whichever is larger.
AtLeast(sbyte, sbyte)
Returns the larger of two 8-bit signed integers.
public static sbyte AtLeast(this sbyte a, sbyte b)
Parameters
a
sbyteThe first of two 8-bit unsigned integers to compare.
b
sbyteThe second of two 8-bit unsigned integers to compare.
Returns
- sbyte
Parameter a or b, whichever is larger.
AtLeast(float, float)
Returns the larger of two single-precision floating-point numbers.
public static float AtLeast(this float a, float b)
Parameters
a
floatThe first of two single-precision floating-point numbers to compare.
b
floatThe second of two single-precision floating-point numbers to compare.
Returns
- float
Parameter a or b, whichever is larger. If a, or b, or both a and b are equal to NaN, NaN is returned.
AtLeast(ushort, ushort)
Returns the larger of two 16-bit unsigned integers.
public static ushort AtLeast(this ushort a, ushort b)
Parameters
a
ushortThe first of two 16-bit unsigned integers to compare.
b
ushortThe second of two 16-bit unsigned integers to compare.
Returns
- ushort
Parameter a or b, whichever is larger.
AtLeast(uint, uint)
Returns the larger of two 32-bit unsigned integers.
public static uint AtLeast(this uint a, uint b)
Parameters
a
uintThe first of two 32-bit unsigned integers to compare.
b
uintThe second of two 32-bit unsigned integers to compare.
Returns
- uint
Parameter a or b, whichever is larger.
AtLeast(ulong, ulong)
Returns the larger of two 64-bit unsigned integers.
public static ulong AtLeast(this ulong a, ulong b)
Parameters
a
ulongThe first of two 64-bit unsigned integers to compare.
b
ulongThe second of two 64-bit unsigned integers to compare.
Returns
- ulong
Parameter a or b, whichever is larger.
AtMost(byte, byte)
Returns the smaller of two 8-bit unsigned integers.
public static byte AtMost(this byte a, byte b)
Parameters
a
byteThe first of two 8-bit unsigned integers to compare.
b
byteThe second of two 8-bit unsigned integers to compare.
Returns
- byte
Parameter a or b, whichever is smaller.
AtMost(decimal, decimal)
Returns the smaller of two decimal numbers.
public static decimal AtMost(this decimal a, decimal b)
Parameters
a
decimalThe first of two decimal numbers to compare.
b
decimalThe second of two decimal numbers to compare.
Returns
- decimal
Parameter a or b, whichever is smaller.
AtMost(double, double)
Returns the smaller of two double-precision floating-point numbers.
public static double AtMost(this double a, double b)
Parameters
a
doubleThe first of two double-precision floating-point numbers to compare.
b
doubleThe second of two double-precision floating-point numbers to compare.
Returns
- double
Parameter a or b, whichever is smaller. If a, b, or both a and b are equal to NaN, NaN is returned.
AtMost(short, short)
Returns the smaller of two 16-bit signed integers.
public static short AtMost(this short a, short b)
Parameters
a
shortThe first of two 16-bit signed integers to compare.
b
shortThe second of two 16-bit signed integers to compare.
Returns
- short
Parameter a or b, whichever is smaller.
AtMost(int, int)
Returns the smaller of two 32-bit signed integers.
public static int AtMost(this int a, int b)
Parameters
a
intThe first of two 32-bit signed integers to compare.
b
intThe second of two 32-bit signed integers to compare.
Returns
- int
Parameter a or b, whichever is smaller.
AtMost(long, long)
Returns the smaller of two 64-bit signed integers.
public static long AtMost(this long a, long b)
Parameters
a
longThe first of two 64-bit signed integers to compare.
b
longThe second of two 64-bit signed integers to compare.
Returns
- long
Parameter a or b, whichever is smaller.
AtMost(sbyte, sbyte)
Returns the smaller of two 8-bit signed integers.
public static sbyte AtMost(this sbyte a, sbyte b)
Parameters
a
sbyteThe first of two 8-bit signed integers to compare.
b
sbyteThe second of two 8-bit signed integers to compare.
Returns
- sbyte
Parameter a or b, whichever is smaller.
AtMost(float, float)
Returns the smaller of two single-precision floating-point numbers.
public static float AtMost(this float a, float b)
Parameters
a
floatThe first of two single-precision floating-point numbers to compare.
b
floatThe second of two single-precision floating-point numbers to compare.
Returns
- float
Parameter a or b, whichever is smaller. If a, b, or both a and b are equal to NaN, NaN is returned.
AtMost(ushort, ushort)
Returns the smaller of two 16-bit unsigned integers.
public static ushort AtMost(this ushort a, ushort b)
Parameters
a
ushortThe first of two 16-bit unsigned integers to compare.
b
ushortThe second of two 16-bit unsigned integers to compare.
Returns
- ushort
Parameter a or b, whichever is smaller.
AtMost(uint, uint)
Returns the smaller of two 32-bit unsigned integers.
public static uint AtMost(this uint a, uint b)
Parameters
a
uintThe first of two 32-bit unsigned integers to compare.
b
uintThe second of two 32-bit unsigned integers to compare.
Returns
- uint
Parameter a or b, whichever is smaller.
AtMost(ulong, ulong)
Returns the smaller of two 64-bit unsigned integers.
public static ulong AtMost(this ulong a, ulong b)
Parameters
a
ulongThe first of two 64-bit unsigned integers to compare.
b
ulongThe second of two 64-bit unsigned integers to compare.
Returns
- ulong
Parameter a or b, whichever is smaller.
Atan(double)
Returns the angle whose tangent is the specified number.
public static double Atan(this double value)
Parameters
value
doubleA number representing a tangent.
Returns
- double
An angle, θ, measured in radians, such that -π/2 ≤ θ ≤ π/2 -or- NaN if value equals NaN, -π/2 rounded to double precision (-1.5707963267949) if value equals NegativeInfinity, or π/2 rounded to double precision (1.5707963267949) if value equals PositiveInfinity.
Atan2(double, double)
Returns the angle whose tangent is the quotient of two specified numbers.
public static double Atan2(this double y, double x)
Parameters
Returns
- double
An angle, θ, measured in radians, such that -π ≤ θ ≤ π, and tan(θ) = y / x, where (x, y) is a point in the Cartesian plane. See Atan2(double, double) for details.
BigMul(int, int)
Produces the full product of two 32-bit numbers.
public static long BigMul(this int a, int b)
Parameters
Returns
Ceiling(decimal)
Returns the smallest integer greater than or equal to the specified decimal number.
public static decimal Ceiling(this decimal value)
Parameters
value
decimalA decimal number.
Returns
- decimal
The smallest integer greater than or equal to value.
Ceiling(double)
Returns the smallest integer greater than or equal to the specified double-precision floating-point number.
public static double Ceiling(this double value)
Parameters
value
doubleA double-precision floating-point number.
Returns
- double
The smallest integer greater than or equal to value. If value is equal to NaN, NegativeInfinity, or PositiveInfinity, that value is returned.
Clamp(byte, byte, byte)
Returns the value constrained inclusively between two 8-bit unsigned integers.
public static byte Clamp(this byte value, byte a, byte b)
Parameters
value
byteThe value to restrict between a and b.
a
byteThe first of two 8-bit unsigned integers to compare.
b
byteThe second of two 8-bit unsigned integers to compare.
Returns
- byte
A value between a and b inclusively.
Clamp(decimal, decimal, decimal)
Returns the value constrained inclusively between two decimal numbers.
public static decimal Clamp(this decimal value, decimal a, decimal b)
Parameters
value
decimalThe value to restrict between a and b.
a
decimalThe first of two decimal numbers to compare.
b
decimalThe second of two decimal numbers to compare.
Returns
- decimal
A value between a and b inclusively.
Clamp(double, double, double)
Returns the value constrained inclusively between two double-precision floating-point numbers.
public static double Clamp(this double value, double a, double b)
Parameters
value
doubleThe value to restrict between a and b.
a
doubleThe first of two double-precision floating-point numbers to compare.
b
doubleThe second of two double-precision floating-point numbers to compare.
Returns
- double
A value between a and b inclusively. If a, b, or both a and b are equal to NaN, NaN is returned.
Clamp(short, short, short)
Returns the value constrained inclusively between two 16-bit signed integers.
public static short Clamp(this short value, short a, short b)
Parameters
value
shortThe value to restrict between a and b.
a
shortThe first of two 16-bit signed integers to compare.
b
shortThe second of two 16-bit signed integers to compare.
Returns
- short
A value between a and b inclusively.
Clamp(int, int, int)
Returns the value constrained inclusively between two 32-bit signed integers.
public static int Clamp(this int value, int a, int b)
Parameters
value
intThe value to restrict between a and b.
a
intThe first of two 32-bit signed integers to compare.
b
intThe second of two 32-bit signed integers to compare.
Returns
- int
A value between a and b inclusively.
Clamp(long, long, long)
Returns the value constrained inclusively between two 64-bit signed integers.
public static long Clamp(this long value, long a, long b)
Parameters
value
longThe value to restrict between a and b.
a
longThe first of two 64-bit signed integers to compare.
b
longThe second of two 64-bit signed integers to compare.
Returns
- long
A value between a and b inclusively.
Clamp(sbyte, sbyte, sbyte)
Returns the value constrained inclusively between two 8-bit signed integers.
public static sbyte Clamp(this sbyte value, sbyte a, sbyte b)
Parameters
value
sbyteThe value to restrict between a and b.
a
sbyteThe first of two 8-bit signed integers to compare.
b
sbyteThe second of two 8-bit signed integers to compare.
Returns
- sbyte
A value between a and b inclusively.
Clamp(float, float, float)
Returns the value constrained inclusively between two single-precision floating-point numbers.
public static float Clamp(this float value, float a, float b)
Parameters
value
floatThe value to restrict between a and b.
a
floatThe first of two single-precision floating-point numbers to compare.
b
floatThe second of two single-precision floating-point numbers to compare.
Returns
- float
A value between a and b inclusively. If a, b, or both a and b are equal to NaN, NaN is returned.
Clamp(ushort, ushort, ushort)
Returns the value constrained inclusively between two 16-bit unsigned integers.
public static ushort Clamp(this ushort value, ushort a, ushort b)
Parameters
value
ushortThe value to restrict between a and b.
a
ushortThe first of two 16-bit unsigned integers to compare.
b
ushortThe second of two 16-bit unsigned integers to compare.
Returns
- ushort
A value between a and b inclusively.
Clamp(uint, uint, uint)
Returns the value constrained inclusively between two 32-bit unsigned integers.
public static uint Clamp(this uint value, uint a, uint b)
Parameters
value
uintThe value to restrict between a and b.
a
uintThe first of two 32-bit unsigned integers to compare.
b
uintThe second of two 32-bit unsigned integers to compare.
Returns
- uint
A value between a and b inclusively.
Clamp(ulong, ulong, ulong)
Returns the value constrained inclusively between two 64-bit unsigned integers.
public static ulong Clamp(this ulong value, ulong a, ulong b)
Parameters
value
ulongThe value to restrict between a and b.
a
ulongThe first of two 64-bit unsigned integers to compare.
b
ulongThe second of two 64-bit unsigned integers to compare.
Returns
- ulong
A value between a and b inclusively.
Cos(double)
Returns the cosine of the specified angle.
public static double Cos(this double angle)
Parameters
angle
doubleAn angle, measured in radians.
Returns
- double
The cosine of angle.
Cosh(double)
Returns the hyperbolic cosine of the specified angle.
public static double Cosh(this double angle)
Parameters
angle
doubleAn angle, measured in radians.
Returns
- double
The hyperbolic cosine of angle. If angle is equal to NegativeInfinity or PositiveInfinity, PositiveInfinity is returned. If angle is equal to NaN, NaN is returned.
DivRem(int, int, out int)
Calculates the quotient of two 32-bit signed integers and also returns the remainder in an output parameter.
public static int DivRem(this int a, int b, out int result)
Parameters
a
intThe int that contains the dividend.
b
intThe int that contains the divisor.
result
intThe int that receives the remainder.
Returns
Exceptions
- DivideByZeroException
b is zero.
DivRem(long, long, out long)
Calculates the quotient of two 64-bit signed integers and also returns the remainder in an output parameter.
public static long DivRem(this long a, long b, out long result)
Parameters
a
longThe long that contains the dividend.
b
longThe long that contains the divisor.
result
longThe long that receives the remainder.
Returns
Exceptions
- DivideByZeroException
b is zero.
Exp(double)
Returns e raised to the specified power.
public static double Exp(this double value)
Parameters
value
doubleA number specifying a power.
Returns
- double
The number e raised to the power value. If value equals NaN or PositiveInfinity, that value is returned. If value equals NegativeInfinity, 0 is returned.
Floor(decimal)
Returns the largest integer less than or equal to the specified decimal number.
public static decimal Floor(this decimal value)
Parameters
value
decimalA decimal number.
Returns
- decimal
The largest integer less than or equal to value.
Floor(double)
Returns the largest integer less than or equal to the specified double-precision floating-point number.
public static double Floor(this double value)
Parameters
value
doubleA double-precision floating-point number.
Returns
- double
The largest integer less than or equal to value. If value is equal to NaN, NegativeInfinity, or PositiveInfinity, that value is returned.
GetValueOrDefault(double)
Retrieves the value of the specified number, or zero if it's not a number (NaN).
public static double GetValueOrDefault(this double value)
Parameters
value
doubleA double-precision floating-point number.
Returns
GetValueOrDefault(double, double)
Retrieves the value of the specified number, or the specified default value if it's not a number (NaN).
public static double GetValueOrDefault(this double value, double defaultValue)
Parameters
value
doubleA double-precision floating-point number.
defaultValue
doubleThe value to return if IsNaN(double) returns true.
Returns
- double
The value of the
value
parameter if it doesn't evaluate to NaN; otherwise, thedefaultValue
parameter.
GetValueOrDefault(float)
Retrieves the value of the specified number, or zero if it's not a number (NaN).
public static float GetValueOrDefault(this float value)
Parameters
value
floatA single-precision floating-point number.
Returns
GetValueOrDefault(float, float)
Retrieves the value of the specified number, or the specified default value if it's not a number (NaN).
public static float GetValueOrDefault(this float value, float defaultValue)
Parameters
value
floatA single-precision floating-point number.
defaultValue
floatThe value to return if IsNaN(double) returns true.
Returns
- float
The value of the
value
parameter if it doesn't evaluate to NaN; otherwise, thedefaultValue
parameter.
IEEERemainder(double, double)
Returns the remainder resulting from the division of a specified number by another specified number.
public static double IEEERemainder(this double x, double y)
Parameters
Returns
- double
A number equal to x - (y Q), where Q is the quotient of x / y rounded to the nearest integer (if x / y falls halfway between two integers, the even integer is returned).If x - (y Q) is zero, the value +0 is returned if x is positive, or -0 if x is negative. If y = 0, NaN (Not-A-Number) is returned.
IsBetween(byte, byte, byte)
Determines whether an 8-bit unsigned integer is inclusively between two values.
public static bool IsBetween(this byte value, byte a, byte b)
Parameters
value
byteAn 8-bit unsigned integer to compare.
a
byteThe first bound to compare value against.
b
byteThe second bound to compare value against.
Returns
- bool
A boolean representing whether value is inclusively between a and b.
IsBetween(decimal, decimal, decimal)
Determines whether a decimal value is inclusively between two values.
public static bool IsBetween(this decimal value, decimal a, decimal b)
Parameters
value
decimalA decimal value to compare.
a
decimalThe first bound to compare value against.
b
decimalThe second bound to compare value against.
Returns
- bool
A boolean representing whether value is inclusively between a and b.
IsBetween(double, double, double)
Determines whether a double-precision floating-point value is inclusively between two values.
public static bool IsBetween(this double value, double a, double b)
Parameters
value
doubleA double-precision floating-point value to compare.
a
doubleThe first bound to compare value against.
b
doubleThe second bound to compare value against.
Returns
- bool
A boolean representing whether value is inclusively between a and b.
IsBetween(short, short, short)
Determines whether a 16-bit signed integer is inclusively between two values.
public static bool IsBetween(this short value, short a, short b)
Parameters
value
shortA 16-bit signed integer to compare.
a
shortThe first bound to compare value against.
b
shortThe second bound to compare value against.
Returns
- bool
A boolean representing whether value is inclusively between a and b.
IsBetween(int, int, int)
Determines whether a 32-bit signed integer is inclusively between two values.
public static bool IsBetween(this int value, int a, int b)
Parameters
value
intA 32-bit signed integer to compare.
a
intThe first bound to compare value against.
b
intThe second bound to compare value against.
Returns
- bool
A boolean representing whether value is inclusively between a and b.
IsBetween(long, long, long)
Determines whether a 64-bit signed integer is inclusively between two values.
public static bool IsBetween(this long value, long a, long b)
Parameters
value
longA 64-bit signed integer to compare.
a
longThe first bound to compare value against.
b
longThe second bound to compare value against.
Returns
- bool
A boolean representing whether value is inclusively between a and b.
IsBetween(float, float, float)
Determines whether a single-precision floating-point value is inclusively between two values.
public static bool IsBetween(this float value, float a, float b)
Parameters
value
floatA double-precision floating-point value to compare.
a
floatThe first bound to compare value against.
b
floatThe second bound to compare value against.
Returns
- bool
A boolean representing whether value is inclusively between a and b.
IsNaN(double)
Returns a value indicating whether the specified number evaluates to a value that is not a number (NaN).
public static bool IsNaN(this double value)
Parameters
value
doubleA double-precision floating-point number.
Returns
IsNaN(float)
Returns a value indicating whether the specified number evaluates to not a number (NaN).
public static bool IsNaN(this float value)
Parameters
value
float
Returns
Log(double)
Returns the natural (base e) logarithm of a specified number.
public static double Log(this double value)
Parameters
value
doubleA number whose logarithm is to be found.
Returns
- double
See Log(double) for details.
Log(double, double)
Returns the logarithm of a specified number in a specified base.
public static double Log(this double value, double newBase)
Parameters
Returns
- double
See Log(double) for details.
Log10(double)
Returns the base 10 logarithm of a specified number.
public static double Log10(this double value)
Parameters
value
doubleA number whose logarithm is to be found.
Returns
- double
See Log10(double) for details.
Pow(double, double)
Returns a specified number raised to the specified power.
public static double Pow(this double x, double y)
Parameters
x
doubleA double-precision floating-point number to be raised to a power.
y
doubleA double-precision floating-point number that specifies a power.
Returns
- double
The number x raised to the power y. See Pow(double, double) for details.
Round(decimal)
Rounds a decimal value to the nearest integer.
public static decimal Round(this decimal value)
Parameters
value
decimalA decimal number to be rounded.
Returns
- decimal
The integer nearest parameter value. If value is halfway between two integers, one of which is even and the other odd, then the even number is returned.
Exceptions
- OverflowException
The result is outside the range of a decimal.
Round(decimal, int)
Rounds a decimal value to a specified precision.
public static decimal Round(this decimal value, int decimals)
Parameters
value
decimalA decimal number to be rounded.
decimals
intThe number of significant decimal places (precision) in the return value.
Returns
- decimal
The number nearest value with a precision equal to decimals. If value is halfway between two numbers, one of which is even and the other odd, then the even number is returned. If the precision of value is less than decimals, then value is returned unchanged.
Exceptions
- OverflowException
The result is outside the range of a decimal.
- ArgumentOutOfRangeException
decimals is less than 0 or greater than 28.
Round(decimal, int, MidpointRounding)
Rounds a decimal value to a specified precision. A parameter specifies how to round the value if it is midway between two other numbers.
public static decimal Round(this decimal value, int decimals, MidpointRounding mode)
Parameters
value
decimalA decimal number to be rounded.
decimals
intThe number of significant decimal places (precision) in the return value.
mode
MidpointRoundingSpecification for how to round value if it is midway between two other numbers.
Returns
- decimal
The number nearest value with a precision equal to decimals. If value is halfway between two numbers, one of which is even and the other odd, then mode determines which of the two numbers is returned. If the precision of value is less than decimals, then value is returned unchanged.
Exceptions
- OverflowException
The result is outside the range of a decimal.
- ArgumentOutOfRangeException
decimals is less than 0 or greater than 28.
- ArgumentException
mode is not a valid value of MidpointRounding.
Round(decimal, MidpointRounding)
Rounds a decimal value to the nearest integer. A parameter specifies how to round the value if it is midway between two other numbers.
public static decimal Round(this decimal value, MidpointRounding mode)
Parameters
value
decimalA decimal number to be rounded.
mode
MidpointRoundingSpecification for how to round value if it is midway between two other numbers.
Returns
- decimal
The integer nearest value. If value is halfway between two numbers, one of which is even and the other odd, then mode determines which of the two is returned.
Exceptions
- OverflowException
The result is outside the range of a decimal.
- ArgumentException
mode is not a valid value of MidpointRounding.
Round(double)
Rounds a double-precision floating-point value to the nearest integer.
public static double Round(this double value)
Parameters
value
doubleA double-precision floating-point number to be rounded.
Returns
- double
The integer nearest value. If value is halfway between two integers, one of which is even and the other odd, then the even number is returned.
Round(double, int)
Rounds a double-precision floating-point value to the specified precision.
public static double Round(this double value, int digits)
Parameters
value
doubleA double-precision floating-point number to be rounded.
digits
intThe number of significant digits (precision) in the return value.
Returns
- double
The number nearest value with a precision equal to digits. If value is halfway between two numbers, one of which is even and the other odd, then the even number is returned. If the precision of value is less than digits, then value is returned unchanged.
Exceptions
- ArgumentOutOfRangeException
digits is less than 0 or greater than 15.
Round(double, int, MidpointRounding)
Rounds a double-precision floating-point value to the specified precision. A parameter specifies how to round the value if it is midway between two other numbers.
public static double Round(this double value, int digits, MidpointRounding mode)
Parameters
value
doubleA double-precision floating-point number to be rounded.
digits
intThe number of significant digits (precision) in the return value.
mode
MidpointRoundingSpecification for how to round value if it is midway between two other numbers.
Returns
- double
The number nearest value with a precision equal to digits. If value is halfway between two numbers, one of which is even and the other odd, then the mode parameter determines which number is returned. If the precision of value is less than digits, then value is returned unchanged.
Exceptions
- ArgumentOutOfRangeException
digits is less than 0 or greater than 15.
- ArgumentException
mode is not a valid value of MidpointRounding.
Round(double, MidpointRounding)
Rounds a double-precision floating-point value to the nearest integer. A parameter specifies how to round the value if it is midway between two other numbers.
public static double Round(this double value, MidpointRounding mode)
Parameters
value
doubleA double-precision floating-point number to be rounded.
mode
MidpointRoundingSpecification for how to round value if it is midway between two other numbers.
Returns
- double
The integer nearest value. If value is halfway between two integers, one of which is even and the other odd, then mode determines which of the two is returned.
Exceptions
- ArgumentException
mode is not a valid value of MidpointRounding.
RoundDown(byte)
Rounds an 8-bit unsigned integer to the previous integer.
public static byte RoundDown(this byte value)
Parameters
value
byteAn 8-bit unsigned integer to be rounded.
Returns
- byte
The nearest integer that is less than or equal to value.
RoundDown(byte, byte)
Rounds an 8-bit unsigned integer to the previous multiple of the specified factor.
public static byte RoundDown(this byte value, byte factor)
Parameters
Returns
- byte
The nearest multiple of factor that is less than or equal to value.
RoundDown(decimal)
Rounds a decimal value to the previous integer.
public static decimal RoundDown(this decimal value)
Parameters
value
decimalA decimal number to be rounded.
Returns
- decimal
The nearest integer that is less than or equal to value.
RoundDown(decimal, decimal)
Rounds a decimal value to the previous multiple of the specified factor.
public static decimal RoundDown(this decimal value, decimal factor)
Parameters
Returns
- decimal
The nearest multiple of factor that is less than or equal to value.
RoundDown(double)
Rounds a double-precision floating-point value to the previous integer.
public static double RoundDown(this double value)
Parameters
value
doubleA double-precision floating-point number to be rounded.
Returns
- double
The nearest integer that is less than or equal to value.
RoundDown(double, double)
Rounds a double-precision floating-point value to the previous multiple of the specified factor.
public static double RoundDown(this double value, double factor)
Parameters
value
doubleA double-precision floating-point number to be rounded.
factor
doubleThe factor to round the value to.
Returns
- double
The nearest multiple of factor that is less than or equal to value.
RoundDown(short)
Rounds a 16-bit signed integer to the previous integer.
public static short RoundDown(this short value)
Parameters
value
shortA 16-bit signed integer to be rounded.
Returns
- short
The nearest integer that is less than or equal to value.
RoundDown(short, short)
Rounds a 16-bit signed integer to the previous multiple of the specified factor.
public static short RoundDown(this short value, short factor)
Parameters
Returns
- short
The nearest multiple of factor that is less than or equal to value.
RoundDown(int)
Rounds a 32-bit signed integer to the previous integer.
public static int RoundDown(this int value)
Parameters
value
intA 32-bit signed integer to be rounded.
Returns
- int
The nearest integer that is less than or equal to value.
RoundDown(int, int)
Rounds a 32-bit signed integer to the previous multiple of the specified factor.
public static int RoundDown(this int value, int factor)
Parameters
Returns
- int
The nearest multiple of factor that is less than or equal to value.
RoundDown(long)
Rounds a 64-bit signed integer to the previous integer.
public static long RoundDown(this long value)
Parameters
value
longA 64-bit signed integer to be rounded.
Returns
- long
The nearest integer that is less than or equal to value.
RoundDown(long, long)
Rounds a 64-bit signed integer to the previous multiple of the specified factor.
public static long RoundDown(this long value, long factor)
Parameters
Returns
- long
The nearest multiple of factor that is less than or equal to value.
RoundDown(float)
Rounds a single-precision floating-point value to the previous integer.
public static float RoundDown(this float value)
Parameters
value
floatA single-precision floating-point number to be rounded.
Returns
- float
The nearest integer that is less than or equal to value.
RoundDown(float, float)
Rounds a single-precision floating-point value to the previous multiple of the specified factor.
public static float RoundDown(this float value, float factor)
Parameters
value
floatA single-precision floating-point number to be rounded.
factor
floatThe factor to round the value to.
Returns
- float
The nearest multiple of factor that is less than or equal to value.
RoundUp(byte)
Rounds a 8-bit signed integer to the next integer.
public static byte RoundUp(this byte value)
Parameters
value
byteA 8-bit signed integer to be rounded.
Returns
- byte
The nearest integer that is greater than or equal to value.
RoundUp(byte, byte)
Rounds a 8-bit signed integer to the next multiple of the specified factor.
public static byte RoundUp(this byte value, byte factor)
Parameters
Returns
- byte
The nearest multiple of factor that is greater than or equal to value.
RoundUp(decimal)
Rounds a decimal value to the next integer.
public static decimal RoundUp(this decimal value)
Parameters
value
decimalA decimal number to be rounded.
Returns
- decimal
The nearest integer that is greater than or equal to value.
RoundUp(decimal, decimal)
Rounds a decimal value to the next multiple of the specified factor.
public static decimal RoundUp(this decimal value, decimal factor)
Parameters
Returns
- decimal
The nearest multiple of factor that is greater than or equal to value.
RoundUp(double)
Rounds a double-precision floating-point value to the next integer.
public static double RoundUp(this double value)
Parameters
value
doubleA double-precision floating-point number to be rounded.
Returns
- double
The nearest integer that is greater than or equal to value.
RoundUp(double, double)
Rounds a double-precision floating-point value to the next multiple of the specified factor.
public static double RoundUp(this double value, double factor)
Parameters
value
doubleA double-precision floating-point number to be rounded.
factor
doubleThe factor to round the value to.
Returns
- double
The nearest multiple of factor that is greater than or equal to value.
RoundUp(short)
Rounds a 16-bit signed integer to the next integer.
public static short RoundUp(this short value)
Parameters
value
shortA 16-bit signed integer to be rounded.
Returns
- short
The nearest integer that is greater than or equal to value.
RoundUp(short, short)
Rounds a 16-bit signed integer to the next multiple of the specified factor.
public static short RoundUp(this short value, short factor)
Parameters
Returns
- short
The nearest multiple of factor that is greater than or equal to value.
RoundUp(int)
Rounds a 32-bit signed integer to the next integer.
public static int RoundUp(this int value)
Parameters
value
intA 32-bit signed integer to be rounded.
Returns
- int
The nearest integer that is greater than or equal to value.
RoundUp(int, int)
Rounds a 32-bit signed integer to the next multiple of the specified factor.
public static int RoundUp(this int value, int factor)
Parameters
Returns
- int
The nearest multiple of factor that is greater than or equal to value.
RoundUp(long)
Rounds a 64-bit signed integer to the next integer.
public static long RoundUp(this long value)
Parameters
value
longA 64-bit signed integer to be rounded.
Returns
- long
The nearest integer that is greater than or equal to value.
RoundUp(long, long)
Rounds a 64-bit signed integer to the next multiple of the specified factor.
public static long RoundUp(this long value, long factor)
Parameters
Returns
- long
The nearest multiple of factor that is greater than or equal to value.
RoundUp(float)
Rounds a single-precision floating-point value to the next integer.
public static float RoundUp(this float value)
Parameters
value
floatA single-precision floating-point number to be rounded.
Returns
- float
The nearest integer that is greater than or equal to value.
RoundUp(float, float)
Rounds a single-precision floating-point value to the next multiple of the specified factor.
public static float RoundUp(this float value, float factor)
Parameters
value
floatA single-precision floating-point number to be rounded.
factor
floatThe factor to round the value to.
Returns
- float
The nearest multiple of factor that is greater than or equal to value.
Sign(decimal)
Returns a value indicating the sign of a decimal number.
public static int Sign(this decimal value)
Parameters
Returns
- int
A number indicating the sign of value.Number Description -1 value is less than zero. 0 value is equal to zero. 1 value is greater than zero.
Sign(double)
Returns a value indicating the sign of a double-precision floating-point number.
public static int Sign(this double value)
Parameters
value
doubleA signed number.
Returns
- int
A number indicating the sign of value.Number Description -1 value is less than zero. 0 value is equal to zero. 1 value is greater than zero.
Exceptions
- ArithmeticException
value is equal to NaN.
Sign(short)
Returns a value indicating the sign of a 16-bit signed integer.
public static int Sign(this short value)
Parameters
value
shortA signed number.
Returns
- int
A number indicating the sign of value.Number Description -1 value is less than zero. 0 value is equal to zero. 1 value is greater than zero.
Sign(int)
Returns a value indicating the sign of a 32-bit signed integer.
public static int Sign(this int value)
Parameters
value
intA signed number.
Returns
- int
A number indicating the sign of value.Number Description -1 value is less than zero. 0 value is equal to zero. 1 value is greater than zero.
Sign(long)
Returns a value indicating the sign of a 64-bit signed integer.
public static int Sign(this long value)
Parameters
value
longA signed number.
Returns
- int
A number indicating the sign of value.Number Description -1 value is less than zero. 0 value is equal to zero. 1 value is greater than zero.
Sign(sbyte)
Returns a value indicating the sign of an 8-bit signed integer.
public static int Sign(this sbyte value)
Parameters
value
sbyteA signed number.
Returns
- int
A number indicating the sign of value.Number Description -1 value is less than zero. 0 value is equal to zero. 1 value is greater than zero.
Sign(float)
Returns a value indicating the sign of a single-precision floating-point number.
public static int Sign(this float value)
Parameters
value
floatA signed number.
Returns
- int
A number indicating the sign of value.Number Description -1 value is less than zero. 0 value is equal to zero. 1 value is greater than zero.
Exceptions
- ArithmeticException
value is equal to NaN.
Sin(double)
Returns the sine of the specified angle.
public static double Sin(this double angle)
Parameters
angle
doubleAn angle, measured in radians.
Returns
- double
The sine of angle. If angle is equal to NaN, NegativeInfinity, or PositiveInfinity, this method returns NaN.
Sinh(double)
Returns the hyperbolic sine of the specified angle.
public static double Sinh(this double angle)
Parameters
angle
doubleAn angle, measured in radians.
Returns
- double
The hyperbolic sine of angle. If angle is equal to NegativeInfinity, PositiveInfinity, or NaN, this method returns a double equal to angle.
Sqrt(double)
Returns the square root of a specified number.
public static double Sqrt(this double value)
Parameters
value
doubleA number.
Returns
- double
Sqrt(double) for details.
Tan(double)
Returns the tangent of the specified angle.
public static double Tan(this double angle)
Parameters
angle
doubleAn angle, measured in radians.
Returns
- double
The tangent of angle. If angle is equal to NaN, NegativeInfinity, or PositiveInfinity, this method returns NaN.
Tanh(double)
Returns the hyperbolic tangent of the specified angle.
public static double Tanh(this double angle)
Parameters
angle
doubleAn angle, measured in radians.
Returns
- double
The hyperbolic tangent of angle. If angle is equal to NegativeInfinity, this method returns -1. If angle is equal to PositiveInfinity, this method returns 1. If angle is equal to NaN, this method returns NaN.
To(decimal, decimal)
Generates a sequence of decimal numbers within a specified range.
public static IEnumerable<decimal> To(this decimal start, decimal bound)
Parameters
Returns
- IEnumerable<decimal>
A sequence of numbers from start to (but not including) bound where each number is 1 greater than the previous number.
To(decimal, decimal, decimal)
Generates a sequence of decimal numbers within a specified range.
public static IEnumerable<decimal> To(this decimal start, decimal bound, decimal step)
Parameters
Returns
- IEnumerable<decimal>
A sequence of numbers from start to (but not including) bound where each number is a given step greater than the previous number.
To(double, double)
Generates a sequence of double-precision floating-point values within a specified range.
public static IEnumerable<double> To(this double start, double bound)
Parameters
Returns
- IEnumerable<double>
A sequence of numbers from start to (but not including) bound where each number is 1 greater than the previous number.
To(double, double, double)
Generates a sequence of double-precision floating-point values within a specified range.
public static IEnumerable<double> To(this double start, double bound, double step)
Parameters
Returns
- IEnumerable<double>
A sequence of numbers from start to (but not including) bound where each number is a given step greater than the previous number.
To(short, short)
Generates a sequence of 16-bit signed integers within a specified range.
public static IEnumerable<short> To(this short start, short bound)
Parameters
Returns
- IEnumerable<short>
A sequence of numbers from start to (but not including) bound where each number is 1 greater than the previous number.
To(short, short, short)
Generates a sequence of 16-bit signed integers within a specified range.
public static IEnumerable<short> To(this short start, short bound, short step)
Parameters
Returns
- IEnumerable<short>
A sequence of numbers from start to (but not including) bound where each number is a given step greater than the previous number.
To(int, int)
Generates a sequence of 32-bit signed integers within a specified range.
public static IEnumerable<int> To(this int start, int bound)
Parameters
Returns
- IEnumerable<int>
A sequence of numbers from start to (but not including) bound where each number is 1 greater than the previous number.
To(int, int, int)
Generates a sequence of 32-bit signed integers within a specified range.
public static IEnumerable<int> To(this int start, int bound, int step)
Parameters
Returns
- IEnumerable<int>
A sequence of numbers from start to (but not including) bound where each number is a given step greater than the previous number.
To(long, long)
Generates a sequence of 64-bit signed integers within a specified range.
public static IEnumerable<long> To(this long start, long bound)
Parameters
Returns
- IEnumerable<long>
A sequence of numbers from start to (but not including) bound where each number is 1 greater than the previous number.
To(long, long, long)
Generates a sequence of 64-bit signed integers within a specified range.
public static IEnumerable<long> To(this long start, long bound, long step)
Parameters
Returns
- IEnumerable<long>
A sequence of numbers from start to (but not including) bound where each number is a given step greater than the previous number.
To(float, float)
Generates a sequence of single-precision floating-point values within a specified range.
public static IEnumerable<float> To(this float start, float bound)
Parameters
Returns
- IEnumerable<float>
A sequence of numbers from start to (but not including) bound where each number is 1 greater than the previous number.
To(float, float, float)
Generates a sequence of single-precision floating-point values within a specified range.
public static IEnumerable<float> To(this float start, float bound, float step)
Parameters
Returns
- IEnumerable<float>
A sequence of numbers from start to (but not including) bound where each number is a given step greater than the previous number.
Truncate(decimal)
Calculates the integral part of a specified decimal number.
public static decimal Truncate(this decimal value)
Parameters
value
decimalA number to truncate.
Returns
- decimal
The integral part of value; that is, the number that remains after any fractional digits have been discarded.
Truncate(double)
Calculates the integral part of a specified double-precision floating-point number.
public static double Truncate(this double value)
Parameters
value
doubleA number to truncate.
Returns
- double
The integral part of value; that is, the number that remains after any fractional digits have been discarded.