Some Math Methods
Name |
Description |
Returns the absolute value of a specified number. |
|
Returns the cosine of the specified angle. Angle must be in radians |
|
Returns the larger of two specified numbers. |
|
Returns the smaller of two numbers. |
|
Rounds a value to the nearest integer. |
|
Returns the sine of the specified angle. Angle must be in radians |
|
Returns the square root of a specified number. |
|
Returns the tangent of the specified angle. Angle must be in radians |
|
Calculates the integral part of a number. |
Imports System.Windows.Forms
Module Module1
Sub Main()
Dim root As Double = Math.Sqrt(2) '
calculate the square root of 2
' display the results in a message
dialog
MessageBox.Show("The square root of 2
is " & root, "The Square Root of 2")
End Sub
End Module
Imports System.Windows.Forms
Module Module1
Sub Main()
Dim number1 As Integer = 37
Dim number2 As Integer = 45
Dim largest As Integer
largest = Math.Max(number1, number2)
MessageBox.Show("The largest of " &
num1 & " and " & unm22 & " is " & largest, "Math.max")
End Sub
End Module
Imports System.Windows.Forms
Module Module1
Sub Main()
Dim num1 As Integer = 37
Dim num2 As Integer = 45
Dim smallest As Integer
smallest = Math.Min(num1, num2)
MessageBox.Show("The smallest of " & num1 & " and
" & num2 & " is " & smallest, "Math.min")
End Sub
End Module
Imports System.Windows.Forms
Module Module1
Sub Main()
Dim num1 As Double = 45.6789
Dim Rnd As Integer = Math.Round(num1)
MessageBox.Show("The effect of using Math.Round
on 45.6789 is: " & Rnd, "Math.Round")
End Sub
End Module
Imports System.Windows.Forms
Module Module1
Sub Main()
Dim num1 As Double = 45.6789
Dim A As Integer = Math.Truncate(num1)
MessageBox.Show("The effect of using
Math.Truncate on 45.6789 is: " & A, "Math.Truncate")
End Sub
End Module
Imports System.Windows.Forms
Module Module1
Sub Main()
Dim num1 As Double = -45.6789
Dim A As Double = Math.Abs(num1)
MessageBox.Show("The effect of using
Math.Abs on -45.6789 is: " & A, "Math.Abs")
End Sub
End Module
Imports System.Windows.Forms
Module Module1
Sub Main()
Dim x As Double = 3.1416 / 4
Dim y As Double = Math.Sin(x)
MessageBox.Show("The Sin of pi/4 is :
" & y, "Math.Sin")
End Sub
End Module
Imports System.Windows.Forms
Module Module1
Sub Main()
Dim x As Double = 3.1416 / 4
Dim y As Double = Math.Cos(x)
MessageBox.Show("The Cos of pi/4 is :
" & y, "Math.Cos")
End Sub
End Module
Imports System.Windows.Forms
Module Module1
Sub Main()
Dim x As Double = 3.1416 / 4
Dim y As Double = Math.Tan(x)
MessageBox.Show("The Tan of pi/4 is :
" & y, "Math.Tan")
End Sub
End Module
Note: The Tan should be 1 - the rest
result from inaccuracies in numerical calculations - discuss in detail in my
numerical methods course second semester