public sealed class Math
Object
Math
mscorlib
ExtendedNumerics
Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions.
System Namespace
Math Methods
Math.Abs(sbyte) Method
Math.Abs(short) Method
Math.Abs(int) Method
Math.Abs(long) Method
Math.Abs(float) Method
Math.Abs(double) Method
Math.Abs(System.Decimal) Method
Math.Acos Method
Math.Asin Method
Math.Atan Method
Math.Atan2 Method
Math.BigMul Method
Math.Ceiling Method
Math.Cos Method
Math.Cosh Method
Math.DivRem(int, int, int) Method
Math.DivRem(long, long, long) Method
Math.Exp Method
Math.Floor Method
Math.IEEERemainder Method
Math.Log(double) Method
Math.Log(double, double) Method
Math.Log10 Method
Math.Max(sbyte, sbyte) Method
Math.Max(byte, byte) Method
Math.Max(short, short) Method
Math.Max(ushort, ushort) Method
Math.Max(int, int) Method
Math.Max(uint, uint) Method
Math.Max(long, long) Method
Math.Max(ulong, ulong) Method
Math.Max(float, float) Method
Math.Max(double, double) Method
Math.Max(System.Decimal, System.Decimal) Method
Math.Min(sbyte, sbyte) Method
Math.Min(byte, byte) Method
Math.Min(short, short) Method
Math.Min(ushort, ushort) Method
Math.Min(int, int) Method
Math.Min(uint, uint) Method
Math.Min(long, long) Method
Math.Min(ulong, ulong) Method
Math.Min(float, float) Method
Math.Min(double, double) Method
Math.Min(System.Decimal, System.Decimal) Method
Math.Pow Method
Math.Round(double) Method
Math.Round(double, int) Method
Math.Round(System.Decimal) Method
Math.Sign(sbyte) Method
Math.Sign(short) Method
Math.Sign(int) Method
Math.Sign(long) Method
Math.Sign(float) Method
Math.Sign(double) Method
Math.Sign(System.Decimal) Method
Math.Sin Method
Math.Sinh Method
Math.Sqrt Method
Math.Tan Method
Math.Tanh Method
Math Fields
public static sbyte Abs(sbyte value);
Returns the absolute value of the specified SByte.
- value
- A SByte.
A SByte containing the absolute value of value.
Exception Type Condition OverflowException value equals System.SByte.MinValue.
This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Abs(System.SByte)(Int16).
CLSCompliantAttribute(false)
System.Math Class, System Namespace
public static short Abs(short value);
Returns the absolute value of the specified Int16.
- value
- A Int16.
A Int16 containing the absolute value of value.
Exception Type Condition OverflowException value equals System.Int16.MinValue.
System.Math Class, System Namespace
public static int Abs(int value);
Returns the absolute value of the specified Int32.
- value
- A Int32.
A Int32 containing the absolute value of value.
Exception Type Condition OverflowException value equals System.Int32.MinValue.
System.Math Class, System Namespace
public static long Abs(long value);
Returns the absolute value of the specified Int64.
- value
- A Int64.
A Int64 containing the absolute value of value.
Exception Type Condition OverflowException value equals System.Int64.MinValue.
System.Math Class, System Namespace
public static float Abs(float value);
Returns the absolute value of the specified Single.
- value
- A Single.
A Single containing the absolute value of value. If value is equal to System.Single.NegativeInfinity or System.Single.PositiveInfinity, returns System.Single.PositiveInfinity. If value is equal to System.Single.NaN, returns System.Single.NaN.
System.Math Class, System Namespace
public static double Abs(double value);
Returns the absolute value of the specified Double.
- value
- A Double.
A Double containing the absolute value of value. If value is equal to System.Double.NegativeInfinity or System.Double.PositiveInfinity, returns System.Double.PositiveInfinity. If value is equal to System.Double.NaN, returns System.Double.NaN.
System.Math Class, System Namespace
public static decimal Abs(decimal value);
Returns the absolute value of the specified Decimal .
- value
- A Decimal.
A Decimal containing the absolute value of value.
The following example demonstrates the System.Math.Abs(System.SByte)(Decimal) method.
using System; public class MathAbsExample { public static void Main() { Decimal d1 = Math.Abs( (Decimal)0.00 ); Decimal d2 = Math.Abs( (Decimal)(-1.23) ); Console.WriteLine("Math.Abs( (Decimal)0.00 ) returns {0}",d1); Console.WriteLine("Math.Abs( (Decimal)(-1.23) ) returns {0}",d2); } }The output is
Math.Abs( (Decimal)0.00 ) returns 0
Math.Abs( (Decimal)(-1.23) ) returns 1.23
System.Math Class, System Namespace
public static double Acos(double d);
Returns the angle whose cosine is the specified Double.
- d
- A Double representing a cosine, where -1 <= d <= 1.
A Double containing the value of an angle, , measured in radians, for which d is the cosine, such that 0 <= <= . If d < -1, d > 1, or d = System.Double.NaN, returns System.Double.NaN.
[Note: Multiply the return value by 180/ to convert from radians to degrees.]
System.Math Class, System Namespace
public static double Asin(double d);
Returns the angle whose sine is the specified Double.
- d
- A Double representing a sine, where -1 <= d <= 1.
A Double containing the value of an angle, , measured in radians, for which d is the sine, such that -/2 <= <= /2. If d < -1, d > 1, or d = System.Double.NaN, returns System.Double.NaN .
[Note: A positive return value represents a counterclockwise angle from the positive x-axis; a negative return value represents a clockwise angle.Multiply the return value by 180/ to convert from radians to degrees.
]
System.Math Class, System Namespace
public static double Atan(double d);
Returns the angle whose tangent is the specified Double.
- d
- A Double that represents a tangent.
A Double containing the value of the angle, , measured in radians, for which d is the tangent, such that -/2 <= <= /2.The following table specifies the return value if d is equal to System.Double.NaN, System.Double.NegativeInfinity, or System.Double.PositiveInfinity .
Return Value Condition System.Double.NaN d is equal to System.Double.NaN. -/2 rounded to double precision (-1.5707963267949) d is equal to System.Double.NegativeInfinity. /2 rounded to double precision (1.5707963267949) d is equal to System.Double.PositiveInfinity.
[Note: A positive return value represents a counterclockwise angle from the positive x-axis; a negative return value represents a clockwise angle.Multiply the return value by 180/ to convert from radians to degrees.
]
System.Math Class, System Namespace
public static double Atan2(double y, double x);
Returns the angle whose tangent is the quotient of two specified Double values.
- y
- A Double representing the y coordinate of a point.
- x
- A Double representing the x coordinate of a point.
A Double containing the value of an angle, , measured in radians, such that - <= <= and tan = y/x, where (x, y) is a point in the Cartesian plane.If both x and y are any combination of System.Double.NegativeInfinity and System.Double.PositiveInfinity, System.Double.NaN is returned.
If either x or y is equal to System.Double.NaN, System.Double.NaN is returned.
The following table specifies the return value if x or y is equal to System.Double.NegativeInfinity or System.Double.PositiveInfinity.
Condition Return Value y is equal to System.Double.PositiveInfinity or System.Double.NegativeInfinity, and x is equal to System.Double.PositiveInfinity or System.Double.NegativeInfinity.
System.Double.NaN. y is equal to System.Double.NegativeInfinity, and x is not equal to System.Double.PositiveInfinity or System.Double.NegativeInfinity.
-System.Math.PI/2. y is equal to System.Double.PositiveInfinity, and x is not equal to System.Double.PositiveInfinity or System.Double.NegativeInfinity.
System.Math.PI/2. x is equal to System.Double.PositiveInfinity, and y is not equal to System.Double.PositiveInfinity or System.Double.NegativeInfinity.
0. x is equal to System.Double.NegativeInfinity, and y >= 0 and not equal to System.Double.PositiveInfinity.
System.Math.PI. x is equal to System.Double.NegativeInfinity, and y < 0 and not equal to System.Double.NegativeInfinity.
-System.Math.PI.
The return value is the angle in the Cartesian plane formed by the x-axis, and a vector starting from the origin, (0,0), and terminating at the point, (x,y).[Note:
]
- For (x, y) in quadrant 1, 0 < < /2.
- For (x, y) in quadrant 2, /2 < < .
- For (x, y) in quadrant 3, - < < -/2.
- For (x, y) in quadrant 4, -/2 < < 0.
The following example demonstrates using the System.Math.Atan2(System.Double,System.Double) method.
using System; public class MathAtan2Example { public static void Main() { Double d1 = Math.Atan2(2,0); Double d2 = Math.Atan2(0,0); Console.WriteLine("Math.Atan2(2,0) returns {0}", d1); Console.WriteLine("Math.Atan2(0,0) returns {0}", d2); } }The output is
Math.Atan2(2,0) returns 1.5707963267949
Math.Atan2(0,0) returns 0
System.Math Class, System Namespace
public static long BigMul(int a, int b);
Produces the full product of two 32-bit numbers.
- a
- The first Int32 to multiply.
- b
- The second Int32 to multiply.
A Int64 containing the product of the specified numbers.
System.Math Class, System Namespace
public static double Ceiling(double a);
Returns the smallest integer greater than or equal to the specified Double.
- a
- A Double .
A Double containing the value of the smallest integer greater than or equal to a. If a is equal to System.Double.NaN, System.Double.NegativeInfinity, or System.Double.PositiveInfinity , that value is returned.
The following example demonstrates using the System.Math.Ceiling(System.Double) method.
using System; public class MathCeilingExample { public static void Main() { Double d1 = Math.Ceiling(3.4); Double d2 = Math.Ceiling(-3.4); Console.WriteLine("Math.Ceiling(3.4) returns {0}", d1); Console.WriteLine("Math.Ceiling(-3.4) returns {0}", d2); } }The output is
Math.Ceiling(3.4) returns 4
Math.Ceiling(-3.4) returns -3
System.Math Class, System Namespace
public static double Cos(double d);
Returns the cosine of the specified Double that represents an angle.
- d
- A Double that represents an angle measured in radians.
A Double containing the value of the cosine of d. If d is equal to System.Double.NaN, System.Double.NegativeInfinity, or System.Double.PositiveInfinity, returns System.Double.NaN.
[Note: Multiply by /180 to convert degrees to radians.]
System.Math Class, System Namespace
public static double Cosh(double value);
Returns the hyperbolic cosine of the specified Double that represents an angle.
- value
- A Double that represents an angle measured in radians.
The hyperbolic cosine of value. If value is equal to System.Double.NegativeInfinity or System.Double.PositiveInfinity, returns System.Double.PositiveInfinity. If value is equal to System.Double.NaN, returns System.Double.NaN.
[Note: Multiply by /180 to convert degrees to radians.]
System.Math Class, System Namespace
public static int DivRem(int a, int b, out int result);
Returns the quotient of two numbers, also passing the remainder as an output parameter.
- a
- A Int32 that contains the dividend.
- b
- A Int32 that contains the divisor.
- result
- A Int32 that receives the remainder.
A Int32 containing the quotient of the specified numbers.
System.Math Class, System Namespace
public static long DivRem(long a, long b, out long result);
Returns the quotient of two numbers, also passing the remainder as an output parameter.
- a
- A Int64 that contains the dividend.
- b
- A Int64 that contains the divisor.
- result
- A Int64 that receives the remainder.
A Int64 containing the quotient of the specified numbers.
System.Math Class, System Namespace
public static double Exp(double d);
Returnse
raised to the specified Double that represents an exponent.
- d
- A Double that represents an exponent.
A Double equal to the numbere
raised to the power of d. If d equals System.Double.NaN or System.Double.PositiveInfinity, returns that value. If d equals System.Double.NegativeInfinity, returns 0.
[Note: Use the System.Math.Pow(System.Double,System.Double) method to calculate powers of other bases.System.Math.Exp(System.Double) is the inverse of System.Math.Log(System.Double) .
]
System.Math Class, System Namespace
public static double Floor(double d);
Returns the largest integer less than or equal to the specified Double.
- d
- A Double .
A Double containing the value of the largest integer less than or equal to d. If d is equal to System.Double.NaN, System.Double.NegativeInfinity, or System.Double.PositiveInfinity, that value is returned..
The behavior of this method follows IEEE Standard 754, section 4.
The following example demonstrates using the System.Math.Floor(System.Double) method.
using System; public class MathFloorExample { public static void Main() { Double d1 = Math.Floor(3.4); Double d2 = Math.Floor(-3.4); Console.WriteLine("Math.Floor(3.4) returns {0}", d1); Console.WriteLine("Math.Floor(-3.4) returns {0}", d2); } }The output is
Math.Floor(3.4) returns 3
Math.Floor(-3.4) returns -4
System.Math Class, System Namespace
public static double IEEERemainder(double x, double y);
Returns the remainder resulting from the division of one specified Double by another specified Double.
- x
- A Double that represents a dividend.
- y
- A Double that represents a divisor.
A Double whose value is as follows:
Value Description x - (y Q), Q is the quotient of x/y rounded to the nearest integer (if x/y is exactly halfway between two integers, the even integer is returned). +0 Q is the quotient of x/y rounded to the nearest integer (if x/y is exactly halfway between two integers, the even integer is returned), x - (y Q) is zero, and x is positive. -0 Q is the quotient of x/y rounded to the nearest integer (if x/y is exactly halfway between two integers, the even integer is returned), x - (y Q) is zero, and x is negative. System.Double.NaN y = 0.
This operation complies with the remainder operation defined in Section 5.1 of ANSI/IEEE Std 754-1985; IEEE Standard for Binary Floating-Point Arithmetic; Institute of Electrical and Electronics Engineers, Inc; 1985.[Note: For more information regarding the use of +0 and -0, see Section 3.1 of ANSI/IEEE Std 754-1985; IEEE Standard for Binary Floating-Point Arithmetic; Institute of Electrical and Electronics Engineers, Inc; 1985.]
The following example demonstrates using the System.Math.IEEERemainder(System.Double,System.Double) method.
using System; public class MathIEEERemainderExample { public static void Main() { Double d1 = Math.IEEERemainder(3.54,0); Double d2 = Math.IEEERemainder(9.99,-3.33); Double d3 = Math.IEEERemainder(-9.99,3.33); Double d4 = Math.IEEERemainder(9.5,1.5); Console.WriteLine("Math.IEEERemainder(3.54,0) returns {0}", d1); Console.WriteLine("Math.IEEERemainder(9.99,-3.33) returns {0}", d2); Console.WriteLine("Math.IEEERemainder(-9.99,3.33) returns {0}", d3); Console.WriteLine("Math.IEEERemainder(9.5,1.5) returns {0}", d4); } }The output is
Math.IEEERemainder(3.54,0) returns NaN
Math.IEEERemainder(9.99,-3.33) returns 0
Math.IEEERemainder(-9.99,3.33) returns 0
Math.IEEERemainder(9.5,1.5) returns 0.5
System.Math Class, System Namespace
public static double Log(double d);
Returns the natural logarithm of the specified Double.
- d
- A Double whose natural logarithm is to be found.
Returns a Double whose value is as follows.
Condition Returns d > 0. The value of the natural logarithm of d. d == 0. System.Double.NegativeInfinity. d < 0. -or-
d is equal to System.Double.NegativeInfinity.
-or-
d is equal to System.Double.NaN.
System.Double.NaN. d is equal to System.Double.PositiveInfinity. System.Double.PositiveInfinity.
d is specified as a base 10 number.
System.Math Class, System Namespace
public static double Log(double a, double newBase);
Returns the logarithm of the specified Double in the specified base.
- a
- A Double whose logarithm is to be found.
- newBase
- A Double containing the value of the base of the logarithm.
Returns a Double whose value is as follows:
If a is equal to System.Double.PositiveInfinity and newBase is not equal System.Double.PositiveInfinity, System.Double.NegativeInfinity, or System.Double.NaN, returns System.Double.PositiveInfinity. If newBase is equal to System.Double.PositiveInfinity and a is not equal to System.Double.PositiveInfinity, System.Double.NegativeInfinity, or System.Double.NaN, returns 0. If both a and newBase are equal to System.Double.PositiveInfinity, or a or newBase is equal to System.Double.NaN or System.Double.NegativeInfinity, returns System.Double.NaN.
Condition Returns a > 0. The value of LognewBasea, if and only if newBase is greater than or equal to 0; otherwise, System.Double.NaN. a == 0. System.Double.NegativeInfinity. a > 0. System.Double.NaN.
System.Math Class, System Namespace
public static double Log10(double d);
Returns log10 of the specified Double.
- d
- A Double whose logarithm is to be found.
Returns a Double as indicated by the following table.
Condition Returns d > 0. A Double containing the value of log10d. d == 0. System.Double.NegativeInfinity. d < 0. -or-
d is equal to System.Double.NegativeInfinity.
-or-
d is equal to System.Double.NaN.
System.Double.NaN. d is equal to System.Double.PositiveInfinity.
System.Double.PositiveInfinity.
System.Math Class, System Namespace
public static sbyte Max(sbyte val1, sbyte val2);
Returns the greater of two specified SByte values.
- val1
- The first of two specified Byte values to compare.
- val2
- The second of two specified Byte values to compare.
A SByte that is equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.
This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Max(System.SByte,System.SByte)(Int16, Int16).
CLSCompliantAttribute(false)
System.Math Class, System Namespace
public static byte Max(byte val1, byte val2);
Returns the greater of two specified Byte values.
- val1
- The first of two specified Byte values to compare.
- val2
- The second of two specified Byte values to compare.
A Byte that is equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.
System.Math Class, System Namespace
public static short Max(short val1, short val2);
Returns the greater of two specified Int16 values.
- val1
- The first of two specified Int16 values to compare.
- val2
- The second of two specified Int16 values to compare.
A Int16 that is equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.
System.Math Class, System Namespace
public static ushort Max(ushort val1, ushort val2);
Returns the greater of two specified UInt16 values.
- val1
- The first of two specified UInt16 values to compare.
- val2
- The second of two specified UInt16 values to compare.
A UInt16 that is equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.
This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Max(System.SByte,System.SByte)(Int32, Int32).
CLSCompliantAttribute(false)
System.Math Class, System Namespace
public static int Max(int val1, int val2);
Returns the greater of two specified Int32 values.
- val1
- The first of two specified Int32 values to compare.
- val2
- The second of two specified Int32 values to compare.
A Int32 that is equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.
System.Math Class, System Namespace
public static uint Max(uint val1, uint val2);
Returns the greater of two specified UInt32 values.
- val1
- The first of two specified UInt32 values to compare.
- val2
- The second of two specified UInt32 values to compare.
A UInt32 that is equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.
This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Max(System.SByte,System.SByte)(Int64, Int64).
CLSCompliantAttribute(false)
System.Math Class, System Namespace
public static long Max(long val1, long val2);
Returns the greater of two specified Int64 values.
- val1
- The first of two specified Int64 values to compare.
- val2
- The second of two specified Int64 values to compare.
A Int64 that is equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.
System.Math Class, System Namespace
public static ulong Max(ulong val1, ulong val2);
Returns the greater of two specified UInt64 values.
- val1
- The first of two specified UInt64 values to compare.
- val2
- The second of two specified UInt64 values to compare.
A UInt64 equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.
This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Max(System.SByte,System.SByte)(Decimal, Decimal).
CLSCompliantAttribute(false)
System.Math Class, System Namespace
public static float Max(float val1, float val2);
Returns the greater of two specified Single values.
- val1
- The first of two specified Single values to compare.
- val2
- The second of two specified Single values to compare.
A Single equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2. If val1, val2, or both are equal to System.Single.NaN, System.Single.NaN is returned.
System.Math Class, System Namespace
public static double Max(double val1, double val2);
Returns the greater of two specified Double values.
- val1
- The first of two specified Double values to compare.
- val2
- The second of two specified Double values to compare.
A Double equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2. If val1 , val2, or both are equal to System.Double.NaN , System.Double.NaN is returned.
System.Math Class, System Namespace
public static decimal Max(decimal val1, decimal val2);
Returns the greater of two specified Decimal values.
- val1
- The first of two specified Decimal values to compare.
- val2
- The second of two specified Decimal values to compare.
A Decimal that is equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.
System.Math Class, System Namespace
public static sbyte Min(sbyte val1, sbyte val2);
Returns the lesser of two specified SByte values.
- val1
- The first of two specified SByte values to compare.
- val2
- The second of two specified SByte values to compare.
A SByte equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2.
This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Min(System.SByte,System.SByte)(Int16, Int16).
CLSCompliantAttribute(false)
System.Math Class, System Namespace
public static byte Min(byte val1, byte val2);
Returns the lesser of two specified Byte values.
- val1
- The first of two specified Byte values to compare.
- val2
- The second of two specified Byte values to compare.
A Byte equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2.
System.Math Class, System Namespace
public static short Min(short val1, short val2);
Returns the lesser of two specified Int16 values.
- val1
- The first of two specified Int16 values to compare.
- val2
- The second of two specified Int16 values to compare.
A Int16 that is equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2.
System.Math Class, System Namespace
public static ushort Min(ushort val1, ushort val2);
Returns the lesser of two specified UInt16 values.
- val1
- The first of two specified UInt16 values to compare.
- val2
- The second of two specified UInt16 values to compare.
A UInt16 equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2 .
This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Min(System.SByte,System.SByte)(Int32, Int32).
CLSCompliantAttribute(false)
System.Math Class, System Namespace
public static int Min(int val1, int val2);
Returns the lesser of two specified Int32 values.
- val1
- The first of two specified Int32 values to compare.
- val2
- The second of two specified Int32 values to compare.
A Int32 equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2.
System.Math Class, System Namespace
public static uint Min(uint val1, uint val2);
Returns the lesser of two specified UInt32 values.
- val1
- The first of two specified UInt32 values to compare.
- val2
- The second of two specified UInt32 values to compare.
A UInt32 equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2.
This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Min(System.SByte,System.SByte)(Int64, Int64).
CLSCompliantAttribute(false)
System.Math Class, System Namespace
public static long Min(long val1, long val2);
Returns the lesser of two specified Int64 values.
- val1
- The first of two specified Int64 values to compare.
- val2
- The second of two specified Int64 values to compare.
A Int64 equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2.
System.Math Class, System Namespace
public static ulong Min(ulong val1, ulong val2);
Returns the lesser of two specified UInt64 values.
- val1
- The first of two specified UInt64 values to compare.
- val2
- The second of two specified UInt64 values to compare.
A UInt64 equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2.
This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Min(System.SByte,System.SByte)(Decimal, Decimal).
CLSCompliantAttribute(false)
System.Math Class, System Namespace
public static float Min(float val1, float val2);
Returns the lesser of two specified Single values.
- val1
- The first of two specified Single values to compare.
- val2
- The second of two specified Single values to compare.
A Single equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2. If val1, val2, or both are equal to System.Single.NaN, System.Single.NaN is returned.
System.Math Class, System Namespace
public static double Min(double val1, double val2);
Returns the lesser of two specified Double values.
- val1
- The first of two specified Double values to compare.
- val2
- The second of two specified Double values to compare.
A Double equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2. If val1, val2, or both are equal to System.Double.NaN, System.Double.NaN is returned.
System.Math Class, System Namespace
public static decimal Min(decimal val1, decimal val2);
Returns the lesser of two specified Decimal values.
- val1
- The first of two specified Decimal values to compare.
- val2
- The second of two specified Decimal values to compare.
A Decimal equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2.
System.Math Class, System Namespace
public static double Pow(double x, double y);
Returns the specified Double raised to the specified power.
- x
- A Double to be raised to a power.
- y
- A Double that specifies that power.
A Double equal to x raised to the power y. The following table specifies the results if x or y is equal to System.Double.NaN, System.Double.NegativeInfinity, or System.Double.PositiveInfinity.
Parameter Values Returns x or y is equal to System.Double.NaN System.Double.NaN. x is equal to System.Double.NegativeInfinity System.Double.NegativeInfinity if y is an odd integer; otherwise, System.Double.PositiveInfinity. y is equal to System.Double.NegativeInfinity 0. x is equal to System.Double.PositiveInfinity 0 if y is equal to System.Double.NegativeInfinity; otherwise, System.Double.PositiveInfinity. y is equal to System.Double.PositiveInfinity System.Double.PositiveInfinity.
System.Math Class, System Namespace
public static double Round(double a);
Returns the integer nearest the specified Double.
- a
- A Double to be rounded.
A Double containing the value of the integer nearest a. If a is exactly halfway between two integers, one of which is even and the other odd, then the even integer is returned.
The behavior of this method follows IEEE Standard 754, section 4.1.
The following example demonstrates using the System.Math.Round(System.Double)(Double) method.
using System; public class MathRoundExample { public static void Main() { Double d1 = Math.Round(4.4); Double d2 = Math.Round(4.5); Double d3 = Math.Round(4.6); Console.WriteLine("Math.Round(4.4) returns {0}", d1); Console.WriteLine("Math.Round(4.5) returns {0}", d2); Console.WriteLine("Math.Round(4.6) returns {0}", d3); } }The output is
Math.Round(4.4) returns 4
Math.Round(4.5) returns 4
Math.Round(4.6) returns 5
System.Math Class, System Namespace
public static double Round(double value, int digits);
Returns the number nearest the specified Double within the specified precision.
- value
- A Double to be rounded.
- digits
- A Int32 containing the value of the number of significant fractional digits (precision) in the return value. This number is required to be greater than or equal to 0 and less than or equal to 15.
A Double containing the value of the number nearest value with a precision equal to digits . If the digit in value that is in the 10-(digits + 1) place is equal to 5 and there are no non-zero numbers in any less significant place, then the digit in the 10-digits place will be unchanged if it is even, else it will be set to the closest even integer value in the direction of the digit in the 10-(digits + 1) place. If the precision of value is less than digits, then value is returned unchanged. If digits is zero, this method behaves in the same manner as System.Math.Round(System.Double) (value ).
Exception Type Condition ArgumentOutOfRangeException digits < 0. digits > 15.
The behavior of this method follows IEEE Standard 754, section 4.1.
The following example demonstrates using the System.Math.Round(System.Double)(Double, Int32) method.
using System; public class MathRoundExample { public static void Main() { Double d1 = Math.Round(3.44,1); Double d2 = Math.Round(3.45,1); Double d3 = Math.Round(3.55,1); Console.WriteLine("Math.Round(3.44, 1) returns {0}", d1); Console.WriteLine("Math.Round(3.45, 1) returns {0}", d2); Console.WriteLine("Math.Round(3.55, 1) returns {0}", d3); } }The output is
Math.Round(3.44, 1) returns 3.4
Math.Round(3.45, 1) returns 3.4
Math.Round(3.55, 1) returns 3.6
System.Math Class, System Namespace
public static decimal Round(decimal d);
Returns the integer nearest the specified Decimal.
- d
- A Decimal to be rounded.
A Decimal containing the value of the integer nearest d. If d is exactly halfway between two integers, one of which is even and the other odd, then the even integer is returned.
The behavior of this method follows IEEE Standard 754, section 4.1.
The following example demonstrates using the System.Math.Round(System.Double)(Decimal) method.
using System; public class MathRoundExample { public static void Main() { Double d1 = Math.Round(4.4); Double d2 = Math.Round(4.5); Double d3 = Math.Round(4.6); Console.WriteLine("Math.Round(4.4) returns {0}", d1); Console.WriteLine("Math.Round(4.5) returns {0}", d2); Console.WriteLine("Math.Round(4.6) returns {0}", d3); } }The output is
Math.Round(4.4) returns 4
Math.Round(4.5) returns 4
Math.Round(4.6) returns 5
System.Math Class, System Namespace
public static int Sign(sbyte value);
Returns a value indicating the sign of the specified SByte .
- value
- A SByte whose sign is to be determined.
A Int32 indicating the sign of value.
Number Description -1 value < 0. 0 value == 0. 1 value > 0.
This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Sign(System.SByte)(Int16).
CLSCompliantAttribute(false)
System.Math Class, System Namespace
public static int Sign(short value);
Returns a value indicating the sign of the specified Int16 .
- value
- A Int16 whose sign is to be determined.
A Int32 indicating the sign of value.
Number Description -1 value < 0. 0 value == 0. 1 value > 0.
System.Math Class, System Namespace
public static int Sign(int value);
Returns a value indicating the sign of the specified Int32 .
- value
- A Int32 whose sign is to be determined.
A Int32 indicating the sign of value.
Number Description -1 value < 0. 0 value == 0. 1 value > 0.
System.Math Class, System Namespace
public static int Sign(long value);
Returns a value indicating the sign of the specified Int64.
- value
- A Int64 whose sign is to be determined.
A Int32 indicating the sign of value.
Number Description -1 value < 0. 0 value == 0. 1 value > 0.
System.Math Class, System Namespace
public static int Sign(float value);
Returns a value indicating the sign of the specified Single.
- value
- A Single whose sign is to be determined.
A Int32 indicating the sign of value.
Number Description -1 value < 0. 0 value == 0. 1 value > 0.
Exception Type Condition ArithmeticException value is equal to System.Single.NaN.
System.Math Class, System Namespace
public static int Sign(double value);
Returns a value indicating the sign of the specified Double.
- value
- A Double whose sign is to be determined.
A Int32 indicating the sign of value.
Number Description -1 value < 0. 0 value == 0. 1 value > 0.
Exception Type Condition ArithmeticException value is equal to System.Double.NaN.
The following example demonstrates using the System.Math.Sign(System.SByte)(Double) method.
using System; public class MathSignExample { public static void Main() { Double d1 = Math.Sign(4.4); Double d2 = Math.Sign(0.0); Double d3 = Math.Sign(-4.5); Console.WriteLine("Math.Sign(4.4) returns {0}", d1); Console.WriteLine("Math.Sign(0.0) returns {0}", d2); Console.WriteLine("Math.Sign(-4.5) returns {0}", d3); } }The output is
Math.Sign(4.4) returns 1
Math.Sign(0.0) returns 0
Math.Sign(-4.5) returns -1
System.Math Class, System Namespace
public static int Sign(decimal value);
Returns a value indicating the sign of the specified Decimal.
- value
- A Decimal number whose sign is to be determined.
A Int32 indicating the sign of value.
Number Description -1 value < 0. 0 value == 0. 1 value > 0.
System.Math Class, System Namespace
public static double Sin(double a);
Returns the sine of the specified Double that represents an angle.
- a
- A Double containing the value of an angle measured in radians.
A Double containing the value of the sine of a. If a is equal to System.Double.NaN, System.Double.NegativeInfinity, or System.Double.PositiveInfinity, returns System.Double.NaN.
[Note: Multiply by /180 to convert degrees to radians.]
The following example demonstrates using the System.Math.Sin(System.Double) method.
using System; public class MathSinExample { public static void Main() { Double d1 = Math.Sin(0); Double d2 = Math.Sin(Math.PI/2.0); Console.WriteLine("Math.Sin(0) returns {0}", d1); Console.WriteLine("Math.Sin(Math.PI/2.0) returns {0}", d2); } }The output is
Math.Sin(0) returns 0
Math.Sin(Math.PI/2.0) returns 1
System.Math Class, System Namespace
public static double Sinh(double value);
Returns the hyperbolic sine of the specified Double that represents an angle.
- value
- A Double containing the value of an angle measured in radians.
A Double containing the value of the hyperbolic sine of value. If value is equal to System.Double.NegativeInfinity, System.Double.PositiveInfinity, or System.Double.NaN, returns a Double equal to value.
[Note: Multiply by /180 to convert degrees to radians.]
The following example demonstrates using the System.Math.Sinh(System.Double) method.
using System; public class MathSinhExample { public static void Main() { Double d1 = Math.Sinh(0); Double d2 = Math.Sinh(Math.PI); Console.WriteLine("Math.Sinh(0) returns {0}", d1); Console.WriteLine("Math.Sinh(Math.PI) returns {0}", d2); } }The output is
Math.Sinh(0) returns 0
Math.Sinh(Math.PI) returns 11.5487393572577
System.Math Class, System Namespace
public static double Sqrt(double d);
Returns the square root of the specified Double.
- d
- A Double .
A Double whose value is indicated as follows:
Condition Returns d == 0 A Double containing the positive square root of d. d < 0 d is equal to System.Double.NegativeInfinity.
d is equal to System.Double.NaN.
System.Double.NaN. d is equal to System.Double.PositiveInfinity
System.Double.PositiveInfinity.
The following example demonstrates using the System.Math.Sqrt(System.Double) method.
using System; public class MathSqrtExample { public static void Main() { Double d1 = Math.Sqrt(16.0); Double d2 = Math.Sqrt(0.0); Double d3 = Math.Sqrt(-10.0); Console.WriteLine("Math.Sqrt(16.0) returns {0}", d1); Console.WriteLine("Math.Sqrt(0.0) returns {0}", d2); Console.WriteLine("Math.Sqrt(-10.0) returns {0}", d3); } }The output is
Math.Sqrt(16.0) returns 4
Math.Sqrt(0.0) returns 0
Math.Sqrt(-10.0) returns NaN
System.Math Class, System Namespace
public static double Tan(double a);
Returns the tangent of the specified Double that represents an angle.
- a
- A Double that represents an angle measured in radians.
A Double containing the value of the tangent of a. If a is equal to System.Double.NaN, System.Double.NegativeInfinity, or System.Double.PositiveInfinity, returns System.Double.NaN.
[Note: Multiply by /180 to convert degrees to radians.]
The following example demonstrates using the System.Math.Tan(System.Double) method.
using System; public class MathTanExample { public static void Main() { Double d1 = Math.Tan(0); Double d2 = Math.Tan(Math.PI/2.0); Console.WriteLine("Math.Tan(0) returns {0}", d1); Console.WriteLine("Math.Tan(Math.PI/2.0) returns {0}", d2); } }The output is
Math.Tan(0) returns 0
Math.Tan(Math.PI/2.0) returns 1.63317787283838E+16
System.Math Class, System Namespace
public static double Tanh(double value);
Returns the hyperbolic tangent of the specified Double that represents an angle.
- value
- A Double that represents an angle measured in radians.
A Double containing the value of the hyperbolic tangent of value. If value is equal to System.Double.NegativeInfinity, returns -1. If value is equal to System.Double.PositiveInfinity, returns 1. If value is equal to System.Double.NaN, returns System.Double.NaN.
[Note: Multiply by /180 to convert degrees to radians.]
The following example demonstrates using the System.Math.Tanh(System.Double) method.
using System; public class MathTanhExample { public static void Main() { Double d1 = Math.Tanh(0); Double d2 = Math.Tanh(Math.PI); Console.WriteLine("Math.Tanh(0) returns {0}", d1); Console.WriteLine("Math.Tanh(Math.PI) returns {0}", d2); } }The output is
Math.Tanh(0) returns 0
Math.Tanh(Math.PI) returns 0.99627207622075
System.Math Class, System Namespace
public const double E = 2.71828182845905;
A constant,e
, which specifies the natural logarithmic base rounded to double precision.
The value of this constant is 2.7182818284590452354 converted to Double.
System.Math Class, System Namespace
public const double PI = 3.14159265358979;
A constant, , which specifies the ratio of the circumference of a circle to its diameter rounded to double precision.
The value of this constant is 3.14159265358979323846 converted to Double.
System.Math Class, System Namespace