unwitch-3.0.0: converts between primitives
Safe HaskellNone
LanguageHaskell2010

Unwitch.Convert.Integer

Description

Conversions from Integer.

Synopsis

Conversions

toDouble :: Integer -> Either Overflows Double Source #

Checked conversion, fails if outside exact double integer range (±9007199254740991).

toFloat :: Integer -> Either Overflows Float Source #

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

toNatural :: Integer -> Either Overflows Natural Source #

Returns Left Underflow for negative values.

toCInt :: Integer -> 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.

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

Bounds-checked double conversion via ISIPIN

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

Bounds-checked float conversion via ISIPIN

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

Integer->Natural via ISIPIN

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

Integer->Int8 via ISIPIN, narrow and roundtrip at Int#

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

Integer->Int16 via ISIPIN

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

Integer->Int32 via ISIPIN

toInt64# :: Integer -> (# Int64 | (# #) #) Source #

Integer->Int64 via ISIPIN

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

Integer->Int via ISIPIN

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

Integer->Word8, IS case uses signed->unsigned narrow

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

Integer->Word16

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

Integer->Word32

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

Integer->Word64: IS checks non-negative; IP uses integerToWord# roundtrip

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

Integer->Word: IS checks non-negative; IP uses integerToWord# roundtrip