Commits

Iago Abal committed 26dc153

A few helpers: isNat, isPos and signumI

  • Participants
  • Parent commits 47908e3

Comments (0)

Files changed (1)

Data/BitVector.hs

     -- * Creation
   , bitVec
   , ones, zeros
+    -- * Test
+  , isNat
+  , isPos
     -- * Comparison
   , (==.), (/=.)
   , (<.), (<=.), (>.), (>=.)
   , least, most
   , msb, lsb, msb1
   -- * Arithmetic
+  , signumI
   , sdiv, srem, smod
   , lg2
   -- * List-like operations
 {-# INLINE zeros #-}
 
 ----------------------------------------------------------------------
+--- Test
+
+isNat :: BV -> Bool
+isNat a = signumI(a) >= (0::Integer)
+
+isPos :: BV -> Bool
+isPos a = signumI(a) > (0::Integer)
+
+----------------------------------------------------------------------
 --- Comparison
 
 infix 4 ==., /=., <., <=., >., >=.
   signum u = bitVec 2 $ signum $ int u
   fromInteger i = bitVec (integerWidth i) i
 
+signumI :: Integral a => BV -> a
+signumI = fromInteger . signum . int
+
 instance Real BV where
   toRational = toRational . nat