Re: Parsing binary Java doubles
- From: "josephoswald+gg@xxxxxxxxx" <josephoswald@xxxxxxxxx>
- Date: Fri, 31 Aug 2007 09:04:17 -0700
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.
.
- References:
- Parsing binary Java doubles
- From: Stefan Arentz
- Re: Parsing binary Java doubles
- From: David Lichteblau
- Re: Parsing binary Java doubles
- From: Stefan Arentz
- Parsing binary Java doubles
- Prev by Date: Re: Parsing binary Java doubles
- Next by Date: Re: How to use Lisp in C/C++
- Previous by thread: Re: Parsing binary Java doubles
- Next by thread: [OT] Software
- Index(es):
Relevant Pages
|