[Haskell-cafe] Bug in Data.Bits.shift?

Keith keith.wygant at gmail.com
Thu Oct 14 20:05:42 UTC 2021

As currently defined, `shift x minBound` calls `shiftR` with a negative displacement.

This would avoid that:
shift x n
   | n >= 0 = shiftL x n
   | n == minBound = shiftR (shiftR x maxBound) 1
   | otherwise = shiftR x (-n)

P.S. Philosophically, `rotate` on a negative `Integer` should do sign extension in the least significant bits (though by the description of `rotate` it should not...).
Sent from my phone with K-9 Mail.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20211014/1927ebc2/attachment.html>

More information about the Haskell-Cafe mailing list