System.Math Class

public sealed class Math

Base Types

Object
  Math

Assembly

mscorlib

Library

ExtendedNumerics

Summary

Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions.

See Also

System Namespace

Members

Math Methods

Math.Abs(System.Decimal) Method
Math.Abs(double) Method
Math.Abs(float) Method
Math.Abs(long) Method
Math.Abs(int) Method
Math.Abs(short) Method
Math.Abs(sbyte) 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(ushort, ushort) Method
Math.Min(short, short) Method
Math.Min(byte, byte) Method
Math.Min(sbyte, sbyte) Method
Math.Min(ulong, ulong) Method
Math.Min(float, float) Method
Math.Min(long, long) Method
Math.Min(uint, uint) Method
Math.Min(int, int) Method
Math.Min(double, double) Method
Math.Min(System.Decimal, System.Decimal) Method
Math.Pow Method
Math.Round(System.Decimal) Method
Math.Round(double, int) Method
Math.Round(double) Method
Math.Sign(System.Decimal) Method
Math.Sign(double) Method
Math.Sign(float) Method
Math.Sign(long) Method
Math.Sign(int) Method
Math.Sign(short) Method
Math.Sign(sbyte) Method
Math.Sin Method
Math.Sinh Method
Math.Sqrt Method
Math.Tan Method
Math.Tanh Method

Math Fields

Math.E Field
Math.PI Field


Math.Abs(System.Decimal) Method

public static decimal Abs(decimal value);

Summary

Returns the absolute value of the specified Decimal .

Parameters

value
A Decimal.

Return Value

A Decimal containing the absolute value of value.

Example

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

See Also

System.Math Class, System Namespace

Math.Abs(double) Method

public static double Abs(double value);

Summary

Returns the absolute value of the specified Double.

Parameters

value
A Double.

Return Value

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.

See Also

System.Math Class, System Namespace

Math.Abs(float) Method

public static float Abs(float value);

Summary

Returns the absolute value of the specified Single.

Parameters

value
A Single.

Return Value

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.

See Also

System.Math Class, System Namespace

Math.Abs(long) Method

public static long Abs(long value);

Summary

Returns the absolute value of the specified Int64.

Parameters

value
A Int64.

Return Value

A Int64 containing the absolute value of value.

Exceptions

Exception TypeCondition
OverflowExceptionvalue equals System.Int64.MinValue.

See Also

System.Math Class, System Namespace

Math.Abs(int) Method

public static int Abs(int value);

Summary

Returns the absolute value of the specified Int32.

Parameters

value
A Int32.

Return Value

A Int32 containing the absolute value of value.

Exceptions

Exception TypeCondition
OverflowExceptionvalue equals System.Int32.MinValue.

See Also

System.Math Class, System Namespace

Math.Abs(short) Method

public static short Abs(short value);

Summary

Returns the absolute value of the specified Int16.

Parameters

value
A Int16.

Return Value

A Int16 containing the absolute value of value.

Exceptions

Exception TypeCondition
OverflowExceptionvalue equals System.Int16.MinValue.

See Also

System.Math Class, System Namespace

Math.Abs(sbyte) Method

public static sbyte Abs(sbyte value);

Summary

Returns the absolute value of the specified SByte.

Parameters

value
A SByte.

Return Value

A SByte containing the absolute value of value.

Exceptions

Exception TypeCondition
OverflowExceptionvalue equals System.SByte.MinValue.

Description

This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Abs(System.SByte)(Int16).

Attributes

CLSCompliantAttribute(false)

See Also

System.Math Class, System Namespace

Math.Acos Method

public static double Acos(double d);

Summary

Returns the angle whose cosine is the specified Double.

Parameters

d
A Double representing a cosine, where -1 <= d <= 1.

Return Value

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.

Description

[Note: Multiply the return value by 180/ to convert from radians to degrees.]

See Also

System.Math Class, System Namespace

Math.Asin Method

public static double Asin(double d);

Summary

Returns the angle whose sine is the specified Double.

Parameters

d
A Double representing a sine, where -1 <= d <= 1.

Return Value

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 .

Description

[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.

]

See Also

System.Math Class, System Namespace

Math.Atan Method

public static double Atan(double d);

Summary

Returns the angle whose tangent is the specified Double.

Parameters

d
A Double that represents a tangent.

Return Value

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 ValueCondition
System.Double.NaNd 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.

Description

[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.

]

See Also

System.Math Class, System Namespace

Math.Atan2 Method

public static double Atan2(double y, double x);

Summary

Returns the angle whose tangent is the quotient of two specified Double values.

Parameters

y
A Double representing the y coordinate of a point.
x
A Double representing the x coordinate of a point.

Return Value

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.

ConditionReturn 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.

Description

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:

]

Example

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

See Also

System.Math Class, System Namespace

Math.BigMul Method

public static long BigMul(int a, int b);

Summary

Produces the full product of two 32-bit numbers.

Parameters

a
The first Int32 to multiply.
b
The second Int32 to multiply.

Return Value

A Int64 containing the product of the specified numbers.

See Also

System.Math Class, System Namespace

Math.Ceiling Method

public static double Ceiling(double a);

Summary

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

Parameters

a
A Double .

Return Value

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.

Example

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

See Also

System.Math Class, System Namespace

Math.Cos Method

public static double Cos(double d);

Summary

Returns the cosine of the specified Double that represents an angle.

Parameters

d
A Double that represents an angle measured in radians.

Return Value

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.

Description

[Note: Multiply by /180 to convert degrees to radians.]

See Also

System.Math Class, System Namespace

Math.Cosh Method

public static double Cosh(double value);

Summary

Returns the hyperbolic cosine of the specified Double that represents an angle.

Parameters

value
A Double that represents an angle measured in radians.

Return Value

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.

Description

[Note: Multiply by /180 to convert degrees to radians.]

See Also

System.Math Class, System Namespace

Math.DivRem(int, int, int) Method

public static int DivRem(int a, int b, out int result);

Summary

Returns the quotient of two numbers, also passing the remainder as an output parameter.

Parameters

a
A Int32 that contains the dividend.
b
A Int32 that contains the divisor.
result
A Int32 that receives the remainder.

Return Value

A Int32 containing the quotient of the specified numbers.

See Also

System.Math Class, System Namespace

Math.DivRem(long, long, long) Method

public static long DivRem(long a, long b, out long result);

Summary

Returns the quotient of two numbers, also passing the remainder as an output parameter.

Parameters

a
A Int64 that contains the dividend.
b
A Int64 that contains the divisor.
result
A Int64 that receives the remainder.

Return Value

A Int64 containing the quotient of the specified numbers.

See Also

System.Math Class, System Namespace

Math.Exp Method

public static double Exp(double d);

Summary

Returns e raised to the specified Double that represents an exponent.

Parameters

d
A Double that represents an exponent.

Return Value

A Double equal to the number e 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.

Description

[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) .

]

See Also

System.Math Class, System Namespace

Math.Floor Method

public static double Floor(double d);

Summary

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

Parameters

d
A Double .

Return Value

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..

Description

The behavior of this method follows IEEE Standard 754, section 4.

Example

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

See Also

System.Math Class, System Namespace

Math.IEEERemainder Method

public static double IEEERemainder(double x, double y);

Summary

Returns the remainder resulting from the division of one specified Double by another specified Double.

Parameters

x
A Double that represents a dividend.
y
A Double that represents a divisor.

Return Value

A Double whose value is as follows:

ValueDescription
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).
+0Q 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.
-0Q 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.NaNy = 0.

Description

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.]

Example

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

See Also

System.Math Class, System Namespace

Math.Log(double) Method

public static double Log(double d);

Summary

Returns the natural logarithm of the specified Double.

Parameters

d
A Double whose natural logarithm is to be found.

Return Value

Returns a Double whose value is as follows.

ConditionReturns
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.

Description

d is specified as a base 10 number.

See Also

System.Math Class, System Namespace

Math.Log(double, double) Method

public static double Log(double a, double newBase);

Summary

Returns the logarithm of the specified Double in the specified base.

Parameters

a
A Double whose logarithm is to be found.
newBase
A Double containing the value of the base of the logarithm.

Return Value

Returns a Double whose value is as follows:

ConditionReturns
a > 0, newBase > 0, but newBase != 1lognewBasea
a < 0System.Double.NaN
newBase < 0System.Double.NaN
newBase == 0, a != 1System.Double.NaN
newBase == 0, a == 1Zero
0 < newBase < 1, a == 0System.Double.PositiveInfinity
0 < newBase < 1, a == +infinitySystem.Double.NegativeInfinity
newBase == 1System.Double.NaN
newBase > 1, a == 0System.Double.NegativeInfinity
newBase > 1, a == +infinitySystem.Double.PositiveInfinity
newBase == +infinity, a != 1System.Double.NaN
newBase == +infinity, a == 1Zero
a == NaN or newBase == NaNSystem.Double.NaN

See Also

System.Math Class, System Namespace

Math.Log10 Method

public static double Log10(double d);

Summary

Returns log10 of the specified Double.

Parameters

d
A Double whose logarithm is to be found.

Return Value

Returns a Double as indicated by the following table.

ConditionReturns
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.

See Also

System.Math Class, System Namespace

Math.Max(sbyte, sbyte) Method

public static sbyte Max(sbyte val1, sbyte val2);

Summary

Returns the greater of two specified SByte values.

Parameters

val1
The first of two specified Byte values to compare.
val2
The second of two specified Byte values to compare.

Return Value

A SByte that is equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.

Description

This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Max(System.SByte,System.SByte)(Int16, Int16).

Attributes

CLSCompliantAttribute(false)

See Also

System.Math Class, System Namespace

Math.Max(byte, byte) Method

public static byte Max(byte val1, byte val2);

Summary

Returns the greater of two specified Byte values.

Parameters

val1
The first of two specified Byte values to compare.
val2
The second of two specified Byte values to compare.

Return Value

A Byte that is equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.

See Also

System.Math Class, System Namespace

Math.Max(short, short) Method

public static short Max(short val1, short val2);

Summary

Returns the greater of two specified Int16 values.

Parameters

val1
The first of two specified Int16 values to compare.
val2
The second of two specified Int16 values to compare.

Return Value

A Int16 that is equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.

See Also

System.Math Class, System Namespace

Math.Max(ushort, ushort) Method

public static ushort Max(ushort val1, ushort val2);

Summary

Returns the greater of two specified UInt16 values.

Parameters

val1
The first of two specified UInt16 values to compare.
val2
The second of two specified UInt16 values to compare.

Return Value

A UInt16 that is equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.

Description

This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Max(System.SByte,System.SByte)(Int32, Int32).

Attributes

CLSCompliantAttribute(false)

See Also

System.Math Class, System Namespace

Math.Max(int, int) Method

public static int Max(int val1, int val2);

Summary

Returns the greater of two specified Int32 values.

Parameters

val1
The first of two specified Int32 values to compare.
val2
The second of two specified Int32 values to compare.

Return Value

A Int32 that is equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.

See Also

System.Math Class, System Namespace

Math.Max(uint, uint) Method

public static uint Max(uint val1, uint val2);

Summary

Returns the greater of two specified UInt32 values.

Parameters

val1
The first of two specified UInt32 values to compare.
val2
The second of two specified UInt32 values to compare.

Return Value

A UInt32 that is equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.

Description

This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Max(System.SByte,System.SByte)(Int64, Int64).

Attributes

CLSCompliantAttribute(false)

See Also

System.Math Class, System Namespace

Math.Max(long, long) Method

public static long Max(long val1, long val2);

Summary

Returns the greater of two specified Int64 values.

Parameters

val1
The first of two specified Int64 values to compare.
val2
The second of two specified Int64 values to compare.

Return Value

A Int64 that is equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.

See Also

System.Math Class, System Namespace

Math.Max(ulong, ulong) Method

public static ulong Max(ulong val1, ulong val2);

Summary

Returns the greater of two specified UInt64 values.

Parameters

val1
The first of two specified UInt64 values to compare.
val2
The second of two specified UInt64 values to compare.

Return Value

A UInt64 equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.

Description

This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Max(System.SByte,System.SByte)(Decimal, Decimal).

Attributes

CLSCompliantAttribute(false)

See Also

System.Math Class, System Namespace

Math.Max(float, float) Method

public static float Max(float val1, float val2);

Summary

Returns the greater of two specified Single values.

Parameters

val1
The first of two specified Single values to compare.
val2
The second of two specified Single values to compare.

Return Value

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.

See Also

System.Math Class, System Namespace

Math.Max(double, double) Method

public static double Max(double val1, double val2);

Summary

Returns the greater of two specified Double values.

Parameters

val1
The first of two specified Double values to compare.
val2
The second of two specified Double values to compare.

Return Value

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.

See Also

System.Math Class, System Namespace

Math.Max(System.Decimal, System.Decimal) Method

public static decimal Max(decimal val1, decimal val2);

Summary

Returns the greater of two specified Decimal values.

Parameters

val1
The first of two specified Decimal values to compare.
val2
The second of two specified Decimal values to compare.

Return Value

A Decimal that is equal to val1 if val1 is greater than or equal to val2; otherwise, the return value is equal to val2.

See Also

System.Math Class, System Namespace

Math.Min(ushort, ushort) Method

public static ushort Min(ushort val1, ushort val2);

Summary

Returns the lesser of two specified UInt16 values.

Parameters

val1
The first of two specified UInt16 values to compare.
val2
The second of two specified UInt16 values to compare.

Return Value

A UInt16 equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2 .

Description

This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Min(System.SByte,System.SByte)(Int32, Int32).

Attributes

CLSCompliantAttribute(false)

See Also

System.Math Class, System Namespace

Math.Min(short, short) Method

public static short Min(short val1, short val2);

Summary

Returns the lesser of two specified Int16 values.

Parameters

val1
The first of two specified Int16 values to compare.
val2
The second of two specified Int16 values to compare.

Return Value

A Int16 that is equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2.

See Also

System.Math Class, System Namespace

Math.Min(byte, byte) Method

public static byte Min(byte val1, byte val2);

Summary

Returns the lesser of two specified Byte values.

Parameters

val1
The first of two specified Byte values to compare.
val2
The second of two specified Byte values to compare.

Return Value

A Byte equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2.

See Also

System.Math Class, System Namespace

Math.Min(sbyte, sbyte) Method

public static sbyte Min(sbyte val1, sbyte val2);

Summary

Returns the lesser of two specified SByte values.

Parameters

val1
The first of two specified SByte values to compare.
val2
The second of two specified SByte values to compare.

Return Value

A SByte equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2.

Description

This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Min(System.SByte,System.SByte)(Int16, Int16).

Attributes

CLSCompliantAttribute(false)

See Also

System.Math Class, System Namespace

Math.Min(ulong, ulong) Method

public static ulong Min(ulong val1, ulong val2);

Summary

Returns the lesser of two specified UInt64 values.

Parameters

val1
The first of two specified UInt64 values to compare.
val2
The second of two specified UInt64 values to compare.

Return Value

A UInt64 equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2.

Description

This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Min(System.SByte,System.SByte)(Decimal, Decimal).

Attributes

CLSCompliantAttribute(false)

See Also

System.Math Class, System Namespace

Math.Min(float, float) Method

public static float Min(float val1, float val2);

Summary

Returns the lesser of two specified Single values.

Parameters

val1
The first of two specified Single values to compare.
val2
The second of two specified Single values to compare.

Return Value

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.

See Also

System.Math Class, System Namespace

Math.Min(long, long) Method

public static long Min(long val1, long val2);

Summary

Returns the lesser of two specified Int64 values.

Parameters

val1
The first of two specified Int64 values to compare.
val2
The second of two specified Int64 values to compare.

Return Value

A Int64 equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2.

See Also

System.Math Class, System Namespace

Math.Min(uint, uint) Method

public static uint Min(uint val1, uint val2);

Summary

Returns the lesser of two specified UInt32 values.

Parameters

val1
The first of two specified UInt32 values to compare.
val2
The second of two specified UInt32 values to compare.

Return Value

A UInt32 equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2.

Description

This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Min(System.SByte,System.SByte)(Int64, Int64).

Attributes

CLSCompliantAttribute(false)

See Also

System.Math Class, System Namespace

Math.Min(int, int) Method

public static int Min(int val1, int val2);

Summary

Returns the lesser of two specified Int32 values.

Parameters

val1
The first of two specified Int32 values to compare.
val2
The second of two specified Int32 values to compare.

Return Value

A Int32 equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2.

See Also

System.Math Class, System Namespace

Math.Min(double, double) Method

public static double Min(double val1, double val2);

Summary

Returns the lesser of two specified Double values.

Parameters

val1
The first of two specified Double values to compare.
val2
The second of two specified Double values to compare.

Return Value

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.

See Also

System.Math Class, System Namespace

Math.Min(System.Decimal, System.Decimal) Method

public static decimal Min(decimal val1, decimal val2);

Summary

Returns the lesser of two specified Decimal values.

Parameters

val1
The first of two specified Decimal values to compare.
val2
The second of two specified Decimal values to compare.

Return Value

A Decimal equal to val1 if val1 is less than or equal to val2; otherwise, the return value is equal to val2.

See Also

System.Math Class, System Namespace

Math.Pow Method

public static double Pow(double x, double y);

Summary

Returns the specified Double raised to the specified power.

Parameters

x
A Double to be raised to a power.
y
A Double that specifies that power.

Return Value

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 ValuesReturns
x or y == NaN System.Double.NaN
x == any value except NaN, y == 0 1
x == -infinity, y < 0 0
x == -infinity, y is a positive odd integer System.Double.NegativeInfinity
x == -infinity, y is not 0 or a positive odd integer System.Double.PositiveInfinity
x < 0, (-1 < y < 0) or (0 < y < 1) System.Double.NaN
x < -1, y == -infinity 0
x < -1, y == +infinity System.Double.PositiveInfinity
x == -1, y == -infinity or +infinity System.Double.NaN
(-1 < x <= 0), y == -infinity System.Double.PositiveInfinity
(-1 < x <= 0), y == +infinity 0
x == 0, y < 0 System.Double.PositiveInfinity
x == 0, y > 0 0
(0 < x < 1), y == -infinity System.Double.PositiveInfinity
(0 < x < 1), y == +infinity 0
x == 1 y == any value except NaN 1
x > 1, y == -infinity 0
x > 1, y == +infinity System.Double.PositiveInfinity
x == +infinity y < 00
x == +infinity y > 0System.Double.PositiveInfinity

See Also

System.Math Class, System Namespace

Math.Round(System.Decimal) Method

public static decimal Round(decimal d);

Summary

Returns the integer nearest the specified Decimal.

Parameters

d
A Decimal to be rounded.

Return Value

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.

Description

The behavior of this method follows IEEE Standard 754, section 4.1.

Example

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

See Also

System.Math Class, System Namespace

Math.Round(double, int) Method

public static double Round(double value, int digits);

Summary

Returns the number nearest the specified Double within the specified precision.

Parameters

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.

Return Value

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 ).

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptiondigits < 0

-or-

digits > 15

Description

The behavior of this method follows IEEE Standard 754, section 4.1.

Example

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

See Also

System.Math Class, System Namespace

Math.Round(double) Method

public static double Round(double a);

Summary

Returns the integer nearest the specified Double.

Parameters

a
A Double to be rounded.

Return Value

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.

Description

The behavior of this method follows IEEE Standard 754, section 4.1.

Example

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

See Also

System.Math Class, System Namespace

Math.Sign(System.Decimal) Method

public static int Sign(decimal value);

Summary

Returns a value indicating the sign of the specified Decimal.

Parameters

value
A Decimal number whose sign is to be determined.

Return Value

A Int32 indicating the sign of value.

NumberDescription
-1value < 0.
0value == 0.
1value > 0.

See Also

System.Math Class, System Namespace

Math.Sign(double) Method

public static int Sign(double value);

Summary

Returns a value indicating the sign of the specified Double.

Parameters

value
A Double whose sign is to be determined.

Return Value

A Int32 indicating the sign of value.

NumberDescription
-1value < 0.
0value == 0.
1value > 0.

Exceptions

Exception TypeCondition
ArithmeticExceptionvalue is equal to System.Double.NaN.

Example

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

See Also

System.Math Class, System Namespace

Math.Sign(float) Method

public static int Sign(float value);

Summary

Returns a value indicating the sign of the specified Single.

Parameters

value
A Single whose sign is to be determined.

Return Value

A Int32 indicating the sign of value.

NumberDescription
-1value < 0.
0value == 0.
1value > 0.

Exceptions

Exception TypeCondition
ArithmeticExceptionvalue is equal to System.Single.NaN.

See Also

System.Math Class, System Namespace

Math.Sign(long) Method

public static int Sign(long value);

Summary

Returns a value indicating the sign of the specified Int64.

Parameters

value
A Int64 whose sign is to be determined.

Return Value

A Int32 indicating the sign of value.

NumberDescription
-1value < 0.
0value == 0.
1value > 0.

See Also

System.Math Class, System Namespace

Math.Sign(int) Method

public static int Sign(int value);

Summary

Returns a value indicating the sign of the specified Int32 .

Parameters

value
A Int32 whose sign is to be determined.

Return Value

A Int32 indicating the sign of value.

NumberDescription
-1value < 0.
0value == 0.
1value > 0.

See Also

System.Math Class, System Namespace

Math.Sign(short) Method

public static int Sign(short value);

Summary

Returns a value indicating the sign of the specified Int16 .

Parameters

value
A Int16 whose sign is to be determined.

Return Value

A Int32 indicating the sign of value.

NumberDescription
-1value < 0.
0value == 0.
1value > 0.

See Also

System.Math Class, System Namespace

Math.Sign(sbyte) Method

public static int Sign(sbyte value);

Summary

Returns a value indicating the sign of the specified SByte .

Parameters

value
A SByte whose sign is to be determined.

Return Value

A Int32 indicating the sign of value.

NumberDescription
-1value < 0.
0value == 0.
1value > 0.

Description

This method is not CLS-compliant. For a CLS-compliant alternative, use System.Math.Sign(System.SByte)(Int16).

Attributes

CLSCompliantAttribute(false)

See Also

System.Math Class, System Namespace

Math.Sin Method

public static double Sin(double a);

Summary

Returns the sine of the specified Double that represents an angle.

Parameters

a
A Double containing the value of an angle measured in radians.

Return Value

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.

Description

[Note: Multiply by /180 to convert degrees to radians.]

Example

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

See Also

System.Math Class, System Namespace

Math.Sinh Method

public static double Sinh(double value);

Summary

Returns the hyperbolic sine of the specified Double that represents an angle.

Parameters

value
A Double containing the value of an angle measured in radians.

Return Value

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.

Description

[Note: Multiply by /180 to convert degrees to radians.]

Example

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

See Also

System.Math Class, System Namespace

Math.Sqrt Method

public static double Sqrt(double d);

Summary

Returns the square root of the specified Double.

Parameters

d
A Double .

Return Value

A Double whose value is indicated as follows:

ConditionReturns
d >= 0A 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.

Example

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

See Also

System.Math Class, System Namespace

Math.Tan Method

public static double Tan(double a);

Summary

Returns the tangent of the specified Double that represents an angle.

Parameters

a
A Double that represents an angle measured in radians.

Return Value

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.

Description

[Note: Multiply by /180 to convert degrees to radians.]

Example

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

See Also

System.Math Class, System Namespace

Math.Tanh Method

public static double Tanh(double value);

Summary

Returns the hyperbolic tangent of the specified Double that represents an angle.

Parameters

value
A Double that represents an angle measured in radians.

Return Value

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.

Description

[Note: Multiply by /180 to convert degrees to radians.]

Example

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

See Also

System.Math Class, System Namespace

Math.E Field

public const double E = 2.71828182845905;

Summary

A constant, e , which specifies the natural logarithmic base rounded to double precision.

See Also

System.Math Class, System Namespace

Math.PI Field

public const double PI = 3.14159265358979;

Summary

A constant, , which specifies the ratio of the circumference of a circle to its diameter rounded to double precision.

See Also

System.Math Class, System Namespace