Bugs or features?

Per Karlström per at karlstrom.se
Fri Feb 15 02:40:12 CET 2008


Sorry for the previous post, C-x C-s is not good in Thunderbird ;)

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 code is an example of what I mean.

#include <gmpxx.h>
#include <cassert>

int main()
{
  //111....101 = -3 in 2'complement representation
  mpz_class val_mpz(-3);
  int a = -3;

  val_mpz>>=1; //Should be 111...10 = -2 for an arithmetic right shift
  a>>=1;

  assert(val_mpz == a); //This will fail!.


  return 0;
}


More information about the gmp-discuss mailing list