in reply to Re: Unpacking extended-double precision floats
in thread Unpacking extended-double precision floats

Howdy!

I'm reading a binary file. Part of the file consists of 10-byte sequences that are clearly floats, probably IEEE extended-double-precision floats. I'm looking to be able to convert to unpack that to a numeric value and pack it to a 10-byte sequence.

That is, unpack 0x4001c888888888888888 to 12.5 (if I'm remembering actual data correctly), and pack 12.5 back to 0x4001c888888888888888.

I may just resort to picking the bits apart and converting it myself. I'm not sure if my C compiler (gcc on Mac) does that particular datatype. I can afford to simply do the bit-slinging myself, if it comes to that. I was just hoping to find that someone else has already solved the problem. So far, no joy.

update: added more words to clarify

yours,
Michael
  • Comment on Re^2: Unpacking extended-double precision floats

Replies are listed 'Best First'.
Re^3: Unpacking extended-double precision floats
by ikegami (Patriarch) on Nov 29, 2006 at 18:43 UTC

    My question was about 12.5's format. You implied (in a private message) that the lost of precision is of no concern, so I'm deducing that you want an NV (double).

    Have you tried unpack 'D' yet?

      If loss of precision is of no concern, and the number of bits of exponent and sign is the same between d and D formats, you may be able to use unpack d plus two skip bytes, and pack it as a double d followed by two appropriate fill bytes (00 or 88 ?). Bill N1VUX
        Howdy!

        If I recall correctly (and I'll be checking the references before I do anything), "double precision" and "extended double precision" have different numbers of bits in the exponent. It's not quite that simple to smush the precision down. I think I go from 64 bits of mantissa to 53 bits of mantissa (but don't hold me to precise numbers here).

        In the end, I should be able to pick the three components apart and Just Do The Math.

        yours,
        Michael
      Howdy!

      Yep. I tried that. The Perl on my mac (where I'm actually doing this) told me to pound sand. I'll try Convert::Binary::C when I get home.

      ...so, yes, I want an NV on the Perl side of things.

      yours,
      Michael