Bugs or features?

Torbjorn Granlund tg at swox.com
Sat Feb 16 02:35:28 CET 2008


  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.

-- 
Torbjörn


More information about the gmp-discuss mailing list