Bug in Data.Bits.shift?

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.

On Thu, Oct 14, 2021 at 08:05:42PM +0000, Keith wrote:
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) ```
That would require `Bits` to be a subclass of both `Ord` and `Bounded`; currently it is only a subclass of `Eq`, and I’d want to be very cautious about changing that. Regards, Seph -- Seph Shewell Brockway, BSc MSc (Glas.) Pronouns: she/her

On Fri, Oct 15, 2021 at 09:22:10PM +0100, Seph Shewell Brockway wrote:
That would require `Bits` to be a subclass of both `Ord` and `Bounded`; currently it is only a subclass of `Eq`, and I’d want to be very cautious about changing that.
Sorry, completely mixed up the two arguments to `shift`. Don’t mind me. S -- Seph Shewell Brockway, BSc MSc (Glas.) Pronouns: she/her

Hi, Am Donnerstag, dem 14.10.2021 um 20:05 +0000 schrieb Keith:
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) ```
thanks, yes, this looks like a bug to me: ghci> shift (-2) (-20000) :: Integer -1 ghci> shift (-2) minBound :: Integer -2 ghci> shift (-2) (-20000) :: Int -1 ghci> shift (-2) minBound :: Int -2 Maybe report it at https://gitlab.haskell.org/ghc/ghc/issues/new (once the gitlab is up again), or even supply a patch. Cheers, Joachim -- Joachim Breitner mail@joachim-breitner.de http://www.joachim-breitner.de/
participants (3)
-
Joachim Breitner
-
Keith
-
Seph Shewell Brockway