module Data.Bits

Alastair Reid alastair at
Tue Sep 10 10:09:56 EDT 2002

> 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.


>> 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]


More information about the FFI mailing list