1 /* mpn_divrem -- Divide natural numbers, producing both remainder and
2 quotient. This is now just a middle layer for calling the new
5 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000 Free Software
8 This file is part of the GNU MP Library.
10 The GNU MP Library is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or (at your
13 option) any later version.
15 The GNU MP Library is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with the GNU MP Library; see the file COPYING.LIB. If not, write to
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 MA 02111-1307, USA. */
31 mpn_divrem (mp_ptr qp, mp_size_t qxn,
32 mp_ptr np, mp_size_t nn,
33 mp_srcptr dp, mp_size_t dn)
35 mpn_divrem (qp, qxn, np, nn, dp, dn)
52 q2p = (mp_ptr) TMP_ALLOC ((nn + qxn) * BYTES_PER_MP_LIMB);
54 np[0] = mpn_divrem_1 (q2p, qxn, np, nn, dp[0]);
56 MPN_COPY (qp, q2p, qn);
64 return mpn_divrem_2 (qp, qxn, np, nn, dp);
77 n2p = (mp_ptr) TMP_ALLOC ((nn + qxn) * BYTES_PER_MP_LIMB);
79 MPN_COPY (n2p + qxn, np, nn);
80 q2p = (mp_ptr) TMP_ALLOC ((nn - dn + qxn + 1) * BYTES_PER_MP_LIMB);
81 rp = (mp_ptr) TMP_ALLOC (dn * BYTES_PER_MP_LIMB);
82 mpn_tdiv_qr (q2p, rp, 0L, n2p, nn + qxn, dp, dn);
83 MPN_COPY (np, rp, dn);
85 MPN_COPY (qp, q2p, qn);
90 q2p = (mp_ptr) TMP_ALLOC ((nn - dn + 1) * BYTES_PER_MP_LIMB);
91 rp = (mp_ptr) TMP_ALLOC (dn * BYTES_PER_MP_LIMB);
92 mpn_tdiv_qr (q2p, rp, 0L, np, nn, dp, dn);
93 MPN_COPY (np, rp, dn); /* overwrite np area with remainder */
95 MPN_COPY (qp, q2p, qn);