View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.misc
joeu2004 joeu2004 is offline
external usenet poster
 
Posts: 2,059
Default Precision As Displayed Has Failed Me--Help

Sorry, I omitted the user-defined type definitions, namely:

Type Tdouble
val As Double
End Type

Type Tlong2
val(1) As Long
End Type

Also, I should note that the implementation presumes a little-endian
architecture. This is true for Intel (and similar) PCs. I don't know
about Macs.

Last, I wrote:
' With OnError, "dbl.val=arg" converts (&h7ffxNNNN,z)
' to (&h7ffyNNNN,z), where x=0-7, y=8-f and z0 if x=0,
' otherwise z=0


I should have written y=x+8. It's a nitpick anyway. The situation
should never arise when the function is called from an Excel formula.
The issue is more relevant to a companion function, makedbl, which
constructs a double floating-point value from two hex strings
representing the upper and lower 32 bits.


----- original posting -----

On Jul 16, 6:40*am, joeu2004 wrote:
On Jul 11, 10:02*am, "Niek Otten" wrote:

Just (very) curious:
How do you examine the internal binary representations
of Excel's data?


In its simplest form, I use the following function, dbl2bin(). *The
actual implementation has some bells and whistles that complicate
things.

Function dbl2bin(arg) As String
Dim lng As Tlong2
Dim dbl As Tdouble
Dim lng1 As String, lng0 As String
Dim out1 As String, out0 As String

' LSet requires user-defined types
'
' With OnError, "dbl.val=arg" converts (&h7ffxNNNN,z)
' to (&h7ffyNNNN,z), where x=0-7, y=8-f and z0 if x=0,
' otherwise z=0; that is, everything except INF, which
' is (&h7ff00000,0). *Without OnError, assignment causes
' error. *CopyMemory avoids error on assignment; and it
' should avoid conversion. *but CopyMemory might not be
' portable; and it might not be worth the trouble since
' we cannot find a way for "arg" to be any of the values
' (&h7ffxNNNN,z) as described above.

On Error Resume Next
dbl.val = arg
LSet lng = dbl

lng1 = Hex(lng.val(1)): len1 = Len(lng1)
out1 = "&h00000000": Mid(out1, 11 - len1, len1) = lng1

lng0 = Hex(lng.val(0)): len0 = Len(lng0)
out0 = "00000000": Mid(out0, 9 - len0, len0) = lng0

dbl2bin = out1 & "," & out0
End Function