MathHelper

Ecng.Common

Provides various mathematical helper methods and extension methods for numeric types.

方法

Abs
public static decimal Abs(decimal value)
result = MathHelper.Abs(value)

Returns the absolute value of the decimal .

value
The decimal value.

返回值: The absolute value.

Abs
public static short Abs(short value)
result = MathHelper.Abs(value)

Returns the absolute value of the short .

value
The short integer.

返回值: The absolute value.

Abs
public static int Abs(int value)
result = MathHelper.Abs(value)

Returns the absolute value of the integer .

value
The integer value.

返回值: The absolute value.

Abs
public static long Abs(long value)
result = MathHelper.Abs(value)

Returns the absolute value of the long integer .

value
The long integer.

返回值: The absolute value.

Abs
public static sbyte Abs(sbyte value)
result = MathHelper.Abs(value)

Returns the absolute value of the sbyte .

value
The sbyte value.

返回值: The absolute value.

Abs
public static float Abs(float value)
result = MathHelper.Abs(value)

Returns the absolute value of the float .

value
The float value.

返回值: The absolute value.

Abs
public static double Abs(double value)
result = MathHelper.Abs(value)

Returns the absolute value of the double .

value
The double value.

返回值: The absolute value.

Abs
public static TimeSpan Abs(TimeSpan value)
result = MathHelper.Abs(value)

Returns a TimeSpan whose ticks are the absolute value of the original TimeSpan's ticks.

value
The TimeSpan value.

返回值: The TimeSpan with absolute ticks.

Acos
public static decimal Acos(decimal value)
result = MathHelper.Acos(value)

Returns the angle whose cosine is the specified decimal value.

value
A decimal value representing a cosine.

返回值: The angle, in radians, whose cosine is the specified value.

Acos
public static double Acos(double value)
result = MathHelper.Acos(value)

Returns the angle whose cosine is the specified value.

value
A double value representing a cosine.

返回值: The angle, in radians, whose cosine is the specified value.

Asin
public static decimal Asin(decimal value)
result = MathHelper.Asin(value)

Returns the angle whose sine is the specified decimal value.

value
A decimal value representing a sine.

返回值: The angle, in radians, whose sine is the specified value.

Asin
public static double Asin(double value)
result = MathHelper.Asin(value)

Returns the angle whose sine is the specified value.

value
A double value representing a sine.

返回值: The angle, in radians, whose sine is the specified value.

AsRaw
public static long AsRaw(double value)
result = MathHelper.AsRaw(value)

Gets the raw 64-bit integer representation of the double value.

value
The double value.

返回值: The 64-bit integer representation.

AsRaw
public static double AsRaw(long value)
result = MathHelper.AsRaw(value)

Converts a 64-bit integer representation to a double value.

value
The 64-bit integer representation.

返回值: The double value.

AsRaw
public static float AsRaw(int value)
result = MathHelper.AsRaw(value)

Converts an integer value to a single-precision float via a byte array conversion.

value
The integer value.

返回值: The float value.

AsRaw
public static int AsRaw(float value)
result = MathHelper.AsRaw(value)

Converts a float value to its raw 32-bit integer representation.

value
The float value.

返回值: The 32-bit integer representation.

Atan
public static decimal Atan(decimal value)
result = MathHelper.Atan(value)

Returns the angle whose tangent is the specified decimal value.

value
A decimal value representing a tangent.

返回值: The angle, in radians, whose tangent is the specified value.

Atan
public static double Atan(double value)
result = MathHelper.Atan(value)

Returns the angle whose tangent is the specified value.

value
A double value representing a tangent.

返回值: The angle, in radians, whose tangent is the specified value.

Atan2
public static decimal Atan2(decimal y, decimal x)
result = MathHelper.Atan2(y, x)

Returns the angle whose tangent is the quotient of two specified decimal numbers.

y
The y coordinate.
x
The x coordinate.

返回值: The angle, in radians, whose tangent is the quotient of y and x.

Atan2
public static double Atan2(double y, double x)
result = MathHelper.Atan2(y, x)

Returns the angle whose tangent is the quotient of two specified double numbers.

y
The y coordinate.
x
The x coordinate.

返回值: The angle, in radians, whose tangent is the quotient of y and x.

BigMul
public static long BigMul(int x, int y)
result = MathHelper.BigMul(x, y)

Returns the full product of two integers.

x
The first integer.
y
The second integer.

返回值: The product as a long.

Ceiling
public static int Ceiling(float value)
result = MathHelper.Ceiling(value)

Returns the smallest integer greater than or equal to the float value.

value
The float value.

返回值: The ceiling integer.

Ceiling
public static decimal Ceiling(decimal value)
result = MathHelper.Ceiling(value)

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

value
The decimal value.

返回值: The ceiled value.

Ceiling
public static decimal Ceiling(decimal value, decimal step)
result = MathHelper.Ceiling(value, step)

Returns the smallest multiple of greater than or equal to the specified .

value
The decimal value.
step
The step size.

返回值: The ceiled value.

Ceiling
public static long Ceiling(double value)
result = MathHelper.Ceiling(value)

Returns the smallest integer greater than or equal to the specified double as a long.

value
The double value.

返回值: The ceiled value as long.

Cos
public static double Cos(double value)
result = MathHelper.Cos(value)

Returns the cosine of the specified double angle.

value
An angle, measured in radians.

返回值: The cosine of the angle.

Cos
public static decimal Cos(decimal value)
result = MathHelper.Cos(value)

Returns the cosine of the specified decimal angle.

value
An angle, measured in radians (as decimal).

返回值: The cosine of the angle as a decimal.

Cosh
public static double Cosh(double value)
result = MathHelper.Cosh(value)

Returns the hyperbolic cosine of the specified double angle.

value
An angle, measured in radians.

返回值: The hyperbolic cosine of the angle.

Cosh
public static decimal Cosh(decimal value)
result = MathHelper.Cosh(value)

Returns the hyperbolic cosine of the specified decimal angle.

value
An angle, measured in radians (as decimal).

返回值: The hyperbolic cosine of the angle as a decimal.

DivRem
public static long DivRem(long a, long b, long result)
result = MathHelper.DivRem(a, b, result)

Computes the quotient and remainder of the division of two long integers.

a
The dividend.
b
The divisor.
result
When the method returns, contains the remainder.

返回值: The quotient.

DivRem
public static int DivRem(int a, int b, int result)
result = MathHelper.DivRem(a, b, result)

Computes the quotient and remainder of the division of two integers.

a
The dividend.
b
The divisor.
result
When the method returns, contains the remainder.

返回值: The quotient.

Exp
public static double Exp(double value)
result = MathHelper.Exp(value)

Returns e raised to the specified double power.

value
A double exponent.

返回值: The value of e raised to the specified power.

Exp
public static decimal Exp(decimal value)
result = MathHelper.Exp(value)

Returns e raised to the specified decimal power.

value
A decimal exponent.

返回值: The value of e raised to the specified power as a decimal.

ExtractMantissaExponent
public static void ExtractMantissaExponent(double value, long mantissa, int exponent)
MathHelper.ExtractMantissaExponent(value, mantissa, exponent)

Extracts the normalized mantissa and exponent from the double value.

value
The double value.
mantissa
The extracted mantissa (negative for negative values).
exponent
The extracted exponent.
ExtractMantissaExponent
public static ValueTuple<long, int> ExtractMantissaExponent(decimal value)
result = MathHelper.ExtractMantissaExponent(value)

Extracts the mantissa and exponent from the decimal value.

value
The decimal value.

返回值: The extracted mantissa and exponent.

Floor
public static int Floor(float value)
result = MathHelper.Floor(value)

Returns the largest integer less than or equal to the float value.

value
The float value.

返回值: The floor integer.

Floor
public static decimal Floor(decimal value, decimal step)
result = MathHelper.Floor(value, step)

Returns the largest multiple of less than or equal to the specified .

value
The decimal value.
step
The step size.

返回值: The floored value.

Floor
public static double Floor(double value, double step)
result = MathHelper.Floor(value, step)

Returns the largest multiple of less than or equal to the double .

value
The double value.
step
The step size.

返回值: The floored value.

Floor
public static float Floor(float value, float step)
result = MathHelper.Floor(value, step)

Returns the largest multiple of less than or equal to the float .

value
The float value.
step
The step size.

返回值: The floored value.

Floor
public static long Floor(long value, long step)
result = MathHelper.Floor(value, step)

Returns the largest multiple of less than or equal to the long integer .

value
The long integer value.
step
The step size.

返回值: The floored value.

Floor
public static int Floor(int value, int step)
result = MathHelper.Floor(value, step)

Returns the largest multiple of less than or equal to the integer .

value
The integer value.
step
The step size.

返回值: The floored value.

Floor
public static long Floor(double value)
result = MathHelper.Floor(value)

Returns the largest integer less than or equal to the specified double as a long.

value
The double value.

返回值: The floored value as long.

Floor
public static decimal Floor(decimal value)
result = MathHelper.Floor(value)

Returns the largest integer less than or equal to the specified .

value
The decimal value.

返回值: The floored value.

GetBit
public static bool GetBit(int value, int index)
result = MathHelper.GetBit(value, index)

Gets the state of the bit at the specified index in an integer.

value
The integer value.
index
The bit index (0-based).

返回值: True if the bit is set; otherwise, false.

GetBit
public static bool GetBit(long value, int index)
result = MathHelper.GetBit(value, index)

Gets the state of the bit at the specified index in a long value.

value
The long value.
index
The bit index (0-based).

返回值: True if the bit is set; otherwise, false.

GetBit
public static bool GetBit(byte value, int index)
result = MathHelper.GetBit(value, index)

Determines whether the bit at the specified zero-based index in the byte is set.

value
The byte value.
index
The zero-based index of the bit to test.

返回值: true if the specified bit is set; otherwise, false.

GetCachedDecimals
public static int GetCachedDecimals(decimal value)
result = MathHelper.GetCachedDecimals(value)

Gets the effective scale (number of significant decimal places) of the decimal value, using caching for performance.

value
The decimal value.

返回值: The effective scale of the decimal.

GetDecimalInfo
public static DecimalInfo GetDecimalInfo(decimal value)
result = MathHelper.GetDecimalInfo(value)

Retrieves detailed information about the decimal value, including mantissa, precision, scale, and trailing zeros.

value
The decimal value.

返回值: A DecimalInfo structure containing detailed decimal information.

GetDigitCount
public static int GetDigitCount(long x)
result = MathHelper.GetDigitCount(x)

Returns the number of digits in a positive long integer.

x
The positive long integer value.

返回值: The digit count.

GetDigitCount
public static int GetDigitCount(int x)
result = MathHelper.GetDigitCount(x)

Returns the number of digits in a positive integer.

x
The positive integer value.

返回值: The digit count.

GetMiddle
public static decimal GetMiddle(decimal from, decimal to)
result = MathHelper.GetMiddle(from, to)

Calculates the middle (average) value between two decimal values.

from
The first value.
to
The second value.

返回值: The middle value as a decimal.

GetMiddle
public static decimal GetMiddle(double from, double to)
result = MathHelper.GetMiddle(from, to)

Calculates the middle (average) value between two double values.

from
The first value.
to
The second value.

返回值: The middle value as a decimal.

GetMiddle
public static decimal GetMiddle(float from, float to)
result = MathHelper.GetMiddle(from, to)

Calculates the middle (average) value between two float values.

from
The first value.
to
The second value.

返回值: The middle value as a decimal.

GetMiddle
public static decimal GetMiddle(long from, long to)
result = MathHelper.GetMiddle(from, to)

Calculates the middle (average) value between two long integer values.

from
The first value.
to
The second value.

返回值: The middle value as a decimal.

GetMiddle
public static decimal GetMiddle(int from, int to)
result = MathHelper.GetMiddle(from, to)

Calculates the middle (average) value between two integer values.

from
The first value.
to
The second value.

返回值: The middle value as a decimal.

GetMiddle
public static decimal GetMiddle(short from, short to)
result = MathHelper.GetMiddle(from, to)

Calculates the middle (average) value between two short values.

from
The first value.
to
The second value.

返回值: The middle value as a decimal.

GetParts
public static float[] GetParts(float value)
result = MathHelper.GetParts(value)

Splits a float value into its integer and fractional parts.

value
The float value.

返回值: An array with the integer part and the fractional remainder.

GetParts
public static double[] GetParts(double value)
result = MathHelper.GetParts(value)

Splits a double value into its integer and fractional parts.

value
The double value.

返回值: An array with the integer part and the fractional remainder.

GetParts
public static int[] GetParts(long value)
result = MathHelper.GetParts(value)

Extracts the high and low parts of a long value.

value
The long value.

返回值: An array with two integers: the low and high parts.

GetRoots
public static double[] GetRoots(double a, double b, double c)
result = MathHelper.GetRoots(a, b, c)

Calculates the real roots of a quadratic equation given coefficients a, b, and c.

a
Coefficient a.
b
Coefficient b.
c
Coefficient c.

返回值: An array containing the two roots if the discriminant is non-negative; otherwise, an empty array.

HasBits
public static bool HasBits(long value, long part)
result = MathHelper.HasBits(value, part)

Determines whether the specified bits are set in the long integer value.

value
The long integer value.
part
The bits to test.

返回值: true if all specified bits are set; otherwise, false.

HasBits
public static bool HasBits(int value, int part)
result = MathHelper.HasBits(value, part)

Determines whether the specified bits are set in the integer value.

value
The integer value.
part
The bits to test.

返回值: true if all specified bits are set; otherwise, false.

IsInfinity
public static bool IsInfinity(double value)
result = MathHelper.IsInfinity(value)

Determines if the double value represents infinity.

value
The double value.

返回值: true if the value is infinity; otherwise, false.

IsInfinity
public static bool IsInfinity(float value)
result = MathHelper.IsInfinity(value)

Determines if the float value represents infinity.

value
The float value.

返回值: true if the value is infinity; otherwise, false.

IsNaN
public static bool IsNaN(double value)
result = MathHelper.IsNaN(value)

Determines if the double value is NaN (Not a Number).

value
The double value.

返回值: true if the value is NaN; otherwise, false.

IsNaN
public static bool IsNaN(float value)
result = MathHelper.IsNaN(value)

Determines if the float value is NaN (Not a Number).

value
The float value.

返回值: true if the value is NaN; otherwise, false.

IsNegativeInfinity
public static bool IsNegativeInfinity(float value)
result = MathHelper.IsNegativeInfinity(value)

Determines if the float value represents negative infinity.

value
The float value.

返回值: true if the value is negative infinity; otherwise, false.

IsNegativeInfinity
public static bool IsNegativeInfinity(double value)
result = MathHelper.IsNegativeInfinity(value)

Determines if the double value represents negative infinity.

value
The double value.

返回值: true if the value is negative infinity; otherwise, false.

IsPositiveInfinity
public static bool IsPositiveInfinity(float value)
result = MathHelper.IsPositiveInfinity(value)

Determines if the float value represents positive infinity.

value
The float value.

返回值: true if the value is positive infinity; otherwise, false.

IsPositiveInfinity
public static bool IsPositiveInfinity(double value)
result = MathHelper.IsPositiveInfinity(value)

Determines if the double value represents positive infinity.

value
The double value.

返回值: true if the value is positive infinity; otherwise, false.

Log
public static decimal Log(decimal value, decimal newBase)
result = MathHelper.Log(value, newBase)

Returns the logarithm of a decimal value in the specified base.

value
The decimal value.
newBase
The base of the logarithm.

返回值: The logarithm of the value in the specified base as a decimal.

Log
public static double Log(double value)
result = MathHelper.Log(value)

Returns the natural logarithm of a double value.

value
The double value.

返回值: The natural logarithm of the value.

Log
public static decimal Log(decimal value)
result = MathHelper.Log(value)

Returns the natural logarithm of a decimal value.

value
The decimal value.

返回值: The natural logarithm of the value as a decimal.

Log
public static double Log(double value, double newBase)
result = MathHelper.Log(value, newBase)

Returns the logarithm of a double value in the specified base.

value
The double value.
newBase
The base of the logarithm.

返回值: The logarithm of value in the specified base.

Log10
public static decimal Log10(decimal value)
result = MathHelper.Log10(value)

Returns the base 10 logarithm of a decimal value.

value
The decimal value.

返回值: The base 10 logarithm of the value as a decimal.

Log10
public static double Log10(double value)
result = MathHelper.Log10(value)

Returns the base 10 logarithm of a double value.

value
The double value.

返回值: The base 10 logarithm of the value.

Max
public static decimal Max(decimal v1, decimal v2, decimal v3, decimal v4)
result = MathHelper.Max(v1, v2, v3, v4)

Returns the largest of four decimal values.

Max
public static decimal Max(decimal v1, decimal v2, decimal v3, decimal v4, decimal v5)
result = MathHelper.Max(v1, v2, v3, v4, v5)

Returns the largest of five decimal values.

Max
public static DateTimeOffset Max(DateTimeOffset value1, DateTimeOffset value2)
result = MathHelper.Max(value1, value2)

Returns the maximum of two DateTimeOffset values.

value1
The first DateTimeOffset value.
value2
The second DateTimeOffset value.

返回值: The later DateTimeOffset.

Max
public static decimal Max(decimal v1, decimal v2, decimal v3)
result = MathHelper.Max(v1, v2, v3)

Returns the largest of three decimal values.

Max
public static decimal Max(decimal value1, decimal value2)
result = MathHelper.Max(value1, value2)

Returns the maximum of two decimal values.

value1
The first decimal value.
value2
The second decimal value.

返回值: The larger decimal value.

Max
public static double Max(double value1, double value2)
result = MathHelper.Max(value1, value2)

Returns the maximum of two double values.

value1
The first double value.
value2
The second double value.

返回值: The larger double value.

Max
public static float Max(float value1, float value2)
result = MathHelper.Max(value1, value2)

Returns the maximum of two float values.

value1
The first float value.
value2
The second float value.

返回值: The larger float value.

Max
public static byte Max(byte value1, byte value2)
result = MathHelper.Max(value1, value2)

Returns the maximum of two byte values.

value1
The first byte value.
value2
The second byte value.

返回值: The larger byte value.

Max
public static sbyte Max(sbyte value1, sbyte value2)
result = MathHelper.Max(value1, value2)

Returns the maximum of two sbyte values.

value1
The first sbyte value.
value2
The second sbyte value.

返回值: The larger sbyte value.

Max
public static ulong Max(ulong value1, ulong value2)
result = MathHelper.Max(value1, value2)

Returns the maximum of two ulong values.

value1
The first ulong value.
value2
The second ulong value.

返回值: The larger ulong value.

Max
public static long Max(long value1, long value2)
result = MathHelper.Max(value1, value2)

Returns the maximum of two long values.

value1
The first long value.
value2
The second long value.

返回值: The larger long value.

Max
public static TimeSpan Max(TimeSpan value1, TimeSpan value2)
result = MathHelper.Max(value1, value2)

Returns the maximum of two TimeSpan values.

value1
The first TimeSpan value.
value2
The second TimeSpan value.

返回值: The longer TimeSpan.

Max
public static uint Max(uint value1, uint value2)
result = MathHelper.Max(value1, value2)

Returns the maximum of two uint values.

value1
The first uint value.
value2
The second uint value.

返回值: The larger uint value.

Max
public static ushort Max(ushort value1, ushort value2)
result = MathHelper.Max(value1, value2)

Returns the maximum of two ushort values.

value1
The first ushort value.
value2
The second ushort value.

返回值: The larger ushort value.

Max
public static short Max(short value1, short value2)
result = MathHelper.Max(value1, value2)

Returns the maximum of two short values.

value1
The first short value.
value2
The second short value.

返回值: The larger short value.

Max
public static int Max(int value1, int value2)
result = MathHelper.Max(value1, value2)

Returns the maximum of two int values.

value1
The first int value.
value2
The second int value.

返回值: The larger int value.

Max
public static DateTime Max(DateTime value1, DateTime value2)
result = MathHelper.Max(value1, value2)

Returns the maximum of two DateTime values.

value1
The first DateTime value.
value2
The second DateTime value.

返回值: The later DateTime.

Min
public static DateTimeOffset Min(DateTimeOffset value1, DateTimeOffset value2)
result = MathHelper.Min(value1, value2)

Returns the minimum of two DateTimeOffset values.

value1
The first DateTimeOffset value.
value2
The second DateTimeOffset value.

返回值: The smaller DateTimeOffset value.

Min
public static DateTime Min(DateTime value1, DateTime value2)
result = MathHelper.Min(value1, value2)

Returns the earlier DateTime.

value1
The first DateTime.
value2
The second DateTime.

返回值: The minimum DateTime.

Min
public static TimeSpan Min(TimeSpan value1, TimeSpan value2)
result = MathHelper.Min(value1, value2)

Returns the earlier TimeSpan.

value1
The first TimeSpan.
value2
The second TimeSpan.

返回值: The minimum TimeSpan.

Min
public static decimal Min(decimal v1, decimal v2, decimal v3, decimal v4, decimal v5)
result = MathHelper.Min(v1, v2, v3, v4, v5)

Returns the smallest of five decimal values.

Min
public static decimal Min(decimal v1, decimal v2, decimal v3, decimal v4)
result = MathHelper.Min(v1, v2, v3, v4)

Returns the smallest of four decimal values.

Min
public static decimal Min(decimal v1, decimal v2, decimal v3)
result = MathHelper.Min(v1, v2, v3)

Returns the smallest of three decimal values.

Min
public static decimal Min(decimal value1, decimal value2)
result = MathHelper.Min(value1, value2)

Returns the smaller of two decimal values.

value1
The first decimal value.
value2
The second decimal value.

返回值: The minimum value.

Min
public static uint Min(uint value1, uint value2)
result = MathHelper.Min(value1, value2)

Returns the smaller of two uint values.

value1
The first uint value.
value2
The second uint value.

返回值: The minimum value.

Min
public static double Min(double value1, double value2)
result = MathHelper.Min(value1, value2)

Returns the smaller of two double values.

value1
The first double value.
value2
The second double value.

返回值: The minimum value.

Min
public static float Min(float value1, float value2)
result = MathHelper.Min(value1, value2)

Returns the smaller of two float values.

value1
The first float value.
value2
The second float value.

返回值: The minimum value.

Min
public static byte Min(byte value1, byte value2)
result = MathHelper.Min(value1, value2)

Returns the smaller of two byte values.

value1
The first byte value.
value2
The second byte value.

返回值: The minimum value.

Min
public static int Min(int value1, int value2)
result = MathHelper.Min(value1, value2)

Returns the smaller of two integer values.

value1
The first integer value.
value2
The second integer value.

返回值: The minimum value.

Min
public static sbyte Min(sbyte value1, sbyte value2)
result = MathHelper.Min(value1, value2)

Returns the smaller of two sbyte values.

value1
The first sbyte value.
value2
The second sbyte value.

返回值: The minimum value.

Min
public static ushort Min(ushort value1, ushort value2)
result = MathHelper.Min(value1, value2)

Returns the smaller of two ushort values.

value1
The first ushort value.
value2
The second ushort value.

返回值: The minimum value.

Min
public static short Min(short value1, short value2)
result = MathHelper.Min(value1, value2)

Returns the smaller of two short values.

value1
The first short value.
value2
The second short value.

返回值: The minimum value.

Min
public static long Min(long value1, long value2)
result = MathHelper.Min(value1, value2)

Returns the smaller of two long values.

value1
The first long value.
value2
The second long value.

返回值: The minimum value.

Min
public static ulong Min(ulong value1, ulong value2)
result = MathHelper.Min(value1, value2)

Returns the smaller of two ulong values.

value1
The first ulong value.
value2
The second ulong value.

返回值: The minimum value.

Pow
public static double Pow(double x, double y)
result = MathHelper.Pow(x, y)

Raises a double number to the power of a double exponent.

x
The base double value.
y
The exponent double value.

返回值: The resulting double value.

Pow
public static int Pow(int x, int y)
result = MathHelper.Pow(x, y)

Raises an int number to the power of an int exponent.

x
The base int value.
y
The exponent int value.

返回值: The resulting int value.

Pow
public static decimal Pow(decimal x, decimal y)
result = MathHelper.Pow(x, y)

Raises a decimal number to the power of another decimal number.

x
The base decimal value.
y
The exponent decimal value.

返回值: The resulting decimal value.

Remainder
public static double Remainder(double x, double y)
result = MathHelper.Remainder(x, y)

Returns the IEEE remainder of two double values.

x
The dividend.
y
The divisor.

返回值: The remainder after division.

Remainder
public static decimal Remainder(decimal x, decimal y)
result = MathHelper.Remainder(x, y)

Returns the IEEE remainder of two decimal values.

x
The dividend.
y
The divisor.

返回值: The remainder after division as a decimal.

RemoveTrailingZeros
public static decimal RemoveTrailingZeros(decimal value)
result = MathHelper.RemoveTrailingZeros(value)

Removes insignificant trailing zeros from the decimal value.

value
The decimal value.

返回值: The decimal value without trailing zeros.

Round
public static decimal Round(decimal value, int digits)
result = MathHelper.Round(value, digits)

Rounds the specified to a specified number of fractional digits.

value
The decimal value.
digits
The number of fractional digits.

返回值: The rounded value.

Round
public static double Round(double value, MidpointRounding rounding)
result = MathHelper.Round(value, rounding)

Rounds the double using the specified rounding mode.

value
The double value.
rounding
The rounding mode.

返回值: The rounded value.

Round
public static double Round(double value, int digits, MidpointRounding rounding)
result = MathHelper.Round(value, digits, rounding)

Rounds the double to a specified number of digits using the specified rounding mode.

value
The double value.
digits
The number of fractional digits.
rounding
The rounding mode.

返回值: The rounded value.

Round
public static double Round(double value)
result = MathHelper.Round(value)

Rounds the double value to the nearest integer.

value
The double value to round.

返回值: The rounded double value.

Round
public static decimal Round(decimal value, decimal step, int? digits, MidpointRounding rounding)
result = MathHelper.Round(value, step, digits, rounding)

Rounds the specified to the nearest multiple of , and optionally rounds to the specified number of digits.

value
The decimal value.
step
The step size.
digits
Optional number of fractional digits.
rounding
The rounding mode (defaults to ToEven).

返回值: The rounded value.

Round
public static decimal Round(decimal value, MidpointRounding rounding)
result = MathHelper.Round(value, rounding)

Rounds the specified using the specified rounding mode.

value
The decimal value.
rounding
The rounding mode.

返回值: The rounded value.

Round
public static decimal Round(decimal value, int digits, MidpointRounding rounding)
result = MathHelper.Round(value, digits, rounding)

Rounds the specified to the specified number of fractional digits using the specified rounding mode.

value
The decimal value.
digits
The number of fractional digits.
rounding
The rounding mode.

返回值: The rounded value.

Round
public static double Round(double value, int digits)
result = MathHelper.Round(value, digits)

Rounds the double value to the specified number of fractional digits.

value
The double value to round.
digits
The number of decimal places to round to.

返回值: The rounded double value.

Round
public static decimal Round(decimal value)
result = MathHelper.Round(value)

Rounds the specified to the nearest integer.

value
The decimal value.

返回值: The rounded value.

Round4Expression
public static decimal Round4Expression(decimal value, decimal digits)
result = MathHelper.Round4Expression(value, digits)

Rounds the specified to a specified number of fractional digits.

value
The decimal value.
digits
The number of fractional digits (as decimal, will be converted to int).

返回值: The rounded value.

RoundToNearest
public static double RoundToNearest(double value)
result = MathHelper.RoundToNearest(value)

Rounds the double value to the nearest significant digit.

value
The double value.

返回值: The rounded value.

SetBit
public static byte SetBit(byte value, int index, bool bit)
result = MathHelper.SetBit(value, index, bit)

Sets or clears the bit at the specified index in the byte.

value
The byte value.
index
The zero-based index of the bit to modify.
bit
If set to true, the bit is set; otherwise, it is cleared.

返回值: The modified byte value.

SetBit
public static int SetBit(int value, int index, bool bit)
result = MathHelper.SetBit(value, index, bit)

Sets or clears the bit at the specified index in an integer.

value
The integer value.
index
The bit index (0-based).
bit
True to set the bit; false to clear it.

返回值: The resulting integer value after modification.

SetBit
public static long SetBit(long value, int index, bool bit)
result = MathHelper.SetBit(value, index, bit)

Sets or clears the bit at the specified index in a long value.

value
The long value.
index
The bit index (0-based).
bit
True to set the bit; false to clear it.

返回值: The resulting long value after modification.

Sign
public static int Sign(float value)
result = MathHelper.Sign(value)

Returns the sign of a float value.

value
The float value.

返回值: -1, 0, or 1 depending on the sign of the value.

Sign
public static int Sign(sbyte value)
result = MathHelper.Sign(value)

Returns the sign of a sbyte value.

value
The sbyte value.

返回值: -1, 0, or 1 depending on the sign of the value.

Sign
public static int Sign(double value)
result = MathHelper.Sign(value)

Returns the sign of a double value.

value
The double value.

返回值: -1, 0, or 1 depending on the sign of the value.

Sign
public static int Sign(decimal value)
result = MathHelper.Sign(value)

Returns the sign of a decimal value.

value
The decimal value.

返回值: -1, 0, or 1 depending on the sign of the value.

Sign
public static int Sign(TimeSpan value)
result = MathHelper.Sign(value)

Returns the sign of a TimeSpan value.

value
The TimeSpan value.

返回值: -1, 0, or 1 depending on the sign of the Ticks.

Sign
public static int Sign(long value)
result = MathHelper.Sign(value)

Returns the sign of a long value.

value
The long value.

返回值: -1, 0, or 1 depending on the sign of the value.

Sign
public static int Sign(int value)
result = MathHelper.Sign(value)

Returns the sign of an int value.

value
The int value.

返回值: -1, 0, or 1 depending on the sign of the value.

Sign
public static int Sign(short value)
result = MathHelper.Sign(value)

Returns the sign of a short value.

value
The short value.

返回值: -1, 0, or 1 depending on the sign of the value.

Sin
public static decimal Sin(decimal value)
result = MathHelper.Sin(value)

Returns the sine of the specified decimal angle.

value
An angle, measured in radians (as decimal).

返回值: The sine of the angle as a decimal.

Sin
public static double Sin(double value)
result = MathHelper.Sin(value)

Returns the sine of the specified double angle.

value
An angle, measured in radians.

返回值: The sine of the angle.

Sinh
public static decimal Sinh(decimal value)
result = MathHelper.Sinh(value)

Returns the hyperbolic sine of the specified decimal angle.

value
An angle, measured in radians (as decimal).

返回值: The hyperbolic sine of the angle as a decimal.

Sinh
public static double Sinh(double value)
result = MathHelper.Sinh(value)

Returns the hyperbolic sine of the specified double angle.

value
An angle, measured in radians.

返回值: The hyperbolic sine of the angle.

Sqrt
public static decimal Sqrt(decimal value)
result = MathHelper.Sqrt(value)

Returns the square root of the decimal value.

value
The decimal value.

返回值: The square root of the value.

Sqrt
public static double Sqrt(double value)
result = MathHelper.Sqrt(value)

Returns the square root of the double value.

value
The double value.

返回值: The square root of the value.

Tan
public static double Tan(double value)
result = MathHelper.Tan(value)

Returns the tangent of the specified double angle.

value
An angle, measured in radians.

返回值: The tangent of the angle.

Tan
public static decimal Tan(decimal value)
result = MathHelper.Tan(value)

Returns the tangent of the specified decimal angle.

value
An angle, measured in radians (as decimal).

返回值: The tangent of the angle as a decimal.

Tanh
public static double Tanh(double value)
result = MathHelper.Tanh(value)

Returns the hyperbolic tangent of the specified double angle.

value
An angle, measured in radians.

返回值: The hyperbolic tangent of the angle.

Tanh
public static decimal Tanh(decimal value)
result = MathHelper.Tanh(value)

Returns the hyperbolic tangent of the specified decimal angle.

value
An angle, measured in radians (as decimal).

返回值: The hyperbolic tangent of the angle as a decimal.

ToAngles
public static double ToAngles(double radian)
result = MathHelper.ToAngles(radian)

Converts an angle in radians to degrees.

radian
The angle in radians.

返回值: The angle in degrees.

ToDecimal
public static decimal ToDecimal(long mantissa, int exponent)
result = MathHelper.ToDecimal(mantissa, exponent)

Creates a decimal value from a given mantissa and exponent by applying power-of-ten adjustments.

mantissa
The mantissa.
exponent
The exponent, where positive values scale up and negative values scale down.

返回值: The resulting decimal value.

ToDecimal
public static decimal? ToDecimal(double value)
result = MathHelper.ToDecimal(value)

Converts a double to a decimal if within the allowed range; otherwise, returns null.

value
The double value.

返回值: The converted decimal value or null when conversion is not possible.

ToDecimal
public static decimal? ToDecimal(float value)
result = MathHelper.ToDecimal(value)

Converts a float to a decimal if within the allowed range; otherwise, returns null.

value
The float value.

返回值: The converted decimal value or null when conversion is not possible.

ToRadians
public static double ToRadians(double angle)
result = MathHelper.ToRadians(angle)

Converts an angle in degrees to radians.

angle
The angle in degrees.

返回值: The angle in radians.

Truncate
public static double Truncate(double value)
result = MathHelper.Truncate(value)

Truncates the double by discarding the fractional part.

value
The double value.

返回值: The truncated value.

Truncate
public static decimal Truncate(decimal value)
result = MathHelper.Truncate(value)

Truncates the decimal by discarding the fractional part.

value
The decimal value.

返回值: The truncated value.

字段

MaxExponent
public const int MaxExponent
value = MathHelper.MaxExponent

Maximum exponent value for decimal mantissa scaling.

MinExponent
public const int MinExponent
value = MathHelper.MinExponent

Minimum exponent value for decimal mantissa scaling.