unwitch-3.0.0: converts between primitives
Safe HaskellNone
LanguageHaskell2010

Unwitch.Convert.Natural

Description

Conversions from Natural.

Synopsis

Conversions

toFloat :: Natural -> Either Overflows Float Source #

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

toDouble :: Natural -> Either Overflows Double Source #

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

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

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

Via naturalToWordMaybe#, then narrow and roundtrip at Word#

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

Via naturalToWordMaybe#, then narrow

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

Via naturalToWordMaybe#, then narrow

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

Via naturalToWordMaybe#, then widen to Word64

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

Via naturalToWordMaybe#

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

Via naturalToWordMaybe#, check upper bound for Int8

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

Via naturalToWordMaybe#, check upper bound for Int16

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

Via naturalToWordMaybe#, check upper bound for Int32

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

Via naturalToWordMaybe#, check fits in non-negative Int64

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

Via naturalToWordMaybe#, check fits in non-negative Int

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

Via naturalToWordMaybe#, bounds-checked float

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

Via naturalToWordMaybe#, bounds-checked double