开发者

vb.net mantissa and exponent calculation from double

开发者 https://www.devze.com 2023-01-20 18:28 出处:网络
Can anyone offer any advice on how to get开发者_运维技巧 the mantissa and exponent from a double in VB.net? I know I can do a string parse and some conversion to ints but I wondered if anyone had a ma

Can anyone offer any advice on how to get开发者_运维技巧 the mantissa and exponent from a double in VB.net? I know I can do a string parse and some conversion to ints but I wondered if anyone had a mathematical equivalent formula that would allow me to do this?

Many thanks


Do you want to get the "native" mantissa and exponent within the IEEE-754 value? That's actually fairly easy: use BitConverter.DoubleToInt64Bits to get the value as an integer (which is easier to perform bit operations on) and then see my article on .NET binary floating point types for which bits are where.

I have some C# code which extracts the various parts in order to convert it to a precise decimal representation - you could convert the relevant bits of that into VB reasonably easily.


You should try this:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消