| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Unwitch.Convert.Natural
Contents
Description
Conversions from Natural.
Synopsis
- toWord8 :: Natural -> Maybe Word8
- toWord16 :: Natural -> Maybe Word16
- toWord32 :: Natural -> Maybe Word32
- toWord64 :: Natural -> Maybe Word64
- toWord :: Natural -> Maybe Word
- toInt8 :: Natural -> Maybe Int8
- toInt16 :: Natural -> Maybe Int16
- toInt32 :: Natural -> Maybe Int32
- toInt64 :: Natural -> Maybe Int64
- toInt :: Natural -> Maybe Int
- toInteger :: Natural -> Integer
- toFloat :: Natural -> Either Overflows Float
- toDouble :: Natural -> Either Overflows Double
- toCInt :: Natural -> Maybe CInt
- toWord8# :: Natural -> (# Word8 | (# #) #)
- toWord16# :: Natural -> (# Word16 | (# #) #)
- toWord32# :: Natural -> (# Word32 | (# #) #)
- toWord64# :: Natural -> (# Word64 | (# #) #)
- toWord# :: Natural -> (# Word | (# #) #)
- toInt8# :: Natural -> (# Int8 | (# #) #)
- toInt16# :: Natural -> (# Int16 | (# #) #)
- toInt32# :: Natural -> (# Int32 | (# #) #)
- toInt64# :: Natural -> (# Int64 | (# #) #)
- toInt# :: Natural -> (# Int | (# #) #)
- toFloat# :: Natural -> (# Overflows | Float #)
- toDouble# :: Natural -> (# Overflows | Double #)
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#
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