[commit: integer-simple] master: Define testBitInteger; part of #3489. Patch from pumpkingod at gmail.com (d5ee098)
Ian Lynagh
igloo at earth.li
Sun Aug 5 17:40:45 CEST 2012
Repository : ssh://darcs.haskell.org//srv/darcs/packages/integer-simple
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/d5ee098c0e801fbd2590a526c0cb30d5935a36fd
>---------------------------------------------------------------
commit d5ee098c0e801fbd2590a526c0cb30d5935a36fd
Author: Ian Lynagh <ian at well-typed.com>
Date: Sun Aug 5 15:56:00 2012 +0100
Define testBitInteger; part of #3489. Patch from pumpkingod at gmail.com
>---------------------------------------------------------------
GHC/Integer.hs | 2 +-
GHC/Integer/Type.hs | 7 +++++++
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/GHC/Integer.hs b/GHC/Integer.hs
index 4122d38..3bc8f16 100644
--- a/GHC/Integer.hs
+++ b/GHC/Integer.hs
@@ -33,7 +33,7 @@ module GHC.Integer (
encodeDoubleInteger, decodeDoubleInteger, doubleFromInteger,
-- gcdInteger, lcmInteger, -- XXX
andInteger, orInteger, xorInteger, complementInteger,
- shiftLInteger, shiftRInteger,
+ shiftLInteger, shiftRInteger, testInteger,
hashInteger,
) where
diff --git a/GHC/Integer/Type.hs b/GHC/Integer/Type.hs
index 67ed19c..ee2c08f 100644
--- a/GHC/Integer/Type.hs
+++ b/GHC/Integer/Type.hs
@@ -314,6 +314,13 @@ shiftRInteger j@(Negative _) i
= complementInteger (shiftRInteger (complementInteger j) i)
shiftRInteger Naught _ = Naught
+-- XXX this could be a lot more efficient, but this is a quick
+-- reimplementation of the default Data.Bits instance, so that we can
+-- implement the Integer interface
+testBitInteger :: Integer -> Int# -> Bool
+testBitInteger x i = (x `andInteger` (smallInteger 1# `shiftLInteger` i))
+ `neqInteger` smallInteger 0#
+
twosComplementPositive :: Positive -> DigitsOnes
twosComplementPositive p = flipBits (p `minusPositive` onePositive)
More information about the Cvs-libraries
mailing list