[Haskell-cafe] Re: ANNOUNCE: protocol-buffers-0.2.9 for Haskell
gale at sefer.org
Mon Sep 22 07:12:57 EDT 2008
Chris Kuklewicz wrote:
> Who can suggest a way to cast from Float to Word32 and Double to Word64
> using ghc? The actual task is that I need to write out the Float as a
> little endian sequence of four bytes and also be able to read it back in.
> The writing and reading are done in Put and Get monads to ByteString (from
> the "binary" package).
I think alloca-like hacks is really the wrong direction and asking
You are trying to translate between platform-dependent native floats,
and IEEE floats in a specified platform-independent binary format
for Google. So use encodeFloat/decodeFloat - fast primitives in
GHC - on the native side, and a hand-written Binary instance for
the exact format you need on the Google side.
My opinion, YMMV.
More information about the Haskell-Cafe