Re: Parsing binary Java doubles



On Aug 31, 9:12 am, Stefan Arentz <stefan.are...@xxxxxxxxx> wrote:
David Lichteblau <usenet-2...@xxxxxxxxxxxxxx> writes:
On 2007-08-31, Stefan Arentz <stefan.are...@xxxxxxxxx> wrote:
I have a blob of data that contains Java double values written to
it. How would I parse those back into something Lisp understands? I'm
using SBCL 1.0.9.

Read its 32-bit halves as integers, then use
sb-kernel:make-double-float.

Ah I think that was the final piece of the puzzle :-) Thanks!

S.

A more portable solution involves parsing out the various components
of the underlying representation into sign, exponent, and mantissa,
and use SCALE-FLOAT.

http://www.lisp.org/HyperSpec/Body/fun_decode-fl_decode-float.html#scale-float

This is straightforward if your representation's FLOAT-RADIX for the
floating-point type you are construction matches Java's choice (of
radix 2?). That's a pretty safe bet in these days of IEEE-compliant
floating point. Otherwise, you would have to convert the exponent, and
correct the mantissa for the "remainder", if any, of the exponent that
could not be converted.

.



Relevant Pages

  • Re: BigNum -- Floating Point
    ... > mantissa and exponent. ... In that the current implementation already uses 32-bit "digits", ... (in one design I'm considering) ...
    (comp.programming)
  • Re: Fixed-point Math help
    ... > suggestion of using google is probably a good one. ... > can be packed in any format you like or is convenient to you. ... but it is usually assumed for the mantissa at any convenient ... > values of the exponent. ...
    (comp.arch.embedded)
  • A Collating Representation for Extremely Gradual Overflow
    ... the binary point does not move as the exponent changes from 000...001 to ... the first part of the mantissa, whether it is 1, 01, or 001, before the ... After I thought of a further improvement, letting the exponent field ... This extremely gradual underflow representation does more than regular ...
    (comp.arch.arithmetic)
  • Re: floating point mantissa?
    ... optimized normalization, denormalization methods. ... > IMHO 146 cycles just for a normalization of a single floating point number ... shift the mantissa left a bit (and decrement the exponent) ...
    (microsoft.public.vc.language)
  • Re: QI and MQ Coder: First real-life experiences
    ... > is used to align the mantissa? ... If you look at SWI as a floating point number, ... So for that concept of "precision", ... The SW exponent, of course, as shown e.g. in EncDec.c, function ...
    (comp.compression)