本文整理汇总了VB.NET中System.Single.Epsilon字段的典型用法代码示例。如果您正苦于以下问题:VB.NET Single.Epsilon字段的具体用法?VB.NET Single.Epsilon怎么用?VB.NET Single.Epsilon使用的例子?那么恭喜您, 这里精选的字段代码示例或许可以为您提供帮助。您也可以进一步了解该字段所在类System.Single
的用法示例。
在下文中一共展示了Single.Epsilon字段的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
Module Example
Public Sub Main()
Dim values() As Single = { 0, Single.Epsilon, Single.Epsilon * .5 }
For ctr As Integer = 0 To values.Length - 2
For ctr2 As Integer = ctr + 1 To values.Length - 1
Console.WriteLine("{0:r} = {1:r}: {2}", _
values(ctr), values(ctr2), _
values(ctr).Equals(values(ctr2)))
Next
Console.WriteLine()
Next
End Sub
End Module
输出:
0 = 1.401298E-45: False 0 = 0: True 1.401298E-45 = 0: False
示例2: Example
Module Example
Public Sub Main()
Dim values() As Single = { 0.0, Single.Epsilon }
For Each value In values
Console.WriteLine(GetComponentParts(value))
Console.WriteLine()
Next
End Sub
Private Function GetComponentParts(value As Single) As String
Dim result As String = String.Format("{0:R}: ", value)
Dim indent As Integer = result.Length
' Convert the single to an 8-byte array.
Dim bytes() As Byte = BitConverter.GetBytes(value)
Dim formattedSingle As Integer = BitConverter.ToInt32(bytes, 0)
' Get the sign bit (byte 3, bit 7).
result += String.Format("Sign: {0}{1}",
If(formattedSingle >> 31 <> 0, "1 (-)", "0 (+)"),
vbCrLf)
' Get the exponent (byte 2 bit 7 to byte 3, bits 6)
Dim exponent As Integer = (formattedSingle >> 23) And &h000000FF
Dim adjustment As Integer = If(exponent <> 0, 127, 126)
result += String.Format("{0}Exponent: 0x{1:X4} ({1}){2}",
New String(" "c, indent), exponent - adjustment,
vbCrLf)
' Get the significand (bits 0-22)
Dim significand As Long = If(exponent <> 0,
(formattedSingle And &h007FFFFF) Or &h800000,
formattedSingle And &h007FFFFF)
result += String.Format("{0}Mantissa: 0x{1:X13}{2}",
New String(" "c, indent), significand, vbCrLf)
Return result
End Function
End Module
输出:
0: Sign: 0 (+) Exponent: 0xFFFFFF82 (-126) Mantissa: 0x0000000000000 1.401298E-45: Sign: 0 (+) Exponent: 0xFFFFFF82 (-126) Mantissa: 0x0000000000001