数学函数 (Visual Basic)

System.Math 选件类的方法提供三角形,对数和其他常见的算术函数。

备注

下表列出了 System.Math 选件类的方法。在 Visual Basic 程序可以使用它们。

.NET Framework 方法

描述

Abs

返回数字的绝对值。

Acos

返回余弦值为指定数字的角度。

Asin

返回正弦值为指定数字的角度。

Atan

返回正切值为指定数字的角度。

Atan2

返回正切值为两个指定数字的商的角度。

BigMul

返回两个 32 位数完整的产品。

Ceiling

返回大于或等于指定的 Decimal 或 Double的最小整数值。

Cos

返回指定角度的余弦值。

Cosh

返回指定角度的双曲余弦值。

DivRem

返回两个 32 位或 64 位带符号整数控件,并返回该输出参数的其余部分。

Exp

返回 e (自然对数的底) 引发到指定的幂次。

Floor

返回小于或等于指定的 Decimal 或 Double 数字的最大的整数。

IEEERemainder

返回余数会将一个指定数目的部门的结果是由另一个指定数目。

Log

返回指定数量的自然对数 e(基) 或一个指定数量的对数在指定的基础。

Log10

返回指定数字以 10 为底的对数。

Max

返回大两个数字。

Min

返回两个数字中较小的一个。

Pow

返回指定数字的指定次幂。

Round

返回 Decimal 或 Double 值四舍五入到最新的整数值或对小数位指定数目的。

Sign

返回表示数字符号的 Integer 值。

Sin

返回指定角度的正弦值。

Sinh

返回指定角度的双曲正弦值。

Sqrt

返回指定数字的平方根。

Tan

返回指定角度的正切值。

Tanh

返回指定角度的双曲正切值。

Truncate

计算一个指定的 Decimal 或 Double 数字组成部分。

若要使用这些功能,无需限定,则应导入命名空间 System.Math 到可通过将以下代码添加到源文件顶部:

Imports System.Math

示例

本示例使用 Math 类的 Abs 方法来计算一个数字的绝对值。

' Returns 50.3.
Dim MyNumber1 As Double = Math.Abs(50.3)
' Returns 50.3.
Dim MyNumber2 As Double = Math.Abs(-50.3)

本示例使用 Math 类的 Atan 方法计算 pi 的值。

Public Function GetPi() As Double
    ' Calculate the value of pi.
    Return 4.0 * Math.Atan(1.0)
End Function

本示例使用 Math 类的 Cos 方法返回角度的余弦值。

Public Function Sec(ByVal angle As Double) As Double
    ' Calculate the secant of angle, in radians.
    Return 1.0 / Math.Cos(angle)
End Function

本示例使用 Math 类的 Exp 方法返回以 e 为底的幂。

Public Function Sinh(ByVal angle As Double) As Double
    ' Calculate hyperbolic sine of an angle, in radians.
    Return (Math.Exp(angle) - Math.Exp(-angle)) / 2.0
End Function

本示例使用 Math 类的 Log 方法返回数字的自然对数。

Public Function Asinh(ByVal value As Double) As Double
    ' Calculate inverse hyperbolic sine, in radians.
    Return Math.Log(value + Math.Sqrt(value * value + 1.0))
End Function

本示例使用 Math 类的 Round 方法将数字舍入为最接近的整数。

' Returns 3.
Dim MyVar2 As Double = Math.Round(2.8)

本示例使用 Math 类的 Sign 方法确定数字的符号。

' Returns 1.
Dim MySign1 As Integer = Math.Sign(12)
' Returns -1.
Dim MySign2 As Integer = Math.Sign(-2.4)
' Returns 0.
Dim MySign3 As Integer = Math.Sign(0)

本示例使用 Math 类的 Sin 方法返回角度的正弦值。

Public Function Csc(ByVal angle As Double) As Double
    ' Calculate cosecant of an angle, in radians.
    Return 1.0 / Math.Sin(angle)
End Function

本示例使用 Math 类的 Sqrt 方法计算数字的平方根。

' Returns 2.
Dim MySqr1 As Double = Math.Sqrt(4)
' Returns 4.79583152331272.
Dim MySqr2 As Double = Math.Sqrt(23)
' Returns 0.
Dim MySqr3 As Double = Math.Sqrt(0)
' Returns NaN (not a number).
Dim MySqr4 As Double = Math.Sqrt(-4)

本示例使用 Math 类的 Tan 方法返回角度的正切值。

Public Function Ctan(ByVal angle As Double) As Double
    ' Calculate cotangent of an angle, in radians.
    Return 1.0 / Math.Tan(angle)
End Function

要求

类:Math

命名空间:System

**程序集:**mscorlib(位于 mscorlib.dll 中)

请参见

参考

Rnd

Randomize

NaN

算术运算符 (Visual Basic)

概念

派生的数学函数 (Visual Basic)