Maintainer | Ziyang Liu <free@cofree.io> |
---|---|
Safe Haskell | Safe |
Language | Haskell2010 |
Arithmetic on integral numbers.
Synopsis
- saturatedFromInteger :: forall a. (Integral a, Bounded a) => Integer -> a
- saturatedAdd :: (Integral a, Bounded a) => a -> a -> a
- saturatedSubtract :: (Integral a, Bounded a) => a -> a -> a
- saturatedMultiply :: (Integral a, Bounded a) => a -> a -> a
- saturatedPow :: Int -> Int -> Int
- toBinaryString :: FiniteBits b => b -> NonEmpty Char
Saturated arithmetic
saturatedFromInteger :: forall a. (Integral a, Bounded a) => Integer -> a Source #
Like fromInteger
, but returns maxBound
and minBound
in case of
overflow and underflow, respectively.
saturatedAdd :: (Integral a, Bounded a) => a -> a -> a Source #
saturatedSubtract :: (Integral a, Bounded a) => a -> a -> a Source #
saturatedMultiply :: (Integral a, Bounded a) => a -> a -> a Source #
Other helper functions
toBinaryString :: FiniteBits b => b -> NonEmpty Char Source #
Returns the bit representation of the input as a NonEmpty
Char
consisting of 0
s and 1
s,
without leading zeros. The length of the result is at most finiteBitSize
b
.
Data.List.NonEmpty.toList (toBinaryString (100 :: Int)) == "1100100" Data.List.NonEmpty.toList (toBinaryString (-1 :: Int8)) == "11111111"