packages feed

columbia-0.1.0.0: src/Data/Columbia/Coercion.hs

{-# LANGUAGE Trustworthy #-}

module Data.Columbia.Coercion (floatToInt32, int32ToFloat) where

import Foreign.Marshal.Utils
import Foreign.Storable
import Foreign.Ptr
import System.IO.Unsafe
import Data.Int

{-# INLINE unsafeCoerceBits #-}
unsafeCoerceBits :: (Storable t, Storable u) => t -> u
unsafeCoerceBits n = unsafePerformIO$with n(peek.castPtr)

floatToInt32 :: Float -> Int32
floatToInt32 = unsafeCoerceBits

int32ToFloat :: Int32 -> Float
int32ToFloat = unsafeCoerceBits