数学函数 | 您所在的位置:网站首页 › vb编程常用函数是什么 › 数学函数 |
数学函数 (Visual Basic)
项目05/09/2023
System.Math 类的方法提供三角函数、对数函数和其他常见的数学函数。 注解下表列出了 System.Math 类的方法。 你可以在 Visual Basic 程序中使用以下函数: .NET 方法 说明 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 数字的整数部分。下表列出了 .NET Framework 中不存在但在 .NET Standard 或 .NET Core 中新增加的 System.Math 类的方法: .NET 方法 说明 适用于 Acosh 返回双曲余弦值为指定数字的角度。 从 .NET Core 2.1 和 .NET Standard 2.1 开始 Asinh 返回双曲正弦值为指定数字的角度。 从 .NET Core 2.1 和 .NET Standard 2.1 开始 Atanh 返回双曲正切值为指定数字的角度。 从 .NET Core 2.1 和 .NET Standard 2.1 开始 BitDecrement 返回小于 x 的下一个最小值。 从 .NET Core 3.0 开始 BitIncrement 返回大于 x 的下一个最大值。 从 .NET Core 3.0 开始 Cbrt 返回指定数字的立方根。 从 .NET Core 2.1 和 .NET Standard 2.1 开始 Clamp 返回限制在 min 和 max 范围内(含首尾)的 value。 从 .NET Core 2.0 和 .NET Standard 2.1 开始 CopySign 返回一个值,它具有 x 的大小和 y 的符号。 从 .NET Core 3.0 开始 FusedMultiplyAdd 返回 (x * y) + z,舍入为一个三元运算。 从 .NET Core 3.0 开始 ILogB 返回指定数字以 2 为底的整数对数。 从 .NET Core 3.0 开始 Log2 返回指定数字以 2 为底的对数。 从 .NET Core 3.0 开始 MaxMagnitude 返回两个双精度浮点数字中的较大值。 从 .NET Core 3.0 开始 MinMagnitude 返回两个双精度浮点数字中的较小值。 从 .NET Core 3.0 开始 ScaleB 返回有效计算的 x * 2^n。 从 .NET Core 3.0 开始要在没有限定的情况下使用这些函数,请将以下代码添加到源文件的顶部,从而将 System.Math 命名空间导入到你的项目中: Imports System.Math 示例 - 绝对值此示例使用 Math 类的 Abs 方法来计算一个数的绝对值。 Dim x As Double = Math.Abs(50.3) Dim y As Double = Math.Abs(-50.3) Console.WriteLine(x) Console.WriteLine(y) ' This example produces the following output: ' 50.3 ' 50.3 示例 - Atan此示例使用 Math 类的 Atan 方法来计算圆周率 π 的值。 Public Function GetPi() As Double ' Calculate the value of pi. Return 4.0 * Math.Atan(1.0) End Function注意 System.Math 类包含 Math.PI 常量字段。 你可以使用此常量字段,而不是计算此常量字段。 示例 - Cos此示例使用 Math 类的 Cos 方法返回一个角度的余弦值。 Public Function Sec(angle As Double) As Double ' Calculate the secant of angle, in radians. Return 1.0 / Math.Cos(angle) End Function 示例 - Exp此示例使用 Math 类的 Exp 方法来返回 e 的幂。 Public Function Sinh(angle As Double) As Double ' Calculate hyperbolic sine of an angle, in radians. Return (Math.Exp(angle) - Math.Exp(-angle)) / 2.0 End Function 示例 - Log此示例使用 Log 类的 Math 方法返回数字的自然对数。 Public Function Asinh(value As Double) As Double ' Calculate inverse hyperbolic sine, in radians. Return Math.Log(value + Math.Sqrt(value * value + 1.0)) End Function 示例 - Round此示例使用 Round 类的 Math 方法将数字舍入为最接近的整数。 Dim myVar2 As Double = Math.Round(2.8) Console.WriteLine(myVar2) ' The code produces the following output: ' 3 示例 - Sign此示例使用 Math 类的 Sign 方法来确定数字的符号。 Dim mySign1 As Integer = Math.Sign(12) Dim mySign2 As Integer = Math.Sign(-2.4) Dim mySign3 As Integer = Math.Sign(0) Console.WriteLine(mySign1) Console.WriteLine(mySign2) Console.WriteLine(mySign3) ' The code produces the following output: ' 1 ' -1 ' 0 示例 - Sin此示例使用 Math 类的 Sin 方法返回一个角度的正弦值。 Public Function Csc(angle As Double) As Double ' Calculate cosecant of an angle, in radians. Return 1.0 / Math.Sin(angle) End Function 示例 - Sqrt此示例使用 Sqrt 类的 Math 方法计算数字的平方根。 Dim mySqrt1 As Double = Math.Sqrt(4) Dim mySqrt2 As Double = Math.Sqrt(23) Dim mySqrt3 As Double = Math.Sqrt(0) Dim mySqrt4 As Double = Math.Sqrt(-4) Console.WriteLine(mySqrt1) Console.WriteLine(mySqrt2) Console.WriteLine(mySqrt3) Console.WriteLine(mySqrt4) ' The code produces the following output: ' 2 ' 4.79583152331272 ' 0 ' NaN 示例 - Tan此示例使用 Math 类的 Tan 方法返回一个角度的正正切值。 Public Function Ctan(angle As Double) As Double ' Calculate cotangent of an angle, in radians. Return 1.0 / Math.Tan(angle) End Function 另请参阅 Rnd Randomize NaN 派生的数学函数 算术运算符 |
CopyRight 2018-2019 实验室设备网 版权所有 |