Copyright | (c) Edward Kmett 2013-2014 |
---|---|
License | BSD3 |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Trustworthy |
Language | Haskell98 |
Calculate a number of fiddly bit operations using fast de Bruijn multiplication tables.
- class (Num t, FiniteBits t) => Ranked t where
- log2 :: Word32 -> Int
- msb :: Ranked t => t -> Int
- w8 :: Integral a => a -> Word8
- w16 :: Integral a => a -> Word16
- w32 :: Integral a => a -> Word32
- w64 :: Integral a => a -> Word64
- assignBit :: Bits b => b -> Int -> Bool -> b
- zeroBits :: Bits a => a
- oneBits :: Bits b => b
- srl :: Bits b => b -> Int -> b
Documentation
class (Num t, FiniteBits t) => Ranked t where Source #
Calculate the least significant set bit using a debruijn multiplication table. NB: The result of this function is undefined when given 0.
Calculate the number of trailing 0 bits.
Calculate the number of leading zeros.
zeroBits
is the value with all bits unset.
The following laws ought to hold (for all valid bit indices n
):
clearBit
zeroBits
n ==zeroBits
setBit
zeroBits
n ==bit
ntestBit
zeroBits
n == FalsepopCount
zeroBits
== 0
This method uses
as its default
implementation (which ought to be equivalent to clearBit
(bit
0) 0zeroBits
for
types which possess a 0th bit).
Since: 4.7.0.0