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

Joachim Breitner mail at joachim-breitner.de
Sun Oct 17 11:53:43 UTC 2021


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 at joachim-breitner.de
  http://www.joachim-breitner.de/




More information about the Haskell-Cafe mailing list