packages feed

cdar-mBound-0.1.0.0: src/Data/CDAR/Classes.hs

{-|
Defines the 'Scalable' type class.
-}
module Data.CDAR.Classes where

import Data.Bits

-- | 'Scalable' allows scaling numerical data types by powers of 2.
class Scalable a where
  scale :: a -> Int -> a

-- | The 'Integer' instance.
instance Scalable Integer where
  scale x n
    | n >= 0 = unsafeShiftL x n
    | otherwise = unsafeShiftR (x + bit (-n-1)) (-n)