Table of Contents

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

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

public const double PI = 3.141592653589793

Field Value

double

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 double

A number that is greater than or equal to MinValue, but less than or equal to MaxValue.

Returns

double

A double-precision floating-point number, x, such that 0 ≤ x ≤ MaxValue.

Abs(int)

Returns the absolute value of a 32-bit signed integer.

public static int Abs(int value)

Parameters

value int

A number that is greater than MinValue, but less than or equal to MaxValue.

Returns

int

A 32-bit signed integer, x, such that 0 ≤ x ≤ MaxValue.

Abs(float)

Returns the absolute value of a single-precision floating-point number.

public static float Abs(float value)

Parameters

value float

A number that is greater than or equal to MinValue, but less than or equal to MaxValue.

Returns

float

A single-precision floating-point number, x, such that 0 ≤ x ≤ MaxValue.

Acos(double)

Returns the angle whose cosine is the specified number.

public static double Acos(double d)

Parameters

d double

A 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 double

A 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 double

A 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

y double

The y coordinate of a point.

x double

The x coordinate of a point.

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 double

The number whose cube root is to be found.

Returns

double

The cube root of d. -or- NaN if d equals NaN.

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 double

A 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 double

The value to be clamped.

min double

The lower bound of the result.

max double

The upper bound of the result.

Returns

double

value if minvaluemax. -or- min if value<min. -or- max if max<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 long

The value to be clamped.

min long

The lower bound of the result.

max long

The upper bound of the result.

Returns

long

value if minvaluemax. -or- min if value<min. -or- max if max<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 float

The value to be clamped.

min float

The lower bound of the result.

max float

The upper bound of the result.

Returns

float

value if minvaluemax. -or- min if value<min. -or- max if max<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 ulong

The value to be clamped.

min ulong

The lower bound of the result.

max ulong

The upper bound of the result.

Returns

ulong

value if minvaluemax. -or- min if value<min. -or- max if max<value.

Exceptions

ArgumentException

If max < min.

Cos(double)

Returns the cosine of the specified angle.

public static double Cos(double a)

Parameters

a double

An 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 double

An angle, measured in radians.

Returns

double

The hyperbolic cosine of value. If value 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 double

A number specifying a power.

Returns

double

The number e raised to the power d. If d equals NaN or PositiveInfinity, that value is returned. If d 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 double

A double-precision floating-point number.

Returns

double

The largest integer less than or equal to d. If d 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

x double

A dividend.

y double

A divisor.

Returns

double

A number equal to x - (y Q), where Q is the quotient of x / y rounded to the nearest integer (if x / y falls halfway between two integers, the even integer is returned). If x - (y Q) is zero, the value +0 is returned if x is positive, or -0 if x is negative. If y = 0, NaN is returned.

Log(double)

Returns the natural (base e) logarithm of a specified number.

public static double Log(double d)

Parameters

d double

The number whose logarithm is to be found.

Returns

double

The natural logarithm of d; that is, ln d, or log e d

Log10(double)

Returns the base 10 logarithm of a specified number.

public static double Log10(double d)

Parameters

d double

A number whose logarithm is to be found.

Returns

double

The base 10 log of d; that is, log 10 d.

Max(double, double)

Returns the larger of two double-precision floating-point numbers.

public static double Max(double val1, double val2)

Parameters

val1 double

The first of two double-precision floating-point numbers to compare.

val2 double

The second of two double-precision floating-point numbers to compare.

Returns

double

Parameter val1 or val2, whichever is larger. If val1, val2, or both val1 and val2 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 int

The first of two 32-bit signed integers to compare.

val2 int

The second of two 32-bit signed integers to compare.

Returns

int

Parameter val1 or val2, 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 float

The first of two single-precision floating-point numbers to compare.

val2 float

The second of two single-precision floating-point numbers to compare.

Returns

float

Parameter val1 or val2, whichever is larger. If val1, or val2, or both val1 and val2 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 double

The first of two double-precision floating-point numbers to compare.

val2 double

The second of two double-precision floating-point numbers to compare.

Returns

double

Parameter val1 or val2, whichever is smaller. If val1, val2, or both val1 and val2 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 int

The first of two 32-bit signed integers to compare.

val2 int

The second of two 32-bit signed integers to compare.

Returns

int

Parameter val1 or val2, 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 float

The first of two single-precision floating-point numbers to compare.

val2 float

The second of two single-precision floating-point numbers to compare.

Returns

float

Parameter val1 or val2, whichever is smaller. If val1, val2, or both val1 and val2 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 double

A double-precision floating-point number to be raised to a power.

y double

A double-precision floating-point number that specifies a power.

Returns

double

The number x raised to the power y.

Round(double)

Rounds a double-precision floating-point value to the nearest integral value.

public static double Round(double a)

Parameters

a double

A double-precision floating-point number to be rounded.

Returns

double

The integer nearest a. If the fractional component of a 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 double

A 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 float

A 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 double

An 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 double

An angle, measured in radians.

Returns

double

The hyperbolic sine of value. If value is equal to NegativeInfinity, PositiveInfinity, or NaN, this method returns a double equal to value.

Sqrt(double)

Returns the square root of a specified number.

public static double Sqrt(double d)

Parameters

d double

The 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 double

An angle, measured in radians.

Returns

double

The tangent of a. If a 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 double

An angle, measured in radians.

Returns

double

The hyperbolic tangent of value. If value is equal to NegativeInfinity, this method returns -1. If value is equal to PositiveInfinity, this method returns 1. If value 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 double

A number to truncate.

Returns

double

The integral part of d; that is, the number that remains after any fractional digits have been discarded.