module Vivid.OSC.Util (
align
, floatToWord
, wordToFloat
) where
import Data.Bits ((.&.), complement, Bits)
import qualified Foreign as F
import System.IO.Unsafe (unsafePerformIO)
align :: (Num i,Bits i) => i -> i
align n = ((n + 3) .&. complement 3) n
floatToWord :: Float -> F.Word32
floatToWord = coercionThing
wordToFloat :: F.Word32 -> Float
wordToFloat = coercionThing
coercionThing :: (F.Storable a, F.Storable b) => a -> b
coercionThing x = unsafePerformIO $ F.alloca $ \buf -> do
F.poke (F.castPtr buf) x
F.peek buf