#Cyrille37# cyrille37 at gmail.com
Mon Jan 28 16:13:10 CET 2008

```Paul Zimmermann a écrit :
>> Hello,
>> I'm not a expert with mathematic, so I come to you because I need to
>> find the divider and the remainder of 2 numbers, like the Java
>> BigInteger.DivideAndRemainder() do. I do not know wich GMP's divide
>> function to use :
>>
>> To get the remainder I think I've just to call mpz_mod() but I do not
>> know the divide function : cdiv or fdiv or tdiv or another ?
>>
>> Cyrille.
>>
>
> mpz_mod returns the classical remainder, i.e., in [0, |D|-1].
>
> The difference between the cdiv/fdiv/tdiv is clearly explained in the manual:
>
>         * `cdiv' rounds Q up towards +infinity, and R will have the
>           opposite sign to D.  The `c' stands for "ceil".
>
>         * `fdiv' rounds Q down towards -infinity, and R will have the
>           same sign as D.  The `f' stands for "floor".
>
>         * `tdiv' rounds Q towards zero, and R will have the same sign
>           as N.  The `t' stands for "truncate".
>
> For a positive divisor D, mpz_mod thus corresponds to fdiv. Note that if you
> want to be sure that N=Q*D+R, it is better to use the mpz_?div_qr functions,
> which return both quotient and remainder.
>
> Paul Zimmermann
>
Thanks a lot Paul.

The following step for me is how to compute the Java equivalent of
ModInverse() ?
Sorry for my poor questions but I'm not fine with mathematics.

Thanks again
Cyrille.

```