Bugs or features?
Per Karlström
per at karlstrom.se
Sat Feb 16 03:08:53 CET 2008
Torbjorn Granlund wrote:
> Being a hardware oriented person I vote for the changing it. Following
> the principle of least surprise (at least from my point of view) an
> arithmetic right shift does one simple operation. And that is to shift
> bits in a register to the right and copy the sign bit to the top most
> bits. That it is the same as a division by 2 is just a side effect of
> what it does. In all assembly languages I know about an arithmetic right
> shift is defined this way.
>
> Arithmetic right shift is *not* the same as division by (a power of)
> 2, as usually implemented in C.
>
> Arithmetic right shift is defined as floor(a / 2^c).
> Division is defined as trunc(a / 2^c), i.e., truncation
> towards zero.
>
I agree with you. What I mean is that an arithmetic right shift should
be thought of as a bit manipulation operation and that it happens to
perform floor(a/2^c) is a mere side effect of the bit manipulation. Thus
the definition is just s mathematical way of writing what it does. I
guess the right shift was not implemented from its definition, rather
the definition is a mathematical after construction.
More information about the gmp-discuss
mailing list