query: nearest integer divide

Mirar mirar@lysator.liu.se
24 Mar 2003 18:06:54 +0100

> I have an application where I have a large mpz_t x, and a long p,
> and I want to compute the nearest integer y to x/2^p.   It seems I have
> two obvious ways:

I would do this, barring I never remember the function names,

  y = rightshift(x,p)
  if bit (p-1) is set in x, increase y with 1

...which would work if I didn't misunderstand something.