Class Math
- Namespace
- System
- Assembly
- System.Math.dll
Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions.
public static class Math
- Inheritance
-
Math
- Inherited Members
Fields
E
Represents the natural logarithmic base, specified by the constant, e.
public const double E = 2.718281828459045
Field Value
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, π.
public const double PI = 3.141592653589793
Field Value
Remarks
The value of this field is 3.14159265358979323846.
Methods
Abs(double)
Returns the absolute value of a double-precision floating-point number.
public static double Abs(double value)
Parameters
valuedoubleA number that is greater than or equal to MinValue, but less than or equal to MaxValue.
Returns
Abs(int)
Returns the absolute value of a 32-bit signed integer.
public static int Abs(int value)
Parameters
Returns
Abs(float)
Returns the absolute value of a single-precision floating-point number.
public static float Abs(float value)
Parameters
Returns
Acos(double)
Returns the angle whose cosine is the specified number.
public static double Acos(double d)
Parameters
ddoubleA number representing a cosine, where d must be greater than or equal to -1, but less than or equal to 1.
Returns
- 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.
public static double Asin(double d)
Parameters
ddoubleA number representing a sine, where d must be greater than or equal to -1, but less than or equal to 1.
Returns
- 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.
public static double Atan(double d)
Parameters
ddoubleA number representing a tangent.
Returns
- 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.
public static double Atan2(double y, double x)
Parameters
Returns
- 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.
public static double Cbrt(double d)
Parameters
ddoubleThe number whose cube root is to be found.
Returns
Ceiling(double)
Returns the smallest integral value that is greater than or equal to the specified double-precision floating-point number.
public static double Ceiling(double d)
Parameters
ddoubleA double-precision floating-point number.
Returns
- 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.
public static double Clamp(double value, double min, double max)
Parameters
valuedoubleThe value to be clamped.
mindoubleThe lower bound of the result.
maxdoubleThe upper bound of the result.
Returns
- double
valueifmin≤value≤max. -or-minifvalue<min. -or- max ifmax<value.
Exceptions
- ArgumentException
If
max<min.
Clamp(long, long, long)
Returns value clamped to the inclusive range of min and max.
public static long Clamp(long value, long min, long max)
Parameters
valuelongThe value to be clamped.
minlongThe lower bound of the result.
maxlongThe upper bound of the result.
Returns
- long
valueifmin≤value≤max. -or-minifvalue<min. -or- max ifmax<value.
Exceptions
- ArgumentException
If
max<min.
Clamp(float, float, float)
Returns value clamped to the inclusive range of min and max.
public static float Clamp(float value, float min, float max)
Parameters
valuefloatThe value to be clamped.
minfloatThe lower bound of the result.
maxfloatThe upper bound of the result.
Returns
- float
valueifmin≤value≤max. -or-minifvalue<min. -or- max ifmax<value.
Exceptions
- ArgumentException
If
max<min.
Clamp(ulong, ulong, ulong)
Returns value clamped to the inclusive range of min and max.
public static ulong Clamp(ulong value, ulong min, ulong max)
Parameters
valueulongThe value to be clamped.
minulongThe lower bound of the result.
maxulongThe upper bound of the result.
Returns
- ulong
valueifmin≤value≤max. -or-minifvalue<min. -or- max ifmax<value.
Exceptions
- ArgumentException
If
max<min.
Cos(double)
Returns the cosine of the specified angle.
public static double Cos(double a)
Parameters
adoubleAn angle, measured in radians.
Returns
- 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.
public static double Cosh(double value)
Parameters
valuedoubleAn angle, measured in radians.
Returns
- double
The hyperbolic cosine of
value. Ifvalueis equal to NegativeInfinity or PositiveInfinity, PositiveInfinity is returned. If value is equal to NaN, NaN is returned.
Exp(double)
Returns e raised to the specified power.
public static double Exp(double d)
Parameters
ddoubleA number specifying a power.
Returns
- double
The number e raised to the power
d. Ifdequals NaN or PositiveInfinity, that value is returned. Ifdequals NegativeInfinity, 0 is returned.
Floor(double)
Returns the largest integer less than or equal to the specified double-precision floating-point number.
public static double Floor(double d)
Parameters
ddoubleA double-precision floating-point number.
Returns
- double
The largest integer less than or equal to
d. Ifdis equal to NaN, NegativeInfinity, or PositiveInfinity, that value is returned.
IEEERemainder(double, double)
Returns the remainder resulting from the division of a specified number by another specified number.
public static double IEEERemainder(double x, double y)
Parameters
Returns
- double
A number equal to
x- (yQ), where Q is the quotient ofx/yrounded to the nearest integer (ifx/yfalls halfway between two integers, the even integer is returned). Ifx- (yQ) is zero, the value +0 is returned ifxis positive, or -0 ifxis negative. Ify= 0, NaN is returned.
Log(double)
Returns the natural (base e) logarithm of a specified number.
public static double Log(double d)
Parameters
ddoubleThe number whose logarithm is to be found.
Returns
- double
The natural logarithm of
d; that is, lnd, or log ed
Log10(double)
Returns the base 10 logarithm of a specified number.
public static double Log10(double d)
Parameters
ddoubleA number whose logarithm is to be found.
Returns
- double
The base 10 log of
d; that is, log 10d.
Max(double, double)
Returns the larger of two double-precision floating-point numbers.
public static double Max(double val1, double val2)
Parameters
val1doubleThe first of two double-precision floating-point numbers to compare.
val2doubleThe second of two double-precision floating-point numbers to compare.
Returns
- double
Parameter
val1orval2, whichever is larger. Ifval1,val2, or bothval1andval2are equal to NaN, NaN is returned.
Max(int, int)
Returns the larger of two 32-bit signed integers.
public static int Max(int val1, int val2)
Parameters
val1intThe first of two 32-bit signed integers to compare.
val2intThe second of two 32-bit signed integers to compare.
Returns
- int
Parameter
val1orval2, whichever is larger.
Max(float, float)
Returns the larger of two single-precision floating-point numbers.
public static float Max(float val1, float val2)
Parameters
val1floatThe first of two single-precision floating-point numbers to compare.
val2floatThe second of two single-precision floating-point numbers to compare.
Returns
- float
Parameter
val1orval2, whichever is larger. Ifval1, orval2, or bothval1andval2are equal to NaN, NaN is returned.
Min(double, double)
Returns the smaller of two double-precision floating-point numbers.
public static double Min(double val1, double val2)
Parameters
val1doubleThe first of two double-precision floating-point numbers to compare.
val2doubleThe second of two double-precision floating-point numbers to compare.
Returns
- double
Parameter
val1orval2, whichever is smaller. Ifval1,val2, or bothval1andval2are equal to NaN, NaN is returned.
Min(int, int)
Returns the smaller of two 32-bit signed integers.
public static int Min(int val1, int val2)
Parameters
val1intThe first of two 32-bit signed integers to compare.
val2intThe second of two 32-bit signed integers to compare.
Returns
- int
Parameter
val1orval2, whichever is smaller.
Min(float, float)
Returns the smaller of two single-precision floating-point numbers.
public static float Min(float val1, float val2)
Parameters
val1floatThe first of two single-precision floating-point numbers to compare.
val2floatThe second of two single-precision floating-point numbers to compare.
Returns
- float
Parameter
val1orval2, whichever is smaller. Ifval1,val2, or bothval1andval2are equal to NaN, NaN is returned.
Pow(double, double)
Returns a specified number raised to the specified power.
public static double Pow(double x, double y)
Parameters
xdoubleA double-precision floating-point number to be raised to a power.
ydoubleA double-precision floating-point number that specifies a power.
Returns
- double
The number
xraised to the powery.
Round(double)
Rounds a double-precision floating-point value to the nearest integral value.
public static double Round(double a)
Parameters
adoubleA double-precision floating-point number to be rounded.
Returns
- double
The integer nearest
a. If the fractional component ofais halfway between two integers, one of which is even and the other odd, then the even number is returned. Note that this method returns a double instead of an integral type.
Sign(double)
Returns a value indicating the sign of a double-precision floating-point number.
public static int Sign(double value)
Parameters
valuedoubleA signed number.
Returns
- int
A number that indicates the sign of
value.
Sign(float)
Returns a value indicating the sign of a single-precision floating-point number.
public static int Sign(float value)
Parameters
valuefloatA signed number.
Returns
- int
A number that indicates the sign of
value.
Sin(double)
Returns the sine of the specified angle.
public static double Sin(double a)
Parameters
adoubleAn angle, measured in radians.
Returns
- double
The sine of
a. If a is equal to NaN, NegativeInfinity, or PositiveInfinity, this method returns NaN.
Sinh(double)
Returns the hyperbolic sine of the specified angle.
public static double Sinh(double value)
Parameters
valuedoubleAn angle, measured in radians.
Returns
- double
The hyperbolic sine of
value. Ifvalueis equal to NegativeInfinity, PositiveInfinity, or NaN, this method returns a double equal tovalue.
Sqrt(double)
Returns the square root of a specified number.
public static double Sqrt(double d)
Parameters
ddoubleThe number whose square root is to be found.
Returns
- double
The positive square root of
d.
Tan(double)
Returns the tangent of the specified angle.
public static double Tan(double a)
Parameters
adoubleAn angle, measured in radians.
Returns
- double
The tangent of
a. Ifais equal to NaN, NegativeInfinity, or PositiveInfinity, this method returns NaN.
Tanh(double)
Returns the hyperbolic tangent of the specified angle.
public static double Tanh(double value)
Parameters
valuedoubleAn angle, measured in radians.
Returns
- double
The hyperbolic tangent of
value. Ifvalueis equal to NegativeInfinity, this method returns -1. Ifvalueis equal to PositiveInfinity, this method returns 1. Ifvalueis equal to NaN, this method returns NaN.
Truncate(double)
Calculates the integral part of a specified double-precision floating-point number.
public static double Truncate(double d)
Parameters
ddoubleA number to truncate.
Returns
- double
The integral part of
d; that is, the number that remains after any fractional digits have been discarded.