Bugs or features?

Torbjorn Granlund tg at swox.com
Sat Feb 16 01:19:57 CET 2008


  I am just wondering if this is by design or if this is a bug?

  The question if this is the intended functionality of the >>= operator
  for negative numbers. This differs from how it is defined for native
  types like int for example.

This is a sticky issue.

In the C standard, the behaviour of right shift of negative numbers is
undefined.  But in practice, almost every compiler defines it as
rounding towards -oo.  The one exception I am aware of is Cray's
compilers for their vector systems.  (They shift the numbers logically
always, which is not very helpful.)

I am inclined to changing gmpxx.h to make it follow the common
behaviour, although that is not formally standardized.

What do people think?  I am mainly interested in the opinion of people
that actually use gmpxx.h.

(The change is trivial, just change the t to an f in mpz_tdiv_q_2exp
in gmpxx.h.)

-- 
Torbjörn


More information about the gmp-discuss mailing list