From: Stefan Arentz
Subject: Parsing binary Java doubles
Date: 
Message-ID: <87642wot4m.fsf@kip.sateh.com>
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.

 S.

From: David Lichteblau
Subject: Re: Parsing binary Java doubles
Date: 
Message-ID: <slrnfdg4l4.t2k.usenet-2006@radon.home.lichteblau.com>
On 2007-08-31, Stefan Arentz <·············@gmail.com> 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.
From: Stefan Arentz
Subject: Re: Parsing binary Java doubles
Date: 
Message-ID: <871wdjq24p.fsf@kip.sateh.com>
David Lichteblau <···········@lichteblau.com> writes:

> On 2007-08-31, Stefan Arentz <·············@gmail.com> 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.
From: ···············@gmail.com
Subject: Re: Parsing binary Java doubles
Date: 
Message-ID: <1188576257.195143.125000@m37g2000prh.googlegroups.com>
On Aug 31, 9:12 am, Stefan Arentz <·············@gmail.com> wrote:
> David Lichteblau <···········@lichteblau.com> writes:
> > On 2007-08-31, Stefan Arentz <·············@gmail.com> 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.
From: David Lichteblau
Subject: Re: Parsing binary Java doubles
Date: 
Message-ID: <slrnfdgev8.t57.usenet-2006@radon.home.lichteblau.com>
On 2007-08-31, Stefan Arentz <·············@gmail.com> wrote:
>> sb-kernel:make-double-float.
> Ah I think that was the final piece of the puzzle :-) Thanks!

You could also implement it portably and use SCALE-FLOAT like
ieee-floats does it (see http://www.cliki.net/ieee-floats). 

However, for full compatibility with Java you have to handle NaN and
infinity, which Common Lisp does not support portably.  Hence
sb-kernel:make-double-float for a full solution.
From: John Thingstad
Subject: Re: Parsing binary Java doubles
Date: 
Message-ID: <op.txw99tclpqzri1@pandora.upc.no>
P� Fri, 31 Aug 2007 13:12:09 +0200, skrev Stefan Arentz  
<·············@gmail.com>:

>
> 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.
>
>  S.
>

Have a look at  
http://www.gigamonkeys.com/book/practical-parsing-binary-files.html