Visual Basic 2010 Express

-->

The methods of the System.Math class provide trigonometric, logarithmic, and other common mathematical functions.

Remarks

The following table lists methods of the System.Math class. You can use these in a Visual Basic program:

.NET methodDescription
AbsReturns the absolute value of a number.
AcosReturns the angle whose cosine is the specified number.
AsinReturns the angle whose sine is the specified number.
AtanReturns the angle whose tangent is the specified number.
Atan2Returns the angle whose tangent is the quotient of two specified numbers.
BigMulReturns the full product of two 32-bit numbers.
CeilingReturns the smallest integral value that's greater than or equal to the specified Decimal or Double.
CosReturns the cosine of the specified angle.
CoshReturns the hyperbolic cosine of the specified angle.
DivRemReturns the quotient of two 32-bit or 64-bit signed integers, and also returns the remainder in an output parameter.
ExpReturns e (the base of natural logarithms) raised to the specified power.
FloorReturns the largest integer that's less than or equal to the specified Decimal or Double number.
IEEERemainderReturns the remainder that results from the division of a specified number by another specified number.
LogReturns the natural (base e) logarithm of a specified number or the logarithm of a specified number in a specified base.
Log10Returns the base 10 logarithm of a specified number.
MaxReturns the larger of two numbers.
MinReturns the smaller of two numbers.
PowReturns a specified number raised to the specified power.
RoundReturns a Decimal or Double value rounded to the nearest integral value or to a specified number of fractional digits.
SignReturns an Integer value indicating the sign of a number.
SinReturns the sine of the specified angle.
SinhReturns the hyperbolic sine of the specified angle.
SqrtReturns the square root of a specified number.
TanReturns the tangent of the specified angle.
TanhReturns the hyperbolic tangent of the specified angle.
TruncateCalculates the integral part of a specified Decimal or Double number.

The following table lists methods of the System.Math class that don't exist in .NET Framework but are added in .NET Standard or .NET Core:

.NET methodDescriptionAvailable in
AcoshReturns the angle whose hyperbolic cosine is the specified number.Starting with .NET Core 2.1 and .NET Standard 2.1
AsinhReturns the angle whose hyperbolic sine is the specified number.Starting with .NET Core 2.1 and .NET Standard 2.1
AtanhReturns the angle whose hyperbolic tangent is the specified number.Starting with .NET Core 2.1 and .NET Standard 2.1
BitDecrementReturns the next smallest value that compares less than x.Starting with .NET Core 3.0
BitIncrementReturns the next largest value that compares greater than x.Starting with .NET Core 3.0
CbrtReturns the cube root of a specified number.Starting with .NET Core 2.1 and .NET Standard 2.1
ClampReturns value clamped to the inclusive range of min and max.Starting with .NET Core 2.0 and .NET Standard 2.1
CopySignReturns a value with the magnitude of x and the sign of y.Starting with .NET Core 3.0
FusedMultiplyAddReturns (x * y) + z, rounded as one ternary operation.Starting with .NET Core 3.0
ILogBReturns the base 2 integer logarithm of a specified number.Starting with .NET Core 3.0
Log2Returns the base 2 logarithm of a specified number.Starting with .NET Core 3.0
MaxMagnitudeReturns the larger magnitude of two double-precision floating-point numbers.Starting with .NET Core 3.0
MinMagnitudeReturns the smaller magnitude of two double-precision floating-point numbers.Starting with .NET Core 3.0
ScaleBReturns x * 2^n computed efficiently.Starting with .NET Core 3.0 To use these functions without qualification, import the System.Math namespace into your project by adding the following code to the top of your source file:

Example - Abs This example uses the Abs method of the Math class to compute the absolute value of a number.

Example - Atan

This example uses the Atan method of the Math class to calculate the value of pi.

Note

The System.Math class contains Math.PI constant field. You can use it rather than calculating it.

Example - Cos

This example uses the Cos method of the Math class to return the cosine of an angle.

Microsoft Visual Studio 2010

This example uses the Exp method of the Math class to return e raised to a power.

Example - Log

This example uses the Log method of the Math class to return the natural logarithm of a number.

Example - Round

This example uses the Round method of the Math class to round a number to the nearest integer.

Example - Sign

This example uses the Sign method of the Math class to determine the sign of a number.

Example - Sin

This example uses the Sin method of the Math class to return the sine of an angle. Example - Sqrt

This example uses the Sqrt method of the Math class to calculate the square root of a number.

Example - Tan

This example uses the Tan method of the Math class to return the tangent of an angle. 