in reply to 52-bit numbers as floating point

The author of the Spreadsheet::WriteExcel module appears to have had a similar problem.

Spreadsheet::WriteExcel will work on the majority of Windows, UNIX and Macintosh platforms. Specifically, the module will work on any system where perl packs floats in the 64 bit IEEE format. The float must also be in little-endian format but it will be reversed if necessary. Thus:

 
print join(" ", map { sprintf "%#02x", $_ } 
      unpack("C*", pack "d", 1.2345)), "\n";

should give (or in reverse order): 

    0x8d 0x97 0x6e 0x12 0x83 0xc0 0xf3 0x3f
So, as I read it, if you aren't concerned about portability, the following should work:
my $dfloat=unpack("d",reverse($yourbigendian));
(remove the reverse bit if your box is big-endian. I'm assuming it's not, since you mentioned ActiveState..)

Update: Seems I was a bit confused about what format he did have the numbers in. ( In my defense, I'm still not clear :) Perhaps a pointer to the IEEE double format would make this node somewhat useful ? See This page from Sun

Replies are listed 'Best First'.
Re: Re: 52-bit numbers as floating point
by John M. Dlugosz (Monsignor) on Aug 08, 2002 at 14:38 UTC
    The code you posted originally is still a good idea, so that the script can validate its assumptions that a "d" value is indeed stored this way.

    Thanks for the link! That's exactly what I was looking for.

Re: Re: 52-bit numbers as floating point
by John M. Dlugosz (Monsignor) on Aug 08, 2002 at 03:52 UTC
    I think that code you quoted validates his assumptions about how "d" values are stored on the implementation. But it doesn't say anything about why he needs that or what the format is. Presumably, he's also manipulating bits directly.

    The line you suggest will unpack a float, but doesn't tell me how I arrage the bits to make a float in the first place!