vb System.Single.Epsilon类(方法)实例源码

下面列出了vb System.Single.Epsilon 类(方法)源码代码实例,从而了解它的用法。

作者:VB.NET开发    项目:Syste   
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

作者:VB.NET开发    项目:Syste   
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


问题


面经


文章

微信
公众号

扫码关注公众号