unwitch-3.0.0: converts between primitives
Safe HaskellNone
LanguageHaskell2010

Unwitch.Convert.Int

Description

Conversions from Int.

Synopsis

Conversions

toNatural :: Int -> Either Overflows Natural Source #

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

toFloat :: Int -> Either Overflows Float Source #

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

toDouble :: Int -> Either Overflows Double Source #

Checked conversion, fails if outside exact double integer range (+/-9007199254740991).

toCInt :: Int -> Maybe CInt Source #

Narrowing conversion via Int32, fails if outside Int32 range.

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# :: Int -> (# Int8 | (# #) #) Source #

Signed narrowing, roundtrip at Int#

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

Signed narrowing, roundtrip at Int#

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

Signed narrowing, roundtrip at Int#

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

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

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

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

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

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

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

Signed->unsigned, check non-negative

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

Signed->unsigned, check non-negative

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

Check non-negative, construct NS directly

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

Bounds-checked float conversion

toDouble# :: Int -> (# Overflows | Double #) Source #

Bounds-checked double conversion