【问题标题】:vb.net mantissa and exponent calculation from doublevb.net尾数和指数计算双精度
【发布时间】:2010-10-18 08:59:39
【问题描述】:

任何人都可以就如何从 VB.net 中的双精度数中获取尾数和指数提供任何建议吗?我知道我可以进行字符串解析和一些到整数的转换,但我想知道是否有人有一个数学等效公式可以让我这样做?

非常感谢

【问题讨论】:

    标签: vb.net math exponent mantissa


    【解决方案1】:

    您想获得 IEEE-754 值内的“本机”尾数和指数吗?这实际上相当简单:使用BitConverter.DoubleToInt64Bits 将值作为整数获取(更容易对其执行位操作),然后查看我的article on .NET binary floating point types 的位在哪里。

    我有一些 C# code 提取各个部分以便将其转换为精确的十进制表示 - 您可以相当容易地将其相关位转换为 VB。

    【讨论】:

    • 我只想将指数和 manitssa 作为两个单独的整数值。
    • user479122:但是采用什么格式?你的意思是十进制指数和尾数吗?还是原生 base-2 指数和尾数?
    【解决方案2】:

    你应该试试这个:

    Public Function DeclString(ByVal dDegrees As Double) As String
       Dim Flag As String
       Dim ddecimal As Double
       Dim iDegrees As Integer
       If dDegrees < 0 Then Flag = "S" Else Flag = "N"
       iDegrees = Int(Abs(dDegrees))
       ddecimal = (Abs(dDegrees) - iDegrees) * 60 ' + 0.5
       If ddecimal > 59.5 Then iDegrees = iDegrees + 1: ddecimal = 0
       DeclString = Format$(iDegrees, "00") + Flag + Format$(ddecimal, "00")
    End Function
    

    【讨论】:

      猜你喜欢
      • 2017-03-08
      • 2012-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多