#include "MachDeps.h"
module Z.Data.Array.Cast
( Cast(..)
) where
import GHC.Exts
import GHC.Int
import GHC.Word
#if WORD_SIZE_IN_BITS < 64
import GHC.IntWord64
#endif
import GHC.Float
class Cast source destination where
cast :: source -> destination
instance {-# INCOHERENT #-} Coercible a b => Cast a b where
cast :: a -> b
cast = coerce :: forall a b. Coercible a b => a -> b
coerce
instance Cast Int8 Word8 where
{-# INLINE cast #-}
cast :: Int8 -> Word8
cast (I8# Int8#
i) = Word8# -> Word8
W8# (Int8# -> Word8#
int8ToWord8# Int8#
i)
instance Cast Int16 Word16 where
{-# INLINE cast #-}
cast :: Int16 -> Word16
cast (I16# Int16#
i) = Word16# -> Word16
W16# (Int16# -> Word16#
int16ToWord16# Int16#
i)
instance Cast Int32 Word32 where
{-# INLINE cast #-}
cast :: Int32 -> Word32
cast (I32# Int32#
i) = Word32# -> Word32
W32# (Int32# -> Word32#
int32ToWord32# Int32#
i)
instance Cast Int64 Word64 where
{-# INLINE cast #-}
#if WORD_SIZE_IN_BITS < 64
cast (I64# i) = W64# (int64ToWord64# i)
#else
cast :: Int64 -> Word64
cast (I64# Int#
i) = Word# -> Word64
W64# (Int# -> Word#
int2Word# Int#
i)
#endif
instance Cast Int Word where
{-# INLINE cast #-}
cast :: Int -> Word
cast (I# Int#
i) = Word# -> Word
W# (Int# -> Word#
int2Word# Int#
i)
instance Cast Word8 Int8 where
{-# INLINE cast #-}
cast :: Word8 -> Int8
cast (W8# Word8#
i) = Int8# -> Int8
I8# (Word8# -> Int8#
word8ToInt8# Word8#
i)
instance Cast Word16 Int16 where
{-# INLINE cast #-}
cast :: Word16 -> Int16
cast (W16# Word16#
i) = Int16# -> Int16
I16# (Word16# -> Int16#
word16ToInt16# Word16#
i)
instance Cast Word32 Int32 where
{-# INLINE cast #-}
cast :: Word32 -> Int32
cast (W32# Word32#
i) = Int32# -> Int32
I32# (Word32# -> Int32#
word32ToInt32# Word32#
i)
instance Cast Word64 Int64 where
{-# INLINE cast #-}
#if WORD_SIZE_IN_BITS < 64
cast (W64# i) = I64# (word64ToInt64# i)
#else
cast :: Word64 -> Int64
cast (W64# Word#
i) = Int# -> Int64
I64# (Word# -> Int#
word2Int# Word#
i)
#endif
instance Cast Word Int where
{-# INLINE cast #-}
cast :: Word -> Int
cast (W# Word#
w) = Int# -> Int
I# (Word# -> Int#
word2Int# Word#
w)
instance Cast Word64 Double where
{-# INLINE cast #-}
cast :: Word64 -> Double
cast = Word64 -> Double
castWord64ToDouble
instance Cast Word32 Float where
{-# INLINE cast #-}
cast :: Word32 -> Float
cast = Word32 -> Float
castWord32ToFloat
instance Cast Double Word64 where
{-# INLINE cast #-}
cast :: Double -> Word64
cast = Double -> Word64
castDoubleToWord64
instance Cast Float Word32 where
{-# INLINE cast #-}
cast :: Float -> Word32
cast = Float -> Word32
castFloatToWord32
instance Cast Int64 Double where
{-# INLINE cast #-}
cast :: Int64 -> Double
cast = Word64 -> Double
castWord64ToDouble forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall source destination.
Cast source destination =>
source -> destination
cast
instance Cast Int32 Float where
{-# INLINE cast #-}
cast :: Int32 -> Float
cast = Word32 -> Float
castWord32ToFloat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall source destination.
Cast source destination =>
source -> destination
cast
instance Cast Double Int64 where
{-# INLINE cast #-}
cast :: Double -> Int64
cast = forall source destination.
Cast source destination =>
source -> destination
cast forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Word64
castDoubleToWord64
instance Cast Float Int32 where
{-# INLINE cast #-}
cast :: Float -> Int32
cast = forall source destination.
Cast source destination =>
source -> destination
cast forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> Word32
castFloatToWord32