Class Math
Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions.
Inherited Members
Namespace: System
Assembly: System.Math.dll
Syntax
public static class Math
Fields
| Improve this Doc View SourceE
Represents the natural logarithmic base, specified by the constant, e.
Declaration
public const double E = 2.7182818284590451
Field Value
Type | Description |
---|---|
Double |
Remarks
The value of this field is 2.7182818284590452354.
PI
Represents the ratio of the circumference of a circle to its diameter, specified by the constant, π.
Declaration
public const double PI = 3.1415926535897931
Field Value
Type | Description |
---|---|
Double |
Remarks
The value of this field is 3.14159265358979323846.
Methods
Abs(Double)
Returns the absolute value of a double-precision floating-point number.
Declaration
public static extern double Abs(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value | A number that is greater than or equal to MinValue, but less than or equal to MaxValue. |
Returns
Type | Description |
---|---|
Double | A double-precision floating-point number, x, such that 0 ≤ x ≤ MaxValue. |
Abs(Int32)
Returns the absolute value of a 32-bit signed integer.
Declaration
public static int Abs(int value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | A number that is greater than MinValue, but less than or equal to MaxValue. |
Returns
Type | Description |
---|---|
Int32 | A 32-bit signed integer, x, such that 0 ≤ x ≤ MaxValue. |
Abs(Single)
Returns the absolute value of a single-precision floating-point number.
Declaration
public static extern float Abs(float value)
Parameters
Type | Name | Description |
---|---|---|
Single | value | A number that is greater than or equal to MinValue, but less than or equal to MaxValue. |
Returns
Type | Description |
---|---|
Single | A single-precision floating-point number, x, such that 0 ≤ x ≤ MaxValue. |
Acos(Double)
Returns the angle whose cosine is the specified number.
Declaration
public static extern double Acos(double d)
Parameters
Type | Name | Description |
---|---|---|
Double | d | A number representing a cosine, where d must be greater than or equal to -1, but less than or equal to 1. |
Returns
Type | Description |
---|---|
Double | An angle, θ, measured in radians, such that 0 ≤ θ ≤ π -or- NaN if d < -1 or d > 1 or d equals NaN. |
Asin(Double)
Returns the angle whose sine is the specified number.
Declaration
public static extern double Asin(double d)
Parameters
Type | Name | Description |
---|---|---|
Double | d | A number representing a sine, where d must be greater than or equal to -1, but less than or equal to 1. |
Returns
Type | Description |
---|---|
Double | An angle, θ, measured in radians, such that -π/2 ≤ θ ≤ π/2 -or- NaN if d < -1 or d> 1 or d equals NaN. |
Atan(Double)
Returns the angle whose tangent is the specified number.
Declaration
public static extern double Atan(double d)
Parameters
Type | Name | Description |
---|---|---|
Double | d | A number representing a tangent. |
Returns
Type | Description |
---|---|
Double | An angle, θ, measured in radians, such that -π/2 ≤ θ ≤ π/2. -or- NaN if d equals NaN, -π/2 rounded to double precision(-1.5707963267949) if d equals NegativeInfinity, or π/2 rounded to double precision(1.5707963267949) if d equals PositiveInfinity. |
Atan2(Double, Double)
Returns the angle whose tangent is the quotient of two specified numbers.
Declaration
public static extern double Atan2(double y, double x)
Parameters
Type | Name | Description |
---|---|---|
Double | y | The y coordinate of a point. |
Double | x | The x coordinate of a point. |
Returns
Type | Description |
---|---|
Double | An angle, θ, measured in radians, such that -π ≤ θ ≤ π, and tan(θ) = y / x, where (x, y) is a point in the Cartesian plane. |
Cbrt(Double)
Returns the cube root of a specified number.
Declaration
public static extern double Cbrt(double d)
Parameters
Type | Name | Description |
---|---|---|
Double | d | The number whose cube root is to be found. |
Returns
Type | Description |
---|---|
Double |
Ceiling(Double)
Returns the smallest integral value that is greater than or equal to the specified double-precision floating-point number.
Declaration
public static extern double Ceiling(double d)
Parameters
Type | Name | Description |
---|---|---|
Double | d | A double-precision floating-point number. |
Returns
Type | Description |
---|---|
Double | The smallest integral value that is greater than or equal to d. If d is equal to NaN, NegativeInfinity, or PositiveInfinity, that value is returned. Note that this method returns a Double instead of an integral type. |
Clamp(Double, Double, Double)
Returns value
clamped to the inclusive range of min
and max
.
Declaration
public static double Clamp(double value, double min, double max)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The value to be clamped. |
Double | min | The lower bound of the result. |
Double | max | The upper bound of the result. |
Returns
Type | Description |
---|---|
Double |
|
Exceptions
Type | Condition |
---|---|
ArgumentException | If |
Clamp(Int64, Int64, Int64)
Returns value
clamped to the inclusive range of min
and max
.
Declaration
public static long Clamp(long value, long min, long max)
Parameters
Type | Name | Description |
---|---|---|
Int64 | value | The value to be clamped. |
Int64 | min | The lower bound of the result. |
Int64 | max | The upper bound of the result. |
Returns
Type | Description |
---|---|
Int64 |
|
Exceptions
Type | Condition |
---|---|
ArgumentException | If |
Clamp(Single, Single, Single)
Returns value
clamped to the inclusive range of min
and max
.
Declaration
public static float Clamp(float value, float min, float max)
Parameters
Type | Name | Description |
---|---|---|
Single | value | The value to be clamped. |
Single | min | The lower bound of the result. |
Single | max | The upper bound of the result. |
Returns
Type | Description |
---|---|
Single |
|
Exceptions
Type | Condition |
---|---|
ArgumentException | If |
Clamp(UInt64, UInt64, UInt64)
Returns value
clamped to the inclusive range of min
and max
.
Declaration
public static ulong Clamp(ulong value, ulong min, ulong max)
Parameters
Type | Name | Description |
---|---|---|
UInt64 | value | The value to be clamped. |
UInt64 | min | The lower bound of the result. |
UInt64 | max | The upper bound of the result. |
Returns
Type | Description |
---|---|
UInt64 |
|
Exceptions
Type | Condition |
---|---|
ArgumentException | If |
Cos(Double)
Returns the cosine of the specified angle.
Declaration
public static extern double Cos(double a)
Parameters
Type | Name | Description |
---|---|---|
Double | a | An angle, measured in radians. |
Returns
Type | Description |
---|---|
Double | The cosine of a. If a is equal to NaN, NegativeInfinity, or PositiveInfinity, this method returns NaN. |
Cosh(Double)
Returns the hyperbolic cosine of the specified angle.
Declaration
public static extern double Cosh(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value | An angle, measured in radians. |
Returns
Type | Description |
---|---|
Double | The hyperbolic cosine of |
Exp(Double)
Returns e raised to the specified power.
Declaration
public static extern double Exp(double d)
Parameters
Type | Name | Description |
---|---|---|
Double | d | A number specifying a power. |
Returns
Type | Description |
---|---|
Double | The number e raised to the power |
Floor(Double)
Returns the largest integer less than or equal to the specified double-precision floating-point number.
Declaration
public static extern double Floor(double d)
Parameters
Type | Name | Description |
---|---|---|
Double | d | A double-precision floating-point number. |
Returns
Type | Description |
---|---|
Double | The largest integer less than or equal to |
IEEERemainder(Double, Double)
Returns the remainder resulting from the division of a specified number by another specified number.
Declaration
public static extern double IEEERemainder(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
Double | x | A dividend. |
Double | y | A divisor. |
Returns
Type | Description |
---|---|
Double | A number equal to |
Log(Double)
Returns the natural (base e) logarithm of a specified number.
Declaration
public static extern double Log(double d)
Parameters
Type | Name | Description |
---|---|---|
Double | d | The number whose logarithm is to be found. |
Returns
Type | Description |
---|---|
Double | The natural logarithm of |
Log10(Double)
Returns the base 10 logarithm of a specified number.
Declaration
public static extern double Log10(double d)
Parameters
Type | Name | Description |
---|---|---|
Double | d | A number whose logarithm is to be found. |
Returns
Type | Description |
---|---|
Double | The base 10 log of |
Max(Double, Double)
Returns the larger of two double-precision floating-point numbers.
Declaration
public static extern double Max(double val1, double val2)
Parameters
Type | Name | Description |
---|---|---|
Double | val1 | The first of two double-precision floating-point numbers to compare. |
Double | val2 | The second of two double-precision floating-point numbers to compare. |
Returns
Type | Description |
---|---|
Double | Parameter |
Max(Int32, Int32)
Returns the larger of two 32-bit signed integers.
Declaration
public static int Max(int val1, int val2)
Parameters
Type | Name | Description |
---|---|---|
Int32 | val1 | The first of two 32-bit signed integers to compare. |
Int32 | val2 | The second of two 32-bit signed integers to compare. |
Returns
Type | Description |
---|---|
Int32 | Parameter |
Max(Single, Single)
Returns the larger of two single-precision floating-point numbers.
Declaration
public static float Max(float val1, float val2)
Parameters
Type | Name | Description |
---|---|---|
Single | val1 | The first of two single-precision floating-point numbers to compare. |
Single | val2 | The second of two single-precision floating-point numbers to compare. |
Returns
Type | Description |
---|---|
Single | Parameter |
Min(Double, Double)
Returns the smaller of two double-precision floating-point numbers.
Declaration
public static extern double Min(double val1, double val2)
Parameters
Type | Name | Description |
---|---|---|
Double | val1 | The first of two double-precision floating-point numbers to compare. |
Double | val2 | The second of two double-precision floating-point numbers to compare. |
Returns
Type | Description |
---|---|
Double | Parameter |
Min(Int32, Int32)
Returns the smaller of two 32-bit signed integers.
Declaration
public static int Min(int val1, int val2)
Parameters
Type | Name | Description |
---|---|---|
Int32 | val1 | The first of two 32-bit signed integers to compare. |
Int32 | val2 | The second of two 32-bit signed integers to compare. |
Returns
Type | Description |
---|---|
Int32 | Parameter |
Min(Single, Single)
Returns the smaller of two single-precision floating-point numbers.
Declaration
public static float Min(float val1, float val2)
Parameters
Type | Name | Description |
---|---|---|
Single | val1 | The first of two single-precision floating-point numbers to compare. |
Single | val2 | The second of two single-precision floating-point numbers to compare. |
Returns
Type | Description |
---|---|
Single | Parameter |
Pow(Double, Double)
Returns a specified number raised to the specified power.
Declaration
public static extern double Pow(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
Double | x | A double-precision floating-point number to be raised to a power. |
Double | y | A double-precision floating-point number that specifies a power. |
Returns
Type | Description |
---|---|
Double | The number |
Round(Double)
Rounds a double-precision floating-point value to the nearest integral value.
Declaration
public static extern double Round(double a)
Parameters
Type | Name | Description |
---|---|---|
Double | a | A double-precision floating-point number to be rounded. |
Returns
Type | Description |
---|---|
Double | The integer nearest |
Sign(Double)
Returns a value indicating the sign of a double-precision floating-point number.
Declaration
public static extern int Sign(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value | A signed number. |
Returns
Type | Description |
---|---|
Int32 | A number that indicates the sign of |
Sign(Single)
Returns a value indicating the sign of a single-precision floating-point number.
Declaration
public static int Sign(float value)
Parameters
Type | Name | Description |
---|---|---|
Single | value | A signed number. |
Returns
Type | Description |
---|---|
Int32 | A number that indicates the sign of |
Sin(Double)
Returns the sine of the specified angle.
Declaration
public static extern double Sin(double a)
Parameters
Type | Name | Description |
---|---|---|
Double | a | An angle, measured in radians. |
Returns
Type | Description |
---|---|
Double | The sine of |
Sinh(Double)
Returns the hyperbolic sine of the specified angle.
Declaration
public static extern double Sinh(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value | An angle, measured in radians. |
Returns
Type | Description |
---|---|
Double | The hyperbolic sine of |
Sqrt(Double)
Returns the square root of a specified number.
Declaration
public static extern double Sqrt(double d)
Parameters
Type | Name | Description |
---|---|---|
Double | d | The number whose square root is to be found. |
Returns
Type | Description |
---|---|
Double | The positive square root of |
Tan(Double)
Returns the tangent of the specified angle.
Declaration
public static extern double Tan(double a)
Parameters
Type | Name | Description |
---|---|---|
Double | a | An angle, measured in radians. |
Returns
Type | Description |
---|---|
Double | The tangent of |
Tanh(Double)
Returns the hyperbolic tangent of the specified angle.
Declaration
public static extern double Tanh(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value | An angle, measured in radians. |
Returns
Type | Description |
---|---|
Double | The hyperbolic tangent of |
Truncate(Double)
Calculates the integral part of a specified double-precision floating-point number.
Declaration
public static extern double Truncate(double d)
Parameters
Type | Name | Description |
---|---|---|
Double | d | A number to truncate. |
Returns
Type | Description |
---|---|
Double | The integral part of |