# mpz_cdiv_q_2exp

delta trinity deltatrinity@hotmail.com
Thu, 21 Nov 2002 15:43:42 -0500

```The function divide a number by a power of two.  The 'q' in the expression
meen that you want the quotient.  Some variations include 'r' to return
remainder and 'qr' to return both.

Ex: X/2^Y

This is much faster than doing the regular division algorithm as only
logical shifts are involved.

the fdiv round to lowest integer value while the cdiv to highest integer
value.

ex, if you have 100/2^3 (equivalent to 100/8), you get 12.5.  fdiv would
return 12 while cdiv would return 13.  In case of negative numbers, ex:
-100/2^3, giving -12.5, fdiv would return -13 and cdiv would return -12.
You can also specify 'tdiv', 't' for trunc.  In then round the number to the
next value toware zero.  In the last example, they would give 12 and -12.

100/2^2 (or 100/4), giving exactly 25, would return, in both cases, 25.

If you already know that the denominator is a power of two, use the ..._2exp
function.

ex, 100/2^2.
In binary, 100 is:
01100100.

Shift right by to, you get:
00011001 (or, in decimal, 25)

>From: "Chris Saunders" <chris.saunders@sympatico.ca>
>To: "GMP" <gmp-discuss@swox.com>
>Subject: mpz_cdiv_q_2exp
>Date: Thu, 21 Nov 2002 14:25:24 -0500
>
>I am working on an Eiffel interface to GMP and am
>trying to document the code as I go along.  I didn't
>feel that I understood what the function mpz_cdiv_q_2exp
>does and hope that someone might provide me with
>a better explanation than I found in the provided
>documentation.
>
>Regards
>Chris Saunders
>chris.saunders.@sympatico.ca

_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail

```