unwitch-3.0.0: converts between primitives
Safe HaskellNone
LanguageHaskell2010

Unwitch.Convert.Int32

Description

Conversions from Int32.

Synopsis

Conversions

toInt :: Int32 -> Int Source #

Total conversion — GHC implements Int using the primitive type Int#, whose size equals the MachDeps.h constant WORD_SIZE_IN_BITS (32 on 32-bit platforms, 64 on 64-bit). Since Int# is always at least 32 bits wide, every Int32 value fits without loss.

See: GHC.Prim ("Int32 always fits in Int (Int is at least 32 bits)") and Data.Int ("A fixed-precision integer type with at least the range [-2^29 .. 2^29-1]").

toNatural :: Int32 -> Either Overflows Natural Source #

Signed-to-unsigned conversion, returns Left Underflow for negative values.

toFloat :: Int32 -> Either Overflows Float Source #

Checked conversion, fails if outside exact float integer range (+-16777215).

toCInt :: Int32 -> CInt Source #

Direct wrapping, CInt is a newtype over Int32.

Unboxed conversions

These use GHC unboxed types and unboxed sums for zero-allocation failure handling. Requires the MagicHash, UnboxedSums and UnboxedTuples language extensions. See the GHC manual on unboxed types.

toInt8# :: Int32 -> (# Int8 | (# #) #) Source #

Signed narrowing, roundtrip at Int#

toInt16# :: Int32 -> (# Int16 | (# #) #) Source #

Signed narrowing, roundtrip at Int#

toInt# :: Int32 -> (# Int | (# #) #) Source #

Int32 always fits in Int (Int is at least 32 bits)

toWord8# :: Int32 -> (# Word8 | (# #) #) Source #

Signed->unsigned narrow, roundtrip via Word# back to Int#

toWord16# :: Int32 -> (# Word16 | (# #) #) Source #

Signed->unsigned narrow, roundtrip via Word# back to Int#

toWord32# :: Int32 -> (# Word32 | (# #) #) Source #

Signed->unsigned, check non-negative

toWord64# :: Int32 -> (# Word64 | (# #) #) Source #

Signed->unsigned, check non-negative

toWord# :: Int32 -> (# Word | (# #) #) Source #

Signed->unsigned, check non-negative

toNatural# :: Int32 -> (# Overflows | Natural #) Source #

Check non-negative, construct NS directly

toFloat# :: Int32 -> (# Overflows | Float #) Source #

Bounds-checked float conversion