Copyright | (c) Galois Inc 2015-2020 |
---|---|
License | BSD3 |
Maintainer | Joe Hendrix <jhendrix@galois.com> |
Stability | provisional |
Safe Haskell | Safe |
Language | Haskell2010 |
Synopsis
- isPow2 :: (Bits a, Num a) => a -> Bool
- lg :: (Bits a, Num a, Ord a) => a -> Int
- lgCeil :: (Bits a, Num a, Ord a) => a -> Int
- nextMultiple :: Integral a => a -> a -> a
- nextPow2Multiple :: (Bits a, Integral a) => a -> Int -> a
- tryIntSqrt :: Integer -> Maybe Integer
- tryRationalSqrt :: Rational -> Maybe Rational
- roundAway :: RealFrac a => a -> Integer
- ctz :: NatRepr w -> Integer -> Integer
- clz :: NatRepr w -> Integer -> Integer
- rotateLeft :: NatRepr w -> Integer -> Integer -> Integer
- rotateRight :: NatRepr w -> Integer -> Integer -> Integer
Arithmetic utilities
lgCeil :: (Bits a, Num a, Ord a) => a -> Int Source #
Returns ceil of log base 2.
We define lgCeil 0 = 0
nextMultiple :: Integral a => a -> a -> a Source #
nextMultiple x y
computes the next multiple m of x s.t. m >= y. E.g.,
nextMultiple 4 8 = 8 since 8 is a multiple of 8; nextMultiple 4 7 = 8;
nextMultiple 8 6 = 8.
nextPow2Multiple :: (Bits a, Integral a) => a -> Int -> a Source #
nextPow2Multiple x n
returns the smallest multiple of 2^n
not less than x
.
tryIntSqrt :: Integer -> Maybe Integer Source #
This returns the sqrt of an integer if it is well-defined.
roundAway :: RealFrac a => a -> Integer Source #
Evaluate a real to an integer with rounding away from zero.