[Haskell-cafe] Binary IEEE floating point format for AMQP

Stefan O'Rear stefanor at cox.net
Sun Feb 24 10:16:10 EST 2008

On Sun, Feb 24, 2008 at 12:21:00PM +0000, Paul Johnson wrote:
> I'm working on an implementation of the framing layer for AMQP 
> (www.amqp.org).  I almost had 0.9 finished when I found they had released 
> the spec for 0.10, so I have to redo quite a lot of work.
> Amongst the new features of 0.10 are wire formats for floating point.  
> These are the 4 and 8 byte IEEE formats.
> * Is there a principled way of converting a Haskell Float or Double (or 
> Rational, for that matter) to and from IEEE format?
> * Since many computers use IEEE format natively, is there a quicker way of 
> doing this on those architectures?

{-# LANGUAGE MagicHash #-}
import Data.Int
import GHC.Exts

foo :: Double -> Int64 --ghc only
foo (D# x) = I64# (unsafeCoerce# x)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080224/c344cefa/attachment.bin

More information about the Haskell-Cafe mailing list