' Visual Basic 2008 9.0 .NET Examples - Datatypes - Introduction to Visual Basic : Module Example8 Sub Main() Dim singleOperands As Single() = {Single.PositiveInfinity, _ Single.NegativeInfinity, _ 123.0F, -123.0F, 0.0F, -0.0F} Dim operatorSymbols As String() = {"*", "/", "+", "-"} ' For Each operatorSymbol As String In operatorSymbols Console.WriteLine("OPERATOR " & operatorSymbol.ToString()) Console.WriteLine() For Each singleOperand1 As Single In singleOperands For Each singleOperand2 As Single In singleOperands PrintCalculation(singleOperand1, operatorSymbol, _ singleOperand2) Next Console.WriteLine() Next Console.WriteLine() Next ' Console.ReadLine() End Sub Sub PrintCalculation(ByVal operand1 As Single, _ ByVal operatorSymbol As String, _ ByVal operand2 As Single) Console.Write(GetString(operand1) & " " & operatorSymbol & " " & _ GetString(operand2) & " = ") Select Case operatorSymbol Case "*" Console.WriteLine(GetString(operand1 * operand2)) Case "/" Console.WriteLine(GetString(operand1 / operand2)) Case "+" Console.WriteLine(GetString(operand1 + operand2)) Case "-" Console.WriteLine(GetString(operand1 - operand2)) End Select End Sub Function GetString(ByVal value As Single) As String If IsPositiveZero(value) Then GetString = "+0" ElseIf IsNegativeZero(value) Then GetString = "-0" ElseIf Single.IsNegativeInfinity(value) Then GetString = "-Infinity" ElseIf Single.IsPositiveInfinity(value) Then GetString = "+Infinity" ElseIf Single.IsNaN(value) Then GetString = "NaN" Else GetString = value.ToString() End If End Function Public Function IsPositiveZero(ByVal value As Single) As Boolean If BitConverter.GetBytes(value)(0) = 0 AndAlso _ BitConverter.GetBytes(value)(1) = 0 AndAlso _ BitConverter.GetBytes(value)(2) = 0 AndAlso _ BitConverter.GetBytes(value)(3) = 0 Then _ IsPositiveZero = True End Function Public Function IsNegativeZero(ByVal value As Single) As Boolean If BitConverter.GetBytes(value)(0) = 0 AndAlso _ BitConverter.GetBytes(value)(1) = 0 AndAlso _ BitConverter.GetBytes(value)(2) = 0 AndAlso _ BitConverter.GetBytes(value)(3) = 128 Then _ IsNegativeZero = True End Function End Module ' Visit www.studyvb.com for more examples. Copyright 2003-2008 De Wolf.