[GHC] #7860: Add more bit fiddling functions to 'integer-gmp'
GHC
ghc-devs at haskell.org
Sun Jun 9 22:03:26 CEST 2013
#7860: Add more bit fiddling functions to 'integer-gmp'
--------------------------------+-------------------------------------------
Reporter: lebedev | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: libraries (other) | Version: 7.6.3
Resolution: | Keywords: gmp
Os: Unknown/Multiple | Architecture: Unknown/Multiple
Failure: None/Unknown | Difficulty: Unknown
Testcase: | Blockedby:
Blocking: | Related: #3489
--------------------------------+-------------------------------------------
Comment(by lebedev):
Actually, there should also be a case for negative bits, so the full
version is:
{{{
clearBitInteger :: Integer -> Int# -> Integer
clearBitInteger (S# j) i
| i <# 0# || i >=# (WORD_SIZE_IN_BITS# -# 1#) = S# j
| otherwise =
let !mask =
int2Word# (1# `uncheckedIShiftL#` i) `xor#`
int2Word# (negateInt# 1#)
in S# (word2Int# (int2Word# j `and#` mask))
clearBitInteger (J# s d) i =
let !(# s', d' #) = clearBitInteger# s d i in J# s' d'
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7860#comment:8>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list