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
value
doubleA 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
d
doubleA 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
d
doubleA 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
d
doubleA 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
d
doubleThe 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
d
doubleA 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
value
doubleThe value to be clamped.
min
doubleThe lower bound of the result.
max
doubleThe upper bound of the result.
Returns
- double
value
ifmin
≤value
≤max
. -or-min
ifvalue
<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
value
longThe value to be clamped.
min
longThe lower bound of the result.
max
longThe upper bound of the result.
Returns
- long
value
ifmin
≤value
≤max
. -or-min
ifvalue
<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
value
floatThe value to be clamped.
min
floatThe lower bound of the result.
max
floatThe upper bound of the result.
Returns
- float
value
ifmin
≤value
≤max
. -or-min
ifvalue
<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
value
ulongThe value to be clamped.
min
ulongThe lower bound of the result.
max
ulongThe upper bound of the result.
Returns
- ulong
value
ifmin
≤value
≤max
. -or-min
ifvalue
<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
a
doubleAn 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
value
doubleAn angle, measured in radians.
Returns
- double
The hyperbolic cosine of
value
. Ifvalue
is 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
d
doubleA number specifying a power.
Returns
- double
The number e raised to the power
d
. Ifd
equals NaN or PositiveInfinity, that value is returned. Ifd
equals 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
d
doubleA double-precision floating-point number.
Returns
- double
The largest integer less than or equal to
d
. Ifd
is 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
- (y
Q), where Q is the quotient ofx
/y
rounded to the nearest integer (ifx
/y
falls halfway between two integers, the even integer is returned). Ifx
- (y
Q) is zero, the value +0 is returned ifx
is positive, or -0 ifx
is 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
d
doubleThe 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
d
doubleA 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
val1
doubleThe first of two double-precision floating-point numbers to compare.
val2
doubleThe second of two double-precision floating-point numbers to compare.
Returns
- double
Parameter
val1
orval2
, whichever is larger. Ifval1
,val2
, or bothval1
andval2
are 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
val1
intThe first of two 32-bit signed integers to compare.
val2
intThe second of two 32-bit signed integers to compare.
Returns
- int
Parameter
val1
orval2
, 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
val1
floatThe first of two single-precision floating-point numbers to compare.
val2
floatThe second of two single-precision floating-point numbers to compare.
Returns
- float
Parameter
val1
orval2
, whichever is larger. Ifval1
, orval2
, or bothval1
andval2
are 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
val1
doubleThe first of two double-precision floating-point numbers to compare.
val2
doubleThe second of two double-precision floating-point numbers to compare.
Returns
- double
Parameter
val1
orval2
, whichever is smaller. Ifval1
,val2
, or bothval1
andval2
are 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
val1
intThe first of two 32-bit signed integers to compare.
val2
intThe second of two 32-bit signed integers to compare.
Returns
- int
Parameter
val1
orval2
, 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
val1
floatThe first of two single-precision floating-point numbers to compare.
val2
floatThe second of two single-precision floating-point numbers to compare.
Returns
- float
Parameter
val1
orval2
, whichever is smaller. Ifval1
,val2
, or bothval1
andval2
are 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
x
doubleA double-precision floating-point number to be raised to a power.
y
doubleA double-precision floating-point number that specifies a power.
Returns
- double
The number
x
raised to the powery
.
Round(double)
Rounds a double-precision floating-point value to the nearest integral value.
public static double Round(double a)
Parameters
a
doubleA double-precision floating-point number to be rounded.
Returns
- double
The integer nearest
a
. If the fractional component ofa
is 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
value
doubleA 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
value
floatA 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
a
doubleAn 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
value
doubleAn angle, measured in radians.
Returns
- double
The hyperbolic sine of
value
. Ifvalue
is 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
d
doubleThe 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
a
doubleAn angle, measured in radians.
Returns
- double
The tangent of
a
. Ifa
is 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
value
doubleAn angle, measured in radians.
Returns
- double
The hyperbolic tangent of
value
. Ifvalue
is equal to NegativeInfinity, this method returns -1. Ifvalue
is equal to PositiveInfinity, this method returns 1. Ifvalue
is 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
d
doubleA number to truncate.
Returns
- double
The integral part of
d
; that is, the number that remains after any fractional digits have been discarded.