Bit shifting limitations

John Meacham john at repetae.net
Sun Jul 13 20:42:05 UTC 2014


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.

Signedness is a convention of how bit patterns are used, the
underlying bit primitives actually implemented are independent of the
language level conventions. It would make no more sense to call a type
error on them than calling a type error on .&. and .|. on Word or Int.
arithmetic shift may have the useful property that negative numbers
are preserved when the bit patterns are interpreted as 2s complement
numbers, but that is just a useful property, not a condition of use.
Shifts are not numeric operations, they are bit operations like .&.
and .|., they just happen to be able to be used to implement numeric
operations in specific circumstances.

    John

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


More information about the Libraries mailing list