Bit shifting limitations

David Feuer david.feuer at gmail.com
Sun Jul 13 20:33:27 UTC 2014


No, you're right about that. I'm not too clear on what a right shift of a
negative number not represented with 2's complement is supposed to mean (or
what any of these shifts should mean for a non-binary representation). And
you're right that I missed a key test. One possibility is just to test the
high order bit directly and test with that, and use the complement of 0
instead of -1.
On Jul 13, 2014 4:18 PM, "John Meacham" <john at repetae.net> wrote:

> On Sun, Jul 13, 2014 at 12:47 PM, David Feuer <david.feuer at gmail.com>
> wrote:
> > ShiftRArithmetic x c = if (isSigned x)
> >                                       then shiftR x c
> >                                       else (-1 `shiftR` c) .|. (x
> `shiftR`
> > c)
>
>
> hmm... that isn't quite it because it will always add in the ones on
> the left when you only want to do it when the high bit is set, plus it
> assumes a specific representation for -1.
>
>    John
>
> --
> John Meacham - http://notanumber.net/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140713/e4fc79ba/attachment.html>


More information about the Libraries mailing list