namespace VideoBrowser.Extensions { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using VideoBrowser.Common; /// /// Defines the /// internal static class MathExtensions { #region Methods /// /// The Abs /// /// A number in the range ≤ value ≤ . /// A , x, such that 0 ≤ x ≤ . public static decimal Abs(this decimal value) { return Math.Abs(value); } /// /// The Abs /// /// A number in the range ≤ value ≤ . /// A double-precision floating-point number, x, such that 0 ≤ x ≤ . public static double Abs(this double value) { return Math.Abs(value); } /// /// The Abs /// /// A number in the range ≤ value ≤ . /// A single-precision floating-point number, x, such that 0 ≤ x ≤ . public static float Abs(this float value) { return Math.Abs(value); } /// /// The Abs /// /// A number in the range < value ≤ . /// A 32-bit signed integer, x, such that 0 ≤ x ≤ . public static int Abs(this int value) { return Math.Abs(value); } /// /// The Abs /// /// A number in the range < value ≤ . /// A 64-bit signed integer, x, such that 0 ≤ x ≤ . public static long Abs(this long value) { return Math.Abs(value); } /// /// The Abs /// /// A number in the range < value ≤ . /// An 8-bit signed integer, x, such that 0 ≤ x ≤ . public static sbyte Abs(this sbyte value) { return Math.Abs(value); } /// /// The Abs /// /// A number in the range < value ≤ . /// A 16-bit signed integer, x, such that 0 ≤ x ≤ . public static short Abs(this short value) { return Math.Abs(value); } /// /// The Acos /// /// A number representing a cosine, where -1 ≤ value ≤ 1. /// An angle, θ, measured in radians, such that 0 ≤ θ ≤ π -or- if value < -1 or value > 1. public static double Acos(this double value) { return Math.Acos(value); } /// /// The Asin /// /// A number representing a sine, where -1 ≤ value ≤ 1. /// An angle, θ, measured in radians, such that -π/2 ≤ θ ≤ π/2 -or- if value < -1 or value > 1. public static double Asin(this double value) { return Math.Asin(value); } /// /// The Atan /// /// A number representing a tangent. /// An angle, θ, measured in radians, such that -π/2 ≤ θ ≤ π/2 -or- if value equals , -π/2 rounded to double precision (-1.5707963267949) if value equals , or π/2 rounded to double precision (1.5707963267949) if value equals . public static double Atan(this double value) { return Math.Atan(value); } /// /// The Atan2 /// /// The y coordinate of a point. /// The x coordinate of a point. /// An angle, θ, measured in radians, such that -π ≤ θ ≤ π, and tan(θ) = y / x, where (x, y) is a point in the Cartesian plane. See for details. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static double Atan2(this double y, double x) { return Math.Atan2(y, x); } /// /// The AtLeast /// /// The first of two 8-bit unsigned integers to compare. /// The second of two 8-bit unsigned integers to compare. /// Parameter a or b, whichever is larger. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static byte AtLeast(this byte a, byte b) { return Math.Max(a, b); } /// /// The AtLeast /// /// The first of two numbers to compare. /// The second of two numbers to compare. /// Parameter a or b, whichever is larger. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static decimal AtLeast(this decimal a, decimal b) { return Math.Max(a, b); } /// /// The AtLeast /// /// The first of two double-precision floating-point numbers to compare. /// The second of two double-precision floating-point numbers to compare. /// Parameter a or b, whichever is larger. If a, b, or both a and b are equal to , is returned. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static double AtLeast(this double a, double b) { return Math.Max(a, b); } /// /// The AtLeast /// /// The first of two single-precision floating-point numbers to compare. /// The second of two single-precision floating-point numbers to compare. /// Parameter a or b, whichever is larger. If a, or b, or both a and b are equal to , is returned. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static float AtLeast(this float a, float b) { return Math.Max(a, b); } /// /// The AtLeast /// /// The first of two 32-bit signed integers to compare. /// The second of two 32-bit signed integers to compare. /// Parameter a or b, whichever is larger. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static int AtLeast(this int a, int b) { return Math.Max(a, b); } /// /// The AtLeast /// /// The first of two 64-bit signed integers to compare. /// The second of two 64-bit signed integers to compare. /// Parameter a or b, whichever is larger. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static long AtLeast(this long a, long b) { return Math.Max(a, b); } /// /// The AtLeast /// /// The first of two 8-bit unsigned integers to compare. /// The second of two 8-bit unsigned integers to compare. /// Parameter a or b, whichever is larger. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static sbyte AtLeast(this sbyte a, sbyte b) => Math.Max(a, b); /// /// The AtLeast /// /// The first of two 16-bit signed integers to compare. /// The second of two 16-bit signed integers to compare. /// Parameter a or b, whichever is larger. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static short AtLeast(this short a, short b) { return Math.Max(a, b); } /// /// The AtLeast /// /// The first of two 32-bit unsigned integers to compare. /// The second of two 32-bit unsigned integers to compare. /// Parameter a or b, whichever is larger. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static uint AtLeast(this uint a, uint b) { return Math.Max(a, b); } /// /// The AtLeast /// /// The first of two 64-bit unsigned integers to compare. /// The second of two 64-bit unsigned integers to compare. /// Parameter a or b, whichever is larger. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static ulong AtLeast(this ulong a, ulong b) { return Math.Max(a, b); } /// /// The AtLeast /// /// The first of two 16-bit unsigned integers to compare. /// The second of two 16-bit unsigned integers to compare. /// Parameter a or b, whichever is larger. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static ushort AtLeast(this ushort a, ushort b) { return Math.Max(a, b); } /// /// The AtMost /// /// The first of two 8-bit unsigned integers to compare. /// The second of two 8-bit unsigned integers to compare. /// Parameter a or b, whichever is smaller. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static byte AtMost(this byte a, byte b) { return Math.Min(a, b); } /// /// The AtMost /// /// The first of two numbers to compare. /// The second of two numbers to compare. /// Parameter a or b, whichever is smaller. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static decimal AtMost(this decimal a, decimal b) { return Math.Min(a, b); } /// /// The AtMost /// /// The first of two double-precision floating-point numbers to compare. /// The second of two double-precision floating-point numbers to compare. /// Parameter a or b, whichever is smaller. If a, b, or both a and b are equal to , is returned. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static double AtMost(this double a, double b) { return Math.Min(a, b); } /// /// The AtMost /// /// The first of two single-precision floating-point numbers to compare. /// The second of two single-precision floating-point numbers to compare. /// Parameter a or b, whichever is smaller. If a, b, or both a and b are equal to , is returned. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static float AtMost(this float a, float b) { return Math.Min(a, b); } /// /// The AtMost /// /// The first of two 32-bit signed integers to compare. /// The second of two 32-bit signed integers to compare. /// Parameter a or b, whichever is smaller. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static int AtMost(this int a, int b) { return Math.Min(a, b); } /// /// The AtMost /// /// The first of two 64-bit signed integers to compare. /// The second of two 64-bit signed integers to compare. /// Parameter a or b, whichever is smaller. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static long AtMost(this long a, long b) { return Math.Min(a, b); } /// /// The AtMost /// /// The first of two 8-bit signed integers to compare. /// The second of two 8-bit signed integers to compare. /// Parameter a or b, whichever is smaller. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static sbyte AtMost(this sbyte a, sbyte b) { return Math.Min(a, b); } /// /// The AtMost /// /// The first of two 16-bit signed integers to compare. /// The second of two 16-bit signed integers to compare. /// Parameter a or b, whichever is smaller. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static short AtMost(this short a, short b) { return Math.Min(a, b); } /// /// The AtMost /// /// The first of two 32-bit unsigned integers to compare. /// The second of two 32-bit unsigned integers to compare. /// Parameter a or b, whichever is smaller. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static uint AtMost(this uint a, uint b) { return Math.Min(a, b); } /// /// The AtMost /// /// The first of two 64-bit unsigned integers to compare. /// The second of two 64-bit unsigned integers to compare. /// Parameter a or b, whichever is smaller. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static ulong AtMost(this ulong a, ulong b) { return Math.Min(a, b); } /// /// The AtMost /// /// The first of two 16-bit unsigned integers to compare. /// The second of two 16-bit unsigned integers to compare. /// Parameter a or b, whichever is smaller. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static ushort AtMost(this ushort a, ushort b) { return Math.Min(a, b); } /// /// The BigMul /// /// The first to multiply. /// The second to multiply. /// The containing the product of the specified numbers. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static long BigMul(this int a, int b) { return Math.BigMul(a, b); } /// /// The Ceiling /// /// A decimal number. /// The smallest integer greater than or equal to value. public static decimal Ceiling(this decimal value) { return Math.Ceiling(value); } /// /// The Ceiling /// /// A double-precision floating-point number. /// The smallest integer greater than or equal to value. If value is equal to , , or , that value is returned. public static double Ceiling(this double value) { return Math.Ceiling(value); } /// /// The Clamp /// /// The value to restrict between a and b. /// The first of two 8-bit unsigned integers to compare. /// The second of two 8-bit unsigned integers to compare. /// A value between a and b inclusively. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static byte Clamp(this byte value, byte a, byte b) { return a < b ? Math.Min(Math.Max(value, a), b) : Math.Max(Math.Min(value, a), b); } /// /// The Clamp /// /// The value to restrict between a and b. /// The first of two numbers to compare. /// The second of two numbers to compare. /// A value between a and b inclusively. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static decimal Clamp(this decimal value, decimal a, decimal b) { return a < b ? Math.Min(Math.Max(value, a), b) : Math.Max(Math.Min(value, a), b); } /// /// The Clamp /// /// The value to restrict between a and b. /// The first of two double-precision floating-point numbers to compare. /// The second of two double-precision floating-point numbers to compare. /// A value between a and b inclusively. If a, b, or both a and b are equal to , is returned. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static double Clamp(this double value, double a, double b) { return a < b ? Math.Min(Math.Max(value, a), b) : Math.Max(Math.Min(value, a), b); } /// /// The Clamp /// /// The value to restrict between a and b. /// The first of two single-precision floating-point numbers to compare. /// The second of two single-precision floating-point numbers to compare. /// A value between a and b inclusively. If a, b, or both a and b are equal to , is returned. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static float Clamp(this float value, float a, float b) { return a < b ? Math.Min(Math.Max(value, a), b) : Math.Max(Math.Min(value, a), b); } /// /// The Clamp /// /// The value to restrict between a and b. /// The first of two 32-bit signed integers to compare. /// The second of two 32-bit signed integers to compare. /// A value between a and b inclusively. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static int Clamp(this int value, int a, int b) { return a < b ? Math.Min(Math.Max(value, a), b) : Math.Max(Math.Min(value, a), b); } /// /// The Clamp /// /// The value to restrict between a and b. /// The first of two 64-bit signed integers to compare. /// The second of two 64-bit signed integers to compare. /// A value between a and b inclusively. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static long Clamp(this long value, long a, long b) { return a < b ? Math.Min(Math.Max(value, a), b) : Math.Max(Math.Min(value, a), b); } /// /// The Clamp /// /// The value to restrict between a and b. /// The first of two 8-bit signed integers to compare. /// The second of two 8-bit signed integers to compare. /// A value between a and b inclusively. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static sbyte Clamp(this sbyte value, sbyte a, sbyte b) { return a < b ? Math.Min(Math.Max(value, a), b) : Math.Max(Math.Min(value, a), b); } /// /// The Clamp /// /// The value to restrict between a and b. /// The first of two 16-bit signed integers to compare. /// The second of two 16-bit signed integers to compare. /// A value between a and b inclusively. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static short Clamp(this short value, short a, short b) { return a < b ? Math.Min(Math.Max(value, a), b) : Math.Max(Math.Min(value, a), b); } /// /// The Clamp /// /// The value to restrict between a and b. /// The first of two 32-bit unsigned integers to compare. /// The second of two 32-bit unsigned integers to compare. /// A value between a and b inclusively. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static uint Clamp(this uint value, uint a, uint b) { return a < b ? Math.Min(Math.Max(value, a), b) : Math.Max(Math.Min(value, a), b); } /// /// The Clamp /// /// The value to restrict between a and b. /// The first of two 64-bit unsigned integers to compare. /// The second of two 64-bit unsigned integers to compare. /// A value between a and b inclusively. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static ulong Clamp(this ulong value, ulong a, ulong b) { return a < b ? Math.Min(Math.Max(value, a), b) : Math.Max(Math.Min(value, a), b); } /// /// The Clamp /// /// The value to restrict between a and b. /// The first of two 16-bit unsigned integers to compare. /// The second of two 16-bit unsigned integers to compare. /// A value between a and b inclusively. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static ushort Clamp(this ushort value, ushort a, ushort b) { return a < b ? Math.Min(Math.Max(value, a), b) : Math.Max(Math.Min(value, a), b); } /// /// The Cos /// /// An angle, measured in radians. /// The cosine of angle. public static double Cos(this double angle) { return Math.Cos(angle); } /// /// The Cosh /// /// An angle, measured in radians. /// The hyperbolic cosine of angle. If angle is equal to or , is returned. If angle is equal to , is returned. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static double Cosh(this double angle) { return Math.Cosh(angle); } /// /// The DivRem /// /// The that contains the dividend. /// The that contains the divisor. /// The that receives the remainder. /// The containing the quotient of the specified numbers. [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters")] [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static int DivRem(this int a, int b, out int result) { return Math.DivRem(a, b, out result); } /// /// The DivRem /// /// The that contains the dividend. /// The that contains the divisor. /// The that receives the remainder. /// The containing the quotient of the specified numbers. [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters")] [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static long DivRem(this long a, long b, out long result) { return Math.DivRem(a, b, out result); } /// /// The Exp /// /// A number specifying a power. /// The number e raised to the power value. If value equals or , that value is returned. If value equals , 0 is returned. public static double Exp(this double value) { return Math.Exp(value); } /// /// The Floor /// /// A decimal number. /// The largest integer less than or equal to value. public static decimal Floor(this decimal value) { return Math.Floor(value); } /// /// The Floor /// /// A double-precision floating-point number. /// The largest integer less than or equal to value. If value is equal to , , or , that value is returned. public static double Floor(this double value) { return Math.Floor(value); } /// /// The Format the double value with 0.###. /// /// The value /// The public static string Format(this double value) { var message = $"{value:0.###}"; return message; } /// /// The GetValueOrDefault /// /// A double-precision floating-point number. /// The value of the parameter if it doesn't evaluate to ; otherwise, 0.0. public static double GetValueOrDefault(this double value) { return double.IsNaN(value) ? 0.0 : value; } /// /// The GetValueOrDefault /// /// A double-precision floating-point number. /// The value to return if returns true. /// The value of the parameter if it doesn't evaluate to ; otherwise, the parameter. public static double GetValueOrDefault(this double value, double defaultValue) { return double.IsNaN(value) ? defaultValue : value; } /// /// The GetValueOrDefault /// /// A single-precision floating-point number. /// The value of the parameter if it doesn't evaluate to ; otherwise, 0.0. public static float GetValueOrDefault(this float value) { return Single.IsNaN(value) ? 0.0f : value; } /// /// The GetValueOrDefault /// /// A single-precision floating-point number. /// The value to return if returns true. /// The value of the parameter if it doesn't evaluate to ; otherwise, the parameter. public static float GetValueOrDefault(this float value, float defaultValue) { return Single.IsNaN(value) ? defaultValue : value; } /// /// The IEEERemainder /// /// A dividend. /// A divisor. /// 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, (Not-A-Number) is returned. [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly")] [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static double IEEERemainder(this double x, double y) { return Math.IEEERemainder(x, y); } /// /// The IsBetween /// /// An 8-bit unsigned integer to compare. /// The first bound to compare value against. /// The second bound to compare value against. /// A boolean representing whether value is inclusively between a and b. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static bool IsBetween(this byte value, byte a, byte b) { return a < b ? a <= value && value <= b : b <= value && value <= a; } /// /// The IsBetween /// /// A decimal value to compare. /// The first bound to compare value against. /// The second bound to compare value against. /// A boolean representing whether value is inclusively between a and b. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static bool IsBetween(this decimal value, decimal a, decimal b) { return a < b ? a <= value && value <= b : b <= value && value <= a; } /// /// The IsBetween /// /// A double-precision floating-point value to compare. /// The first bound to compare value against. /// The second bound to compare value against. /// A boolean representing whether value is inclusively between a and b. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static bool IsBetween(this double value, double a, double b) { return a < b ? a <= value && value <= b : b <= value && value <= a; } /// /// The IsBetween /// /// A double-precision floating-point value to compare. /// The first bound to compare value against. /// The second bound to compare value against. /// A boolean representing whether value is inclusively between a and b. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static bool IsBetween(this float value, float a, float b) { return a < b ? a <= value && value <= b : b <= value && value <= a; } /// /// The IsBetween /// /// A 32-bit signed integer to compare. /// The first bound to compare value against. /// The second bound to compare value against. /// A boolean representing whether value is inclusively between a and b. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static bool IsBetween(this int value, int a, int b) { return a < b ? a <= value && value <= b : b <= value && value <= a; } /// /// The IsBetween /// /// A 64-bit signed integer to compare. /// The first bound to compare value against. /// The second bound to compare value against. /// A boolean representing whether value is inclusively between a and b. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static bool IsBetween(this long value, long a, long b) { return a < b ? a <= value && value <= b : b <= value && value <= a; } /// /// The IsBetween /// /// A 16-bit signed integer to compare. /// The first bound to compare value against. /// The second bound to compare value against. /// A boolean representing whether value is inclusively between a and b. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static bool IsBetween(this short value, short a, short b) { return a < b ? a <= value && value <= b : b <= value && value <= a; } /// /// Determines whether [is equal to] [the specified b]. /// /// a. /// The b. /// The tolerance. /// The public static bool IsEqualTo(this double a, double b, double tolerance = Epsilon.Default) { var isEqual = ((a - b).Abs() < tolerance) ? true : false; return isEqual; } /// /// The IsNaN /// /// A double-precision floating-point number. /// true if value evaluates to ; otherwise, false. public static bool IsNaN(this double value) { return double.IsNaN(value); } /// /// The IsNaN /// /// A single-precision floating-point number. /// true if value evaluates to not a number (); otherwise, false. public static bool IsNaN(this float value) { return Single.IsNaN(value); } /// /// The IsZero /// /// The /// The public static bool IsZero(this double value) { return value.Abs() < Epsilon.Default; } /// /// The Log /// /// A number whose logarithm is to be found. /// See for details. public static double Log(this double value) { return Math.Log(value); } /// /// The Log /// /// A number whose logarithm is to be found. /// The base of the logarithm. /// See for details. public static double Log(this double value, double newBase) { return Math.Log(value, newBase); } /// /// The Log10 /// /// A number whose logarithm is to be found. /// See for details. public static double Log10(this double value) { return Math.Log10(value); } /// /// The Pow /// /// A double-precision floating-point number to be raised to a power. /// A double-precision floating-point number that specifies a power. /// The number x raised to the power y. See for details. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static double Pow(this double x, double y) { return Math.Pow(x, y); } /// /// The Round /// /// A decimal number to be rounded. /// 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. public static decimal Round(this decimal value) { return Math.Round(value); } /// /// The Round /// /// A decimal number to be rounded. /// The number of significant decimal places (precision) in the return value. /// 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. public static decimal Round(this decimal value, int decimals) { return Math.Round(value, decimals); } /// /// The Round /// /// A decimal number to be rounded. /// The number of significant decimal places (precision) in the return value. /// Specification for how to round value if it is midway between two other numbers. /// 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. public static decimal Round(this decimal value, int decimals, MidpointRounding mode) { return Math.Round(value, decimals, mode); } /// /// The Round /// /// A decimal number to be rounded. /// Specification for how to round value if it is midway between two other numbers. /// 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. public static decimal Round(this decimal value, MidpointRounding mode) { return Math.Round(value, mode); } /// /// The Round /// /// A double-precision floating-point number to be rounded. /// 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. public static double Round(this double value) { return Math.Round(value); } /// /// The Round /// /// A double-precision floating-point number to be rounded. /// The number of significant digits (precision) in the return value. /// 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. public static double Round(this double value, int digits) { return Math.Round(value, digits); } /// /// The Round /// /// A double-precision floating-point number to be rounded. /// The number of significant digits (precision) in the return value. /// Specification for how to round value if it is midway between two other numbers. /// 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. public static double Round(this double value, int digits, MidpointRounding mode) { return Math.Round(value, digits, mode); } /// /// The Round /// /// A double-precision floating-point number to be rounded. /// Specification for how to round value if it is midway between two other numbers. /// 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. public static double Round(this double value, MidpointRounding mode) { return Math.Round(value, mode); } /// /// The RoundDown /// /// An 8-bit unsigned integer to be rounded. /// The nearest integer that is less than or equal to value. public static byte RoundDown(this byte value) { return RoundDown(value, (byte)1); } /// /// The RoundDown /// /// An 8-bit unsigned integer to be rounded. /// The factor to round the value to. /// The nearest multiple of factor that is less than or equal to value. public static byte RoundDown(this byte value, byte factor) { var d = (value % factor); return (byte)(value - d); } /// /// The RoundDown /// /// A decimal number to be rounded. /// The nearest integer that is less than or equal to value. public static decimal RoundDown(this decimal value) { return RoundDown(value, 1); } /// /// The RoundDown /// /// A decimal number to be rounded. /// The factor to round the value to. /// The nearest multiple of factor that is less than or equal to value. public static decimal RoundDown(this decimal value, decimal factor) { var d = (value % factor); return d == 0 ? value : value > 0 ? value - d : value - (factor + d); } /// /// The RoundDown /// /// A double-precision floating-point number to be rounded. /// The nearest integer that is less than or equal to value. public static double RoundDown(this double value) { return RoundDown(value, 1); } /// /// The RoundDown /// /// A double-precision floating-point number to be rounded. /// The factor to round the value to. /// The nearest multiple of factor that is less than or equal to value. public static double RoundDown(this double value, double factor) { var d = (value % factor); return d == 0 ? value : value > 0 ? value - d : value - (factor + d); } /// /// The RoundDown /// /// A single-precision floating-point number to be rounded. /// The nearest integer that is less than or equal to value. public static float RoundDown(this float value) { return RoundDown(value, 1); } /// /// The RoundDown /// /// A single-precision floating-point number to be rounded. /// The factor to round the value to. /// The nearest multiple of factor that is less than or equal to value. public static float RoundDown(this float value, float factor) { var d = (value % factor); return d == 0 ? value : value > 0 ? value - d : value - (factor + d); } /// /// The RoundDown /// /// A 32-bit signed integer to be rounded. /// The nearest integer that is less than or equal to value. public static int RoundDown(this int value) { return RoundDown(value, 1); } /// /// The RoundDown /// /// A 32-bit signed integer to be rounded. /// The factor to round the value to. /// The nearest multiple of factor that is less than or equal to value. public static int RoundDown(this int value, int factor) { var d = (value % factor); return d == 0 ? value : value > 0 ? value - d : value - (factor + d); } /// /// The RoundDown /// /// A 64-bit signed integer to be rounded. /// The nearest integer that is less than or equal to value. public static long RoundDown(this long value) { return RoundDown(value, 1); } /// /// The RoundDown /// /// A 64-bit signed integer to be rounded. /// The factor to round the value to. /// The nearest multiple of factor that is less than or equal to value. public static long RoundDown(this long value, long factor) { var d = (value % factor); return d == 0 ? value : value > 0 ? value - d : value - (factor + d); } /// /// The RoundDown /// /// A 16-bit signed integer to be rounded. /// The nearest integer that is less than or equal to value. public static short RoundDown(this short value) { return RoundDown(value, (short)1); } /// /// The RoundDown /// /// A 16-bit signed integer to be rounded. /// The factor to round the value to. /// The nearest multiple of factor that is less than or equal to value. public static short RoundDown(this short value, short factor) { var d = (value % factor); return (short)(d == 0 ? value : value > 0 ? value - d : value - (factor + d)); } /// /// The RoundUp /// /// A 8-bit signed integer to be rounded. /// The nearest integer that is greater than or equal to value. [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] public static byte RoundUp(this byte value) { return RoundUp(value, (byte)1); } /// /// The RoundUp /// /// A 8-bit signed integer to be rounded. /// The factor to round the value to. /// The nearest multiple of factor that is greater than or equal to value. [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] public static byte RoundUp(this byte value, byte factor) { var d = (value % factor); return (byte)(d == 0 ? value : value + (factor - d)); } /// /// The RoundUp /// /// A decimal number to be rounded. /// The nearest integer that is greater than or equal to value. [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] public static decimal RoundUp(this decimal value) { return RoundUp(value, 1); } /// /// The RoundUp /// /// A decimal number to be rounded. /// The factor to round the value to. /// The nearest multiple of factor that is greater than or equal to value. [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] public static decimal RoundUp(this decimal value, decimal factor) { var d = (value % factor); return d == 0 ? value : value < 0 ? value - d : value + (factor - d); } /// /// The RoundUp /// /// A double-precision floating-point number to be rounded. /// The nearest integer that is greater than or equal to value. [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] public static double RoundUp(this double value) { return RoundUp(value, 1); } /// /// The RoundUp /// /// A double-precision floating-point number to be rounded. /// The factor to round the value to. /// The nearest multiple of factor that is greater than or equal to value. [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] public static double RoundUp(this double value, double factor) { var d = (value % factor); return d == 0 ? value : value < 0 ? value - d : value + (factor - d); } /// /// The RoundUp /// /// A single-precision floating-point number to be rounded. /// The nearest integer that is greater than or equal to value. [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] public static float RoundUp(this float value) { return RoundUp(value, 1); } /// /// The RoundUp /// /// A single-precision floating-point number to be rounded. /// The factor to round the value to. /// The nearest multiple of factor that is greater than or equal to value. [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] public static float RoundUp(this float value, float factor) { var d = (value % factor); return d == 0 ? value : value < 0 ? value - d : value + (factor - d); } /// /// The RoundUp /// /// A 32-bit signed integer to be rounded. /// The nearest integer that is greater than or equal to value. [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] public static int RoundUp(this int value) { return RoundUp(value, 1); } /// /// The RoundUp /// /// A 32-bit signed integer to be rounded. /// The factor to round the value to. /// The nearest multiple of factor that is greater than or equal to value. [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] public static int RoundUp(this int value, int factor) { var d = (value % factor); return d == 0 ? value : value < 0 ? value - d : value + (factor - d); } /// /// The RoundUp /// /// A 64-bit signed integer to be rounded. /// The nearest integer that is greater than or equal to value. [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] public static long RoundUp(this long value) { return RoundUp(value, 1); } /// /// The RoundUp /// /// A 64-bit signed integer to be rounded. /// The factor to round the value to. /// The nearest multiple of factor that is greater than or equal to value. [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] public static long RoundUp(this long value, long factor) { var d = (value % factor); return d == 0 ? value : value < 0 ? value - d : value + (factor - d); } /// /// The RoundUp /// /// A 16-bit signed integer to be rounded. /// The nearest integer that is greater than or equal to value. [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] public static short RoundUp(this short value) { return RoundUp(value, (short)1); } /// /// The RoundUp /// /// A 16-bit signed integer to be rounded. /// The factor to round the value to. /// The nearest multiple of factor that is greater than or equal to value. [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] public static short RoundUp(this short value, short factor) { var d = (value % factor); return (short)(d == 0 ? value : value < 0 ? value - d : value + (factor - d)); } /// /// The Sign /// /// A signed number. /// 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. public static int Sign(this decimal value) { return Math.Sign(value); } /// /// The Sign /// /// A signed number. /// 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. public static int Sign(this double value) { return Math.Sign(value); } /// /// The Sign /// /// A signed number. /// 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. public static int Sign(this float value) { return Math.Sign(value); } /// /// The Sign /// /// A signed number. /// 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. public static int Sign(this int value) { return Math.Sign(value); } /// /// The Sign /// /// A signed number. /// 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. public static int Sign(this long value) { return Math.Sign(value); } /// /// The Sign /// /// A signed number. /// 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. public static int Sign(this sbyte value) { return Math.Sign(value); } /// /// The Sign /// /// A signed number. /// 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. public static int Sign(this short value) { return Math.Sign(value); } /// /// The Sin /// /// An angle, measured in radians. /// The sine of angle. If angle is equal to , , or , this method returns . public static double Sin(this double angle) { return Math.Sin(angle); } /// /// The Sinh /// /// An angle, measured in radians. /// The hyperbolic sine of angle. If angle is equal to , , or , this method returns a equal to angle. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static double Sinh(this double angle) { return Math.Sinh(angle); } /// /// The Sqrt /// /// A number. /// for details. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static double Sqrt(this double value) { return Math.Sqrt(value); } /// /// The Tan /// /// An angle, measured in radians. /// The tangent of angle. If angle is equal to , , or , this method returns . public static double Tan(this double angle) { return Math.Tan(angle); } /// /// The Tanh /// /// An angle, measured in radians. /// The hyperbolic tangent of angle. If angle is equal to , this method returns -1. If angle is equal to , this method returns 1. If angle is equal to , this method returns . [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public static double Tanh(this double angle) { return Math.Tanh(angle); } /// /// The To /// /// The number to start from. /// The number to stop before. /// A sequence of numbers from start to (but not including) bound where each number is 1 greater than the previous number. public static IEnumerable To(this decimal start, decimal bound) { var step = start <= bound ? 1 : (decimal)-1; for (decimal i = start; i < bound; i += step) yield return i; } /// /// The To /// /// The number to start from. /// The number to stop before. /// The increment step. /// A sequence of numbers from start to (but not including) bound where each number is a given step greater than the previous number. public static IEnumerable To(this decimal start, decimal bound, decimal step) { for (decimal i = start; i < bound; i += step) yield return i; } /// /// The To /// /// The number to start from. /// The number to stop before. /// A sequence of numbers from start to (but not including) bound where each number is 1 greater than the previous number. public static IEnumerable To(this double start, double bound) { var step = start <= bound ? 1 : (double)-1; for (double i = start; i < bound; i += step) yield return i; } /// /// The To /// /// The number to start from. /// The number to stop before. /// The increment step. /// A sequence of numbers from start to (but not including) bound where each number is a given step greater than the previous number. public static IEnumerable To(this double start, double bound, double step) { for (double i = start; i < bound; i += step) yield return i; } /// /// The To /// /// The number to start from. /// The number to stop before. /// A sequence of numbers from start to (but not including) bound where each number is 1 greater than the previous number. public static IEnumerable To(this float start, float bound) { var step = start <= bound ? 1 : (float)-1; for (float i = start; i < bound; i += step) yield return i; } /// /// The To /// /// The number to start from. /// The number to stop before. /// The increment step. /// A sequence of numbers from start to (but not including) bound where each number is a given step greater than the previous number. public static IEnumerable To(this float start, float bound, float step) { for (float i = start; i < bound; i += step) yield return i; } /// /// The To /// /// The number to start from. /// The number to stop before. /// A sequence of numbers from start to (but not including) bound where each number is 1 greater than the previous number. public static IEnumerable To(this int start, int bound) { var step = start <= bound ? 1 : -1; for (int i = start; i < bound; i += step) yield return i; } /// /// The To /// /// The number to start from. /// The number to stop before. /// The increment step. /// A sequence of numbers from start to (but not including) bound where each number is a given step greater than the previous number. public static IEnumerable To(this int start, int bound, int step) { for (int i = start; i < bound; i += step) yield return i; } /// /// The To /// /// The number to start from. /// The number to stop before. /// A sequence of numbers from start to (but not including) bound where each number is 1 greater than the previous number. public static IEnumerable To(this long start, long bound) { var step = start <= bound ? 1 : (long)-1; for (long i = start; i < bound; i += step) yield return i; } /// /// The To /// /// The number to start from. /// The number to stop before. /// The increment step. /// A sequence of numbers from start to (but not including) bound where each number is a given step greater than the previous number. public static IEnumerable To(this long start, long bound, long step) { for (long i = start; i < bound; i += step) yield return i; } /// /// The To /// /// The number to start from. /// The number to stop before. /// A sequence of numbers from start to (but not including) bound where each number is 1 greater than the previous number. public static IEnumerable To(this short start, short bound) { var step = start <= bound ? (short)1 : (short)-1; for (short i = start; i < bound; i += step) yield return i; } /// /// The To /// /// The number to start from. /// The number to stop before. /// The increment step. /// A sequence of numbers from start to (but not including) bound where each number is a given step greater than the previous number. public static IEnumerable To(this short start, short bound, short step) { for (short i = start; i < bound; i += step) yield return i; } /// /// The Truncate /// /// A number to truncate. /// The integral part of value; that is, the number that remains after any fractional digits have been discarded. public static decimal Truncate(this decimal value) { return Math.Truncate(value); } /// /// The Truncate /// /// A number to truncate. /// The integral part of value; that is, the number that remains after any fractional digits have been discarded. public static double Truncate(this double value) { return Math.Truncate(value); } #endregion Methods } }