csharp/AlphaYu/Adnc/src/ServerApi/Infrastructures/Adnc.Infra.Core/System/Extensions/Double/DoubleExtension.cs

DoubleExtension.cs
namespace System
{
    public static clast DoubleExtension
    {
        public static long ToLong(this double @this)
        {
            return Convert.ToInt64(@this);
        }

        /// 
        /// A T extension method that check if the value is between inclusively the minValue and maxValue.
        /// 
        /// The @this to act on.
        /// The minimum value.
        /// The maximum value.
        /// true if the value is between inclusively the minValue and maxValue, otherwise false.
        public static bool InRange(this double @this, double minValue, double maxValue)
        {
            return @this.CompareTo(minValue) >= 0 && @this.CompareTo(maxValue)  Convert.ToInt32(Math.Ceiling(a));

        /// 
        ///     Returns the cosine of the specified angle.
        /// 
        /// An angle, measured in radians.
        /// The cosine of . If  is equal to , , or , this method returns .
        public static double Cos(this double d)
        {
            return Math.Cos(d);
        }

        /// 
        ///     Returns the hyperbolic cosine of the specified angle.
        /// 
        /// An angle, measured in radians.
        /// The hyperbolic cosine of . If  is equal to  or ,  is returned. If  is equal to ,  is returned.
        public static double Cosh(this double value)
        {
            return Math.Cosh(value);
        }

        /// 
        ///     Returns e raised to the specified power.
        /// 
        /// A number specifying a power.
        /// 
        ///     The number e raised to the power . If  equals  or , that value is returned. If  equals , 0 is returned.
        /// 
        public static double Exp(this double d)
        {
            return Math.Exp(d);
        }

        /// 
        ///     Returns the largest integer less than or equal to the specified double-precision floating-point number.
        /// 
        /// A double-precision floating-point number.
        /// The largest integer less than or equal to . If  is equal to , , or , that value is returned.
        public static int Floor(this double d)
        {
            return Convert.ToInt32(Math.Floor(d));
        }

        /// 
        ///     Returns the remainder resulting from the division of a specified number by another specified number.
        /// 
        /// A dividend.
        /// A divisor.
        /// 
        ///     A number equal to  - ( Q), where Q is the quotient of  /  rounded to the nearest integer (if  /  falls
        ///     halfway between two integers, the even integer is returned).If  - ( Q) is zero, the value +0 is returned if
        ///     is positive, or -0 if  is negative.If  = 0,  is returned.
        /// 
        public static double IEEERemainder(this double x, double y)
        {
            return Math.IEEERemainder(x, y);
        }

        /// 
        ///     Returns the natural (base e) logarithm of a specified number.
        /// 
        /// The number whose logarithm is to be found.
        /// 
        ///     One of the values in the following table.  parameterReturn value Positive The natural logarithm of ; that is,
        ///     ln , or log eZero Negative Equal to Equal to.
        /// 
        public static double Log(this double d)
        {
            return Math.Log(d);
        }

        /// 
        ///     Returns the logarithm of a specified number in a specified base.
        /// 
        /// The number whose logarithm is to be found.
        /// The base of the logarithm.
        /// 
        ///     One of the values in the following table. (+Infinity denotes , -Infinity denotes , and NaN denotes .)Return
        ///     value> 0(0 << 1) -or-(> 1)lognewBase(a)< 0(any value)NaN(any value)< 0NaN != 1 = 0NaN != 1
        ///     = +InfinityNaN = NaN(any value)NaN(any value) = NaNNaN(any value) = 1NaN = 00 << 1 +Infinity = 0> 1-
        ///     Infinity =  +Infinity0 << 1-Infinity =  +Infinity> 1+Infinity = 1 = 00 = 1 = +Infinity0.
        /// 
        public static double Log(this double d, double newBase)
        {
            return Math.Log(d, newBase);
        }

        /// 
        ///     Returns the base 10 logarithm of a specified number.
        /// 
        /// A number whose logarithm is to be found.
        /// 
        ///     One of the values in the following table.  parameter Return value Positive The base 10 log of ; that is, log
        ///     10. Zero Negative Equal to Equal to.
        /// 
        public static double Log10(this double d)
        {
            return Math.Log10(d);
        }

        /// 
        ///     Returns the larger of two double-precision floating-point numbers.
        /// 
        /// The first of two double-precision floating-point numbers to compare.
        /// The second of two double-precision floating-point numbers to compare.
        /// Parameter  or , whichever is larger. If , , or both  and  are equal to ,  is returned.
        public static double Max(this double val1, double val2)
        {
            return Math.Max(val1, val2);
        }

        /// 
        ///     Returns the smaller of two double-precision floating-point numbers.
        /// 
        /// The first of two double-precision floating-point numbers to compare.
        /// The second of two double-precision floating-point numbers to compare.
        /// Parameter  or , whichever is smaller. If , , or both  and  are equal to ,  is returned.
        public static double Min(this double val1, double val2) => Math.Min(val1, val2);

        /// 
        ///     Returns a specified number raised to the specified power.
        /// 
        /// A double-precision floating-point number to be raised to a power.
        /// A double-precision floating-point number that specifies a power.
        /// The number  raised to the power .
        public static double Pow(this double x, double y) => Math.Pow(x, y);

        /// 
        ///     Rounds a double-precision floating-point value to the nearest integral value.
        /// 
        /// A double-precision floating-point number to be rounded.
        /// 
        ///     The integer nearest . If the fractional component of  is halfway between two integers, one of which is even
        ///     and the other odd, then the even number is returned. Note that this method returns a  instead of an integral
        ///     type.
        /// 
        public static double Round(this double a) => Math.Round(a);

        /// 
        ///     Rounds a double-precision floating-point value to a specified number of fractional digits.
        /// 
        /// A double-precision floating-point number to be rounded.
        /// The number of fractional digits in the return value.
        /// The number nearest to  that contains a number of fractional digits equal to .
        public static double Round(this double a, int digits) => Math.Round(a, digits);

        /// 
        ///     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 numbers.
        /// 
        /// A double-precision floating-point number to be rounded.
        /// Specification for how to round  if it is midway between two other numbers.
        /// 
        ///     The integer nearest . If  is halfway between two integers, one of which is even and the other odd, then
        ///     determines which of the two is returned.
        /// 
        public static double Round(this double a, MidpointRounding mode) => Math.Round(a, mode);

        /// 
        ///     Rounds a double-precision floating-point value to a specified number of fractional digits. A parameter
        ///     specifies how to round the value if it is midway between two numbers.
        /// 
        /// A double-precision floating-point number to be rounded.
        /// The number of fractional digits in the return value.
        /// Specification for how to round  if it is midway between two other numbers.
        /// 
        ///     The number nearest to  that has a number of fractional digits equal to . If  has fewer fractional digits than
        ///     ,  is returned unchanged.
        /// 
        public static double Round(this double value, int digits, MidpointRounding mode) => Math.Round(value, digits, mode);

        /// 
        ///     Returns a value indicating the sign of a double-precision floating-point number.
        /// 
        /// A signed number.
        /// 
        ///     A number that indicates the sign of , as shown in the following table.Return value Meaning -1  is less than
        ///     zero. 0  is equal to zero. 1  is greater than zero.
        /// 
        public static int Sign(this double value) => Math.Sign(value);

        /// 
        ///     Returns the sine of the specified angle.
        /// 
        /// An angle, measured in radians.
        /// The sine of . If  is equal to , , or , this method returns .
        public static double Sin(this double a)
        {
            return Math.Sin(a);
        }

        /// 
        ///     Returns the hyperbolic sine of the specified angle.
        /// 
        /// An angle, measured in radians.
        /// The hyperbolic sine of . If  is equal to , , or , this method returns a  equal to .
        public static double Sinh(this double value)
        {
            return Math.Sinh(value);
        }

        /// 
        ///     Returns the square root of a specified number.
        /// 
        /// The number whose square root is to be found.
        /// 
        ///     One of the values in the following table.  parameter Return value Zero or positive The positive square root
        ///     of . Negative Equals Equals.
        /// 
        public static double Sqrt(this double d)
        {
            return Math.Sqrt(d);
        }

        /// 
        ///     Returns the tangent of the specified angle.
        /// 
        /// An angle, measured in radians.
        /// The tangent of . If  is equal to , , or , this method returns .
        public static double Tan(this double a)
        {
            return Math.Tan(a);
        }

        /// 
        ///     Returns the hyperbolic tangent of the specified angle.
        /// 
        /// An angle, measured in radians.
        /// 
        ///     The hyperbolic tangent of . If  is equal to , this method returns -1. If value is equal to , this method
        ///     returns 1. If  is equal to , this method returns .
        /// 
        public static double Tanh(this double value)
        {
            return Math.Tanh(value);
        }

        /// 
        ///     Calculates the integral part of a specified double-precision floating-point number.
        /// 
        /// A number to truncate.
        /// 
        ///     The integral part of ; that is, the number that remains after any fractional digits have been discarded, or
        ///     one of the values listed in the following table. Return value.
        /// 
        public static double Truncate(this double d) => Math.Truncate(d);

        /// 
        ///     A Double extension method that converts the @this to a moneyFormat.
        /// 
        /// The @this to act on.
        /// @this as a Double.
        public static double ToMoney(this double @this) => Math.Round(@this, 2);
    }
}