unsafeCoerce# between integral and floating point types

John Meacham john at repetae.net
Thu Jul 8 15:13:34 EDT 2010

On Thu, Jul 08, 2010 at 04:49:00PM +0200, Daniel Fischer wrote:
> If there are more pitfalls, is there any chance of getting a function which 
> reinterprets the bit-patterns?

Hi, you can do something like this (untested):

castWordToFloat :: Word32 -> Float
castWordToFloat w = unsafePerformIO $ do
        alloca w $ \pw -> do
                peek (castPtr pw) 


John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/

More information about the Glasgow-haskell-users mailing list