Bit shifting limitations
Henning Thielemann
schlepptop at henning-thielemann.de
Sun Jul 13 20:55:59 UTC 2014
Am 13.07.2014 22:42, schrieb John Meacham:
> On Sun, Jul 13, 2014 at 12:42 PM, Henning Thielemann
> <schlepptop at henning-thielemann.de> wrote:
>> So far, I'd say, that calling "asr" on Word and "lsr" on Int should be a
>> type error.
>
>
> No, that would completely ruin the point of having them, the whole
> idea is being able to perform specifically an arithmetic or logical
> shift independent of the signedness of the underlying type.
I'd prefer to distinguish between IntN, CardN (aka WordN) and BitSetN.
IntN are signed integers, CardN are unsigned integers and BitSetN is a
bit pattern without a numeric interpretation (flags, graphical patterns
...). IntN and CardN would be in a sub-class of Num that supports
multiplication, division and modulo with powers of two, which can be
efficiently implemented by shifts and bitwise Ands. BitSetN would
support all kinds of logical and arithmetical shifts,
shifts-through-carry, rotations, bit counts, bitwise logic and what know I.
Bit manipulation of numbers as provided by the Bits class was certainly
not a good idea and will not become better by extending in that direction.
More information about the Libraries
mailing list