You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Update math-functions.md
* Add methods that are new in .NET Core and .NET Standard
* Use Console.WriteLine
* Fix table
* Update math-functions.md
* update ms.date
Co-authored-by: Maira Wenzel <mairaw@microsoft.com>
The methods of the <xref:System.Math?displayProperty=nameWithType> class provide trigonometric, logarithmic, and other common mathematical functions.
13
-
14
-
## Remarks
15
-
The following table lists methods of the <xref:System.Math?displayProperty=nameWithType> class. You can use these in a Visual Basic program.
16
-
17
-
|.NET method|Description|
18
-
|---------------------------|-----------------|
19
-
|<xref:System.Math.Abs%2A>|Returns the absolute value of a number.|
20
-
|<xref:System.Math.Acos%2A>|Returns the angle whose cosine is the specified number.|
21
-
|<xref:System.Math.Asin%2A>|Returns the angle whose sine is the specified number.|
22
-
|<xref:System.Math.Atan%2A>|Returns the angle whose tangent is the specified number.|
23
-
|<xref:System.Math.Atan2%2A>|Returns the angle whose tangent is the quotient of two specified numbers.|
24
-
|<xref:System.Math.BigMul%2A>|Returns the full product of two 32-bit numbers.|
25
-
|<xref:System.Math.Ceiling%2A>|Returns the smallest integral value that's greater than or equal to the specified `Decimal` or `Double`.|
26
-
|<xref:System.Math.Cos%2A>|Returns the cosine of the specified angle.|
27
-
|<xref:System.Math.Cosh%2A>|Returns the hyperbolic cosine of the specified angle.|
28
-
|<xref:System.Math.DivRem%2A>|Returns the quotient of two 32-bit or 64-bit signed integers, and also returns the remainder in an output parameter.|
29
-
|<xref:System.Math.Exp%2A>|Returns e (the base of natural logarithms) raised to the specified power.|
30
-
|<xref:System.Math.Floor%2A>|Returns the largest integer that's less than or equal to the specified `Decimal` or `Double` number.|
31
-
|<xref:System.Math.IEEERemainder%2A>|Returns the remainder that results from the division of a specified number by another specified number.|
32
-
|<xref:System.Math.Log%2A>|Returns the natural (base e) logarithm of a specified number or the logarithm of a specified number in a specified base.|
33
-
|<xref:System.Math.Log10%2A>|Returns the base 10 logarithm of a specified number.|
34
-
|<xref:System.Math.Max%2A>|Returns the larger of two numbers.|
35
-
|<xref:System.Math.Min%2A>|Returns the smaller of two numbers.|
36
-
|<xref:System.Math.Pow%2A>|Returns a specified number raised to the specified power.|
37
-
|<xref:System.Math.Round%2A>|Returns a `Decimal` or `Double` value rounded to the nearest integral value or to a specified number of fractional digits.|
38
-
|<xref:System.Math.Sign%2A>|Returns an `Integer` value indicating the sign of a number.|
39
-
|<xref:System.Math.Sin%2A>|Returns the sine of the specified angle.|
40
-
|<xref:System.Math.Sinh%2A>|Returns the hyperbolic sine of the specified angle.|
41
-
|<xref:System.Math.Sqrt%2A>|Returns the square root of a specified number.|
42
-
|<xref:System.Math.Tan%2A>|Returns the tangent of the specified angle.|
43
-
|<xref:System.Math.Tanh%2A>|Returns the hyperbolic tangent of the specified angle.|
44
-
|<xref:System.Math.Truncate%2A>|Calculates the integral part of a specified `Decimal` or `Double` number.|
45
-
46
-
To use these functions without qualification, import the <xref:System.Math?displayProperty=nameWithType> namespace into your project by adding the following code to the top of your source file:
47
-
12
+
13
+
The methods of the <xref:System.Math?displayProperty=nameWithType> class provide trigonometric, logarithmic, and other common mathematical functions.
14
+
15
+
## Remarks
16
+
17
+
The following table lists methods of the <xref:System.Math?displayProperty=nameWithType> class. You can use these in a Visual Basic program:
18
+
19
+
|.NET method|Description|
20
+
|---------------------------|-----------------|
21
+
|<xref:System.Math.Abs%2A>|Returns the absolute value of a number.|
22
+
|<xref:System.Math.Acos%2A>|Returns the angle whose cosine is the specified number.|
23
+
|<xref:System.Math.Asin%2A>|Returns the angle whose sine is the specified number.|
24
+
|<xref:System.Math.Atan%2A>|Returns the angle whose tangent is the specified number.|
25
+
|<xref:System.Math.Atan2%2A>|Returns the angle whose tangent is the quotient of two specified numbers.|
26
+
|<xref:System.Math.BigMul%2A>|Returns the full product of two 32-bit numbers.|
27
+
|<xref:System.Math.Ceiling%2A>|Returns the smallest integral value that's greater than or equal to the specified `Decimal` or `Double`.|
28
+
|<xref:System.Math.Cos%2A>|Returns the cosine of the specified angle.|
29
+
|<xref:System.Math.Cosh%2A>|Returns the hyperbolic cosine of the specified angle.|
30
+
|<xref:System.Math.DivRem%2A>|Returns the quotient of two 32-bit or 64-bit signed integers, and also returns the remainder in an output parameter.|
31
+
|<xref:System.Math.Exp%2A>|Returns e (the base of natural logarithms) raised to the specified power.|
32
+
|<xref:System.Math.Floor%2A>|Returns the largest integer that's less than or equal to the specified `Decimal` or `Double` number.|
33
+
|<xref:System.Math.IEEERemainder%2A>|Returns the remainder that results from the division of a specified number by another specified number.|
34
+
|<xref:System.Math.Log%2A>|Returns the natural (base e) logarithm of a specified number or the logarithm of a specified number in a specified base.|
35
+
|<xref:System.Math.Log10%2A>|Returns the base 10 logarithm of a specified number.|
36
+
|<xref:System.Math.Max%2A>|Returns the larger of two numbers.|
37
+
|<xref:System.Math.Min%2A>|Returns the smaller of two numbers.|
38
+
|<xref:System.Math.Pow%2A>|Returns a specified number raised to the specified power.|
39
+
|<xref:System.Math.Round%2A>|Returns a `Decimal` or `Double` value rounded to the nearest integral value or to a specified number of fractional digits.|
40
+
|<xref:System.Math.Sign%2A>|Returns an `Integer` value indicating the sign of a number.|
41
+
|<xref:System.Math.Sin%2A>|Returns the sine of the specified angle.|
42
+
|<xref:System.Math.Sinh%2A>|Returns the hyperbolic sine of the specified angle.|
43
+
|<xref:System.Math.Sqrt%2A>|Returns the square root of a specified number.|
44
+
|<xref:System.Math.Tan%2A>|Returns the tangent of the specified angle.|
45
+
|<xref:System.Math.Tanh%2A>|Returns the hyperbolic tangent of the specified angle.|
46
+
|<xref:System.Math.Truncate%2A>|Calculates the integral part of a specified `Decimal` or `Double` number.|
47
+
48
+
The following table lists methods of the <xref:System.Math?displayProperty=nameWithType> class that don't exist in .NET Framework but are added in .NET Standard or .NET Core:
|<xref:System.Math.Acosh%2A>|Returns the angle whose hyperbolic cosine is the specified number.|Starting with .NET Core 2.1 and .NET Standard 2.1|
53
+
|<xref:System.Math.Asinh%2A>|Returns the angle whose hyperbolic sine is the specified number.|Starting with .NET Core 2.1 and .NET Standard 2.1|
54
+
|<xref:System.Math.Atanh%2A>|Returns the angle whose hyperbolic tangent is the specified number.|Starting with .NET Core 2.1 and .NET Standard 2.1|
55
+
|<xref:System.Math.BitDecrement%2A>|Returns the next smallest value that compares less than `x`.|Starting with .NET Core 3.0|
56
+
|<xref:System.Math.BitIncrement%2A>|Returns the next largest value that compares greater than `x`.|Starting with .NET Core 3.0|
57
+
|<xref:System.Math.Cbrt%2A>|Returns the cube root of a specified number.|Starting with .NET Core 2.1 and .NET Standard 2.1|
58
+
|<xref:System.Math.Clamp%2A>|Returns `value` clamped to the inclusive range of `min` and `max`.|Starting with .NET Core 2.0 and .NET Standard 2.1|
59
+
|<xref:System.Math.CopySign%2A>|Returns a value with the magnitude of `x` and the sign of `y`.|Starting with .NET Core 3.0|
60
+
|<xref:System.Math.FusedMultiplyAdd%2A>|Returns (x \* y) + z, rounded as one ternary operation.|Starting with .NET Core 3.0|
61
+
|<xref:System.Math.ILogB%2A>|Returns the base 2 integer logarithm of a specified number.|Starting with .NET Core 3.0|
62
+
|<xref:System.Math.Log2%2A>|Returns the base 2 logarithm of a specified number.|Starting with .NET Core 3.0|
63
+
|<xref:System.Math.MaxMagnitude%2A>|Returns the larger magnitude of two double-precision floating-point numbers.|Starting with .NET Core 3.0|
64
+
|<xref:System.Math.MinMagnitude%2A>|Returns the smaller magnitude of two double-precision floating-point numbers.|Starting with .NET Core 3.0|
65
+
|<xref:System.Math.ScaleB%2A>|Returns x \* 2^n computed efficiently.|Starting with .NET Core 3.0|
66
+
67
+
To use these functions without qualification, import the <xref:System.Math?displayProperty=nameWithType> namespace into your project by adding the following code to the top of your source file:
68
+
48
69
```vb
49
-
ImportsSystem.Math
50
-
```
51
-
52
-
## Example
53
-
This example uses the <xref:System.Math.Abs%2A> method of the <xref:System.Math> class to compute the absolute value of a number.
54
-
70
+
ImportsSystem.Math
71
+
```
72
+
73
+
## Example - Abs
74
+
75
+
This example uses the <xref:System.Math.Abs%2A> method of the <xref:System.Math> class to compute the absolute value of a number.
76
+
55
77
```vb
56
-
' Returns 50.3.
57
-
DimMyNumber1AsDouble=Math.Abs(50.3)
58
-
' Returns 50.3.
59
-
DimMyNumber2AsDouble=Math.Abs(-50.3)
78
+
DimxAsDouble=Math.Abs(50.3)
79
+
DimyAsDouble=Math.Abs(-50.3)
80
+
Console.WriteLine(x)
81
+
Console.WriteLine(y)
82
+
' This example produces the following output:
83
+
' 50.3
84
+
' 50.3
60
85
```
61
-
62
-
## Example
63
-
This example uses the <xref:System.Math.Atan%2A> method of the <xref:System.Math> class to calculate the value of pi.
64
-
86
+
87
+
## Example - Atan
88
+
89
+
This example uses the <xref:System.Math.Atan%2A> method of the <xref:System.Math> class to calculate the value of pi.
90
+
65
91
```vb
66
-
PublicFunctionGetPi()AsDouble
67
-
' Calculate the value of pi.
68
-
Return4.0*Math.Atan(1.0)
69
-
EndFunction
70
-
```
71
-
72
-
## Example
73
-
This example uses the <xref:System.Math.Cos%2A> method of the <xref:System.Math> class to return the cosine of an angle.
74
-
92
+
PublicFunctionGetPi()AsDouble
93
+
' Calculate the value of pi.
94
+
Return4.0*Math.Atan(1.0)
95
+
EndFunction
96
+
```
97
+
98
+
> [!NOTE]
99
+
> The <xref:System.Math?displayProperty=nameWithType> class contains <xref:System.Math.PI?displayProperty=nameWithType> constant field. You can use it rather than calculating it.
100
+
101
+
## Example - Cos
102
+
103
+
This example uses the <xref:System.Math.Cos%2A> method of the <xref:System.Math> class to return the cosine of an angle.
104
+
75
105
```vb
76
-
PublicFunctionSec(ByValangleAsDouble)AsDouble
77
-
' Calculate the secant of angle, in radians.
78
-
Return1.0/Math.Cos(angle)
79
-
EndFunction
80
-
```
81
-
82
-
## Example
83
-
This example uses the <xref:System.Math.Exp%2A> method of the <xref:System.Math> class to return e raised to a power.
84
-
106
+
PublicFunctionSec(angleAsDouble)AsDouble
107
+
' Calculate the secant of angle, in radians.
108
+
Return1.0/Math.Cos(angle)
109
+
EndFunction
110
+
```
111
+
112
+
## Example - Exp
113
+
114
+
This example uses the <xref:System.Math.Exp%2A> method of the <xref:System.Math> class to return e raised to a power.
115
+
85
116
```vb
86
-
PublicFunctionSinh(ByValangleAsDouble)AsDouble
87
-
' Calculate hyperbolic sine of an angle, in radians.
88
-
Return(Math.Exp(angle)-Math.Exp(-angle))/2.0
89
-
EndFunction
90
-
```
91
-
92
-
## Example
93
-
This example uses the <xref:System.Math.Log%2A> method of the <xref:System.Math> class to return the natural logarithm of a number.
94
-
117
+
PublicFunctionSinh(angleAsDouble)AsDouble
118
+
' Calculate hyperbolic sine of an angle, in radians.
119
+
Return(Math.Exp(angle)-Math.Exp(-angle))/2.0
120
+
EndFunction
121
+
```
122
+
123
+
## Example - Log
124
+
125
+
This example uses the <xref:System.Math.Log%2A> method of the <xref:System.Math> class to return the natural logarithm of a number.
126
+
95
127
```vb
96
-
PublicFunctionAsinh(ByValvalueAsDouble)AsDouble
97
-
' Calculate inverse hyperbolic sine, in radians.
98
-
ReturnMath.Log(value+Math.Sqrt(value*value+1.0))
99
-
EndFunction
100
-
```
101
-
102
-
## Example
103
-
This example uses the <xref:System.Math.Round%2A> method of the <xref:System.Math> class to round a number to the nearest integer.
104
-
128
+
PublicFunctionAsinh(valueAsDouble)AsDouble
129
+
' Calculate inverse hyperbolic sine, in radians.
130
+
ReturnMath.Log(value+Math.Sqrt(value*value+1.0))
131
+
EndFunction
132
+
```
133
+
134
+
## Example - Round
135
+
136
+
This example uses the <xref:System.Math.Round%2A> method of the <xref:System.Math> class to round a number to the nearest integer.
137
+
105
138
```vb
106
-
' Returns 3.
107
-
DimMyVar2AsDouble=Math.Round(2.8)
108
-
```
109
-
110
-
## Example
111
-
This example uses the <xref:System.Math.Sign%2A> method of the <xref:System.Math> class to determine the sign of a number.
112
-
139
+
DimmyVar2AsDouble=Math.Round(2.8)
140
+
Console.WriteLine(myVar2)
141
+
' The code produces the following output:
142
+
' 3
143
+
```
144
+
145
+
## Example - Sign
146
+
147
+
This example uses the <xref:System.Math.Sign%2A> method of the <xref:System.Math> class to determine the sign of a number.
148
+
113
149
```vb
114
-
' Returns 1.
115
-
DimMySign1AsInteger=Math.Sign(12)
116
-
' Returns -1.
117
-
DimMySign2AsInteger=Math.Sign(-2.4)
118
-
' Returns 0.
119
-
DimMySign3AsInteger=Math.Sign(0)
120
-
```
121
-
122
-
## Example
123
-
This example uses the <xref:System.Math.Sin%2A> method of the <xref:System.Math> class to return the sine of an angle.
124
-
150
+
DimmySign1AsInteger=Math.Sign(12)
151
+
DimmySign2AsInteger=Math.Sign(-2.4)
152
+
DimmySign3AsInteger=Math.Sign(0)
153
+
Console.WriteLine(mySign1)
154
+
Console.WriteLine(mySign2)
155
+
Console.WriteLine(mySign3)
156
+
' The code produces the following output:
157
+
' 1
158
+
' -1
159
+
' 0
160
+
```
161
+
162
+
## Example - Sin
163
+
164
+
This example uses the <xref:System.Math.Sin%2A> method of the <xref:System.Math> class to return the sine of an angle.
165
+
125
166
```vb
126
-
PublicFunctionCsc(ByValangleAsDouble)AsDouble
127
-
' Calculate cosecant of an angle, in radians.
128
-
Return1.0/Math.Sin(angle)
129
-
EndFunction
130
-
```
131
-
132
-
## Example
133
-
This example uses the <xref:System.Math.Sqrt%2A> method of the <xref:System.Math> class to calculate the square root of a number.
134
-
167
+
PublicFunctionCsc(angleAsDouble)AsDouble
168
+
' Calculate cosecant of an angle, in radians.
169
+
Return1.0/Math.Sin(angle)
170
+
EndFunction
171
+
```
172
+
173
+
## Example - Sqrt
174
+
175
+
This example uses the <xref:System.Math.Sqrt%2A> method of the <xref:System.Math> class to calculate the square root of a number.
176
+
135
177
```vb
136
-
' Returns 2.
137
-
DimMySqr1AsDouble=Math.Sqrt(4)
138
-
' Returns 4.79583152331272.
139
-
DimMySqr2AsDouble=Math.Sqrt(23)
140
-
' Returns 0.
141
-
DimMySqr3AsDouble=Math.Sqrt(0)
142
-
' Returns NaN (not a number).
143
-
DimMySqr4AsDouble=Math.Sqrt(-4)
144
-
```
145
-
146
-
## Example
147
-
This example uses the <xref:System.Math.Tan%2A> method of the <xref:System.Math> class to return the tangent of an angle.
148
-
178
+
DimmySqrt1AsDouble=Math.Sqrt(4)
179
+
DimmySqrt2AsDouble=Math.Sqrt(23)
180
+
DimmySqrt3AsDouble=Math.Sqrt(0)
181
+
DimmySqrt4AsDouble=Math.Sqrt(-4)
182
+
Console.WriteLine(mySqrt1)
183
+
Console.WriteLine(mySqrt2)
184
+
Console.WriteLine(mySqrt3)
185
+
Console.WriteLine(mySqrt4)
186
+
' The code produces the following output:
187
+
' 2
188
+
' 4.79583152331272
189
+
' 0
190
+
' NaN
191
+
```
192
+
193
+
## Example - Tan
194
+
195
+
This example uses the <xref:System.Math.Tan%2A> method of the <xref:System.Math> class to return the tangent of an angle.
196
+
149
197
```vb
150
-
PublicFunctionCtan(ByValangleAsDouble)AsDouble
151
-
' Calculate cotangent of an angle, in radians.
152
-
Return1.0/Math.Tan(angle)
153
-
EndFunction
154
-
```
155
-
156
-
## Requirements
157
-
**Class:**<xref:System.Math>
158
-
159
-
**Namespace:**<xref:System>
160
-
161
-
**Assembly:** mscorlib (in mscorlib.dll)
162
-
198
+
PublicFunctionCtan(angleAsDouble)AsDouble
199
+
' Calculate cotangent of an angle, in radians.
200
+
Return1.0/Math.Tan(angle)
201
+
EndFunction
202
+
```
203
+
163
204
## See also
164
205
165
206
-<xref:Microsoft.VisualBasic.VBMath.Rnd%2A>
166
207
-<xref:Microsoft.VisualBasic.VBMath.Randomize%2A>
167
208
-<xref:System.Double.NaN>
168
-
-[Derived Math Functions](../../../visual-basic/language-reference/keywords/derived-math-functions.md)
0 commit comments