Table of Contents

Class MathExtensions

Namespace
HeBianGu.Base.WpfBase
Assembly
HeBianGu.Base.WpfBase.dll

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

value decimal

A number in the range MinValue ≤ value ≤ MaxValue.

Returns

decimal

A decimal, x, such that 0 ≤ x ≤ MaxValue.

Abs(double)

Returns the absolute value of a double-precision floating-point number.

public static double Abs(this double value)

Parameters

value double

A number in the range MinValue ≤ value ≤ MaxValue.

Returns

double

A double-precision floating-point number, x, such that 0 ≤ x ≤ MaxValue.

Abs(short)

Returns the absolute value of a 16-bit signed integer.

public static short Abs(this short value)

Parameters

value short

A number in the range MinValue < value ≤ MaxValue.

Returns

short

A 16-bit signed integer, x, such that 0 ≤ x ≤ MaxValue.

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

value int

A number in the range MinValue < value ≤ MaxValue.

Returns

int

A 32-bit signed integer, x, such that 0 ≤ x ≤ MaxValue.

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

value long

A number in the range MinValue < value ≤ MaxValue.

Returns

long

A 64-bit signed integer, x, such that 0 ≤ x ≤ MaxValue.

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

value sbyte

A number in the range MinValue < value ≤ MaxValue.

Returns

sbyte

An 8-bit signed integer, x, such that 0 ≤ x ≤ MaxValue.

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

value float

A number in the range MinValue ≤ value ≤ MaxValue.

Returns

float

A single-precision floating-point number, x, such that 0 ≤ x ≤ MaxValue.

Acos(double)

Returns the angle whose cosine is the specified number.

public static double Acos(this double value)

Parameters

value double

A number representing a cosine, where -1 ≤ value ≤ 1.

Returns

double

An angle, θ, measured in radians, such that 0 ≤ θ ≤ π -or- NaN if value < -1 or value > 1.

Asin(double)

Returns the angle whose sine is the specified number.

public static double Asin(this double value)

Parameters

value double

A 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 byte

The first of two 8-bit unsigned integers to compare.

b byte

The 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 decimal

The first of two decimal numbers to compare.

b decimal

The 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 double

The first of two double-precision floating-point numbers to compare.

b double

The 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 short

The first of two 16-bit signed integers to compare.

b short

The 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 int

The first of two 32-bit signed integers to compare.

b int

The 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 long

The first of two 64-bit signed integers to compare.

b long

The 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 sbyte

The first of two 8-bit unsigned integers to compare.

b sbyte

The 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 float

The first of two single-precision floating-point numbers to compare.

b float

The 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 ushort

The first of two 16-bit unsigned integers to compare.

b ushort

The 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 uint

The first of two 32-bit unsigned integers to compare.

b uint

The 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 ulong

The first of two 64-bit unsigned integers to compare.

b ulong

The 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 byte

The first of two 8-bit unsigned integers to compare.

b byte

The 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 decimal

The first of two decimal numbers to compare.

b decimal

The 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 double

The first of two double-precision floating-point numbers to compare.

b double

The 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 short

The first of two 16-bit signed integers to compare.

b short

The 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 int

The first of two 32-bit signed integers to compare.

b int

The 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 long

The first of two 64-bit signed integers to compare.

b long

The 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 sbyte

The first of two 8-bit signed integers to compare.

b sbyte

The 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 float

The first of two single-precision floating-point numbers to compare.

b float

The 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 ushort

The first of two 16-bit unsigned integers to compare.

b ushort

The 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 uint

The first of two 32-bit unsigned integers to compare.

b uint

The 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 ulong

The first of two 64-bit unsigned integers to compare.

b ulong

The 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 double

A 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

y double

The y coordinate of a point.

x double

The x coordinate of a point.

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

a int

The first int to multiply.

b int

The second int to multiply.

Returns

long

The long containing the product of the specified numbers.

Ceiling(decimal)

Returns the smallest integer greater than or equal to the specified decimal number.

public static decimal Ceiling(this decimal value)

Parameters

value decimal

A 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 double

A 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 byte

The value to restrict between a and b.

a byte

The first of two 8-bit unsigned integers to compare.

b byte

The 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 decimal

The value to restrict between a and b.

a decimal

The first of two decimal numbers to compare.

b decimal

The 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 double

The value to restrict between a and b.

a double

The first of two double-precision floating-point numbers to compare.

b double

The 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 short

The value to restrict between a and b.

a short

The first of two 16-bit signed integers to compare.

b short

The 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 int

The value to restrict between a and b.

a int

The first of two 32-bit signed integers to compare.

b int

The 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 long

The value to restrict between a and b.

a long

The first of two 64-bit signed integers to compare.

b long

The 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 sbyte

The value to restrict between a and b.

a sbyte

The first of two 8-bit signed integers to compare.

b sbyte

The 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 float

The value to restrict between a and b.

a float

The first of two single-precision floating-point numbers to compare.

b float

The 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 ushort

The value to restrict between a and b.

a ushort

The first of two 16-bit unsigned integers to compare.

b ushort

The 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 uint

The value to restrict between a and b.

a uint

The first of two 32-bit unsigned integers to compare.

b uint

The 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 ulong

The value to restrict between a and b.

a ulong

The first of two 64-bit unsigned integers to compare.

b ulong

The 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 double

An 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 double

An 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 int

The int that contains the dividend.

b int

The int that contains the divisor.

result int

The int that receives the remainder.

Returns

int

The int containing the quotient of the specified numbers.

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 long

The long that contains the dividend.

b long

The long that contains the divisor.

result long

The long that receives the remainder.

Returns

long

The long containing the quotient of the specified numbers.

Exceptions

DivideByZeroException

b is zero.

Exp(double)

Returns e raised to the specified power.

public static double Exp(this double value)

Parameters

value double

A 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 decimal

A 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 double

A 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 double

A double-precision floating-point number.

Returns

double

The value of the value parameter if it doesn't evaluate to NaN; otherwise, 0.0.

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 double

A double-precision floating-point number.

defaultValue double

The value to return if IsNaN(double) returns true.

Returns

double

The value of the value parameter if it doesn't evaluate to NaN; otherwise, the defaultValue 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 float

A single-precision floating-point number.

Returns

float

The value of the value parameter if it doesn't evaluate to NaN; otherwise, 0.0.

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 float

A single-precision floating-point number.

defaultValue float

The value to return if IsNaN(double) returns true.

Returns

float

The value of the value parameter if it doesn't evaluate to NaN; otherwise, the defaultValue 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

x double

A dividend.

y double

A divisor.

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 byte

An 8-bit unsigned integer to compare.

a byte

The first bound to compare value against.

b byte

The 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 decimal

A decimal value to compare.

a decimal

The first bound to compare value against.

b decimal

The 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 double

A double-precision floating-point value to compare.

a double

The first bound to compare value against.

b double

The 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 short

A 16-bit signed integer to compare.

a short

The first bound to compare value against.

b short

The 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 int

A 32-bit signed integer to compare.

a int

The first bound to compare value against.

b int

The 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 long

A 64-bit signed integer to compare.

a long

The first bound to compare value against.

b long

The 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 float

A double-precision floating-point value to compare.

a float

The first bound to compare value against.

b float

The 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 double

A double-precision floating-point number.

Returns

bool

true if value evaluates to NaN; otherwise, false.

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

bool

true if value evaluates to not a number (NaN); otherwise, false.

Log(double)

Returns the natural (base e) logarithm of a specified number.

public static double Log(this double value)

Parameters

value double

A 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

value double

A number whose logarithm is to be found.

newBase double

The base of the logarithm.

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 double

A 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 double

A double-precision floating-point number to be raised to a power.

y double

A 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 decimal

A 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 decimal

A decimal number to be rounded.

decimals int

The 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 decimal

A decimal number to be rounded.

decimals int

The number of significant decimal places (precision) in the return value.

mode MidpointRounding

Specification 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 decimal

A decimal number to be rounded.

mode MidpointRounding

Specification 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 double

A 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 double

A double-precision floating-point number to be rounded.

digits int

The 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 double

A double-precision floating-point number to be rounded.

digits int

The number of significant digits (precision) in the return value.

mode MidpointRounding

Specification 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 double

A double-precision floating-point number to be rounded.

mode MidpointRounding

Specification 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 byte

An 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

value byte

An 8-bit unsigned integer to be rounded.

factor byte

The factor to round the value to.

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 decimal

A 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

value decimal

A decimal number to be rounded.

factor decimal

The factor to round the value to.

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 double

A 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 double

A double-precision floating-point number to be rounded.

factor double

The 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 short

A 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

value short

A 16-bit signed integer to be rounded.

factor short

The factor to round the value to.

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 int

A 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

value int

A 32-bit signed integer to be rounded.

factor int

The factor to round the value to.

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 long

A 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

value long

A 64-bit signed integer to be rounded.

factor long

The factor to round the value to.

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 float

A 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 float

A single-precision floating-point number to be rounded.

factor float

The 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 byte

A 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

value byte

A 8-bit signed integer to be rounded.

factor byte

The factor to round the value to.

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 decimal

A 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

value decimal

A decimal number to be rounded.

factor decimal

The factor to round the value to.

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 double

A 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 double

A double-precision floating-point number to be rounded.

factor double

The 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 short

A 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

value short

A 16-bit signed integer to be rounded.

factor short

The factor to round the value to.

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 int

A 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

value int

A 32-bit signed integer to be rounded.

factor int

The factor to round the value to.

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 long

A 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

value long

A 64-bit signed integer to be rounded.

factor long

The factor to round the value to.

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 float

A 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 float

A single-precision floating-point number to be rounded.

factor float

The 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

value decimal

A signed decimal 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(double)

Returns a value indicating the sign of a double-precision floating-point number.

public static int Sign(this double value)

Parameters

value double

A 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 short

A 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 int

A 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 long

A 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 sbyte

A 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 float

A 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 double

An 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 double

An 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 double

A 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 double

An 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 double

An 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

start decimal

The number to start from.

bound decimal

The number to stop before.

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

start decimal

The number to start from.

bound decimal

The number to stop before.

step decimal

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

start double

The number to start from.

bound double

The number to stop before.

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

start double

The number to start from.

bound double

The number to stop before.

step double

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

start short

The number to start from.

bound short

The number to stop before.

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

start short

The number to start from.

bound short

The number to stop before.

step short

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

start int

The number to start from.

bound int

The number to stop before.

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

start int

The number to start from.

bound int

The number to stop before.

step int

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

start long

The number to start from.

bound long

The number to stop before.

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

start long

The number to start from.

bound long

The number to stop before.

step long

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

start float

The number to start from.

bound float

The number to stop before.

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

start float

The number to start from.

bound float

The number to stop before.

step float

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 decimal

A 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 double

A number to truncate.

Returns

double

The integral part of value; that is, the number that remains after any fractional digits have been discarded.