[Haskell-cafe] Coercion from a Word32/64 to a Float/Double

2009-09-14 Thread minh thu
Hi, I'd like to know if this should work: -- GHC coercion getFloat :: BHeader -> Get Float getFloat h = case endianness h of LittleEndian -> fmap (coerce . fromIntegral) getWord32le BigEndian -> fmap (coerce . fromIntegral) getWord32be where coerce (I32# x) = F# (unsafeCoerce# x) --

Re: [Haskell-cafe] Coercion from a Word32/64 to a Float/Double

2009-09-14 Thread John Millikin
If you don't mind a small performance penalty, have you considered using my library data-binary-ieee754? It contains functions for parsing floats and doubles within the Get monad. On Mon, Sep 14, 2009 at 12:24, minh thu wrote: > Hi, > > I'd like to know if this should work: > > -- GHC coercion >

Re: [Haskell-cafe] Coercion from a Word32/64 to a Float/Double

2009-09-14 Thread minh thu
Hi, Yes I did but since I saw that 'solution', I wanted to try it. There is something that bothers me with your library: its licence. Reading a float shouldn't force me to go GPL (I makes an utility to read Blender files and like to make it BSD3). Thanks for pointing it though. Cheers, Thu 200

Re: [Haskell-cafe] Coercion from a Word32/64 to a Float/Double

2009-09-14 Thread Judah Jacobson
On Mon, Sep 14, 2009 at 12:24 PM, minh thu wrote: > Hi, > > I'd like to know if this should work: > > -- GHC coercion > getFloat :: BHeader -> Get Float > getFloat h = >  case endianness h of >    LittleEndian -> fmap (coerce . fromIntegral) getWord32le >    BigEndian -> fmap (coerce . fromIntegra

Re: [Haskell-cafe] Coercion from a Word32/64 to a Float/Double

2009-09-14 Thread minh thu
2009/9/14 Judah Jacobson : > On Mon, Sep 14, 2009 at 12:24 PM, minh thu wrote: >> Hi, >> >> I'd like to know if this should work: >> >> -- GHC coercion >> getFloat :: BHeader -> Get Float >> getFloat h = >> case endianness h of >>LittleEndian -> fmap (coerce . fromIntegral) getWord32le >>