Bit shifting limitations

John Meacham john at repetae.net
Sun Jul 13 20:53:06 UTC 2014


On Sun, Jul 13, 2014 at 1:33 PM, David Feuer <david.feuer at gmail.com> wrote:
> 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.


Yeah, complement of zero would be better as removing dependencies on
the 'Num' superclass is ideal. but 'high order bit' is tough to
define, for instance 'Integer' is a member of bits, which is okay
because it is specified to be treated as if it is sign extended to
infinity for the purpose of bit ops, But any default refering to
'highest bit' wouldn't work. of course, bitSize already returns an
error for Integer so perhaps this isn't making anything worse.  (which
also bugs me, bitSize should have returned a Maybe Int)

    John

-- 
John Meacham - http://notanumber.net/


More information about the Libraries mailing list