14a1767b4Smrg /* mpz_cdiv_q -- Division rounding the quotient towards +infinity. The
24a1767b4Smrg remainder gets the opposite sign as the denominator.
34a1767b4Smrg
4*f81b1c5bSmrg Copyright 1994-1996, 2000, 2001, 2005, 2012 Free Software Foundation, Inc.
54a1767b4Smrg
64a1767b4Smrg This file is part of the GNU MP Library.
74a1767b4Smrg
84a1767b4Smrg The GNU MP Library is free software; you can redistribute it and/or modify
9*f81b1c5bSmrg it under the terms of either:
10*f81b1c5bSmrg
11*f81b1c5bSmrg * the GNU Lesser General Public License as published by the Free
12*f81b1c5bSmrg Software Foundation; either version 3 of the License, or (at your
134a1767b4Smrg option) any later version.
144a1767b4Smrg
15*f81b1c5bSmrg or
16*f81b1c5bSmrg
17*f81b1c5bSmrg * the GNU General Public License as published by the Free Software
18*f81b1c5bSmrg Foundation; either version 2 of the License, or (at your option) any
19*f81b1c5bSmrg later version.
20*f81b1c5bSmrg
21*f81b1c5bSmrg or both in parallel, as here.
22*f81b1c5bSmrg
234a1767b4Smrg The GNU MP Library is distributed in the hope that it will be useful, but
244a1767b4Smrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25*f81b1c5bSmrg or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26*f81b1c5bSmrg for more details.
274a1767b4Smrg
28*f81b1c5bSmrg You should have received copies of the GNU General Public License and the
29*f81b1c5bSmrg GNU Lesser General Public License along with the GNU MP Library. If not,
30*f81b1c5bSmrg see https://www.gnu.org/licenses/. */
314a1767b4Smrg
324a1767b4Smrg #include "gmp-impl.h"
334a1767b4Smrg
344a1767b4Smrg void
mpz_cdiv_q(mpz_ptr quot,mpz_srcptr dividend,mpz_srcptr divisor)354a1767b4Smrg mpz_cdiv_q (mpz_ptr quot, mpz_srcptr dividend, mpz_srcptr divisor)
364a1767b4Smrg {
37d25e02daSmrg mp_size_t dividend_size = SIZ (dividend);
38d25e02daSmrg mp_size_t divisor_size = SIZ (divisor);
394a1767b4Smrg mpz_t rem;
404a1767b4Smrg TMP_DECL;
414a1767b4Smrg
424a1767b4Smrg TMP_MARK;
434a1767b4Smrg
444a1767b4Smrg MPZ_TMP_INIT (rem, ABS (divisor_size));
454a1767b4Smrg
464a1767b4Smrg mpz_tdiv_qr (quot, rem, dividend, divisor);
474a1767b4Smrg
48d25e02daSmrg if ((divisor_size ^ dividend_size) >= 0 && SIZ (rem) != 0)
494a1767b4Smrg mpz_add_ui (quot, quot, 1L);
504a1767b4Smrg
514a1767b4Smrg TMP_FREE;
524a1767b4Smrg }
53