query: nearest integer divide

keith.briggs@bt.com keith.briggs@bt.com
Mon, 24 Mar 2003 10:18:13 -0000


Dear gmp-discuss,

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:

1. mpz_ui_pow_ui(temp,2,p-1);
    mpz_add(y,x,temp);
    mpz_tdiv_q_2exp(y,y,p);

2. or, compute the quotient and remainder (this seems to need separate
calls in gmp with the 2exp functions), and check the size of the remainder 
compared to the divisor.

Does anybody have any knowledge about which method is faster, or perhaps
an idea for another method?

Thank you,
Keith

	Dr. Keith M. Briggs
	Senior Mathematician, Complexity Research, BTexact Technologies