module Data.Bits

Alastair Reid alastair@reid-consulting-uk.ltd.uk
10 Sep 2002 15:09:56 +0100


> Errm, but in C there is no unified shift operator.  You have << for
> left shift and and >> for right shift, and a negative shift is
> undefined.

[blush]

>> This makes the specification come out nice and clean - you're
>> multiplying the number by 2^n instead of 2^{-n}.

> Errm, but then right shift comes out as dividing by 2^{-n}, instead
> of 2^n.  For a unified shift operation, I don't think there is any
> good reason to prefer one direction over the other, since there is
> no precedent in another language (AFAIK).

I think this spec (for >0 == left shift)

  shift x n = x * 2^^n

is simpler than (for >0 == right shift)

  shift x n = x * 2^^(-n)

[Ok, I probably need a few from/to Fractionals added to those specs]


--
A