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 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001 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. */
30
mpn_divrem (mp_ptr qp, mp_size_t qxn,
31
mp_ptr np, mp_size_t nn,
32
mp_srcptr dp, mp_size_t dn)
37
ASSERT (dp[dn-1] & MP_LIMB_T_HIGHBIT);
38
ASSERT (! MPN_OVERLAP_P (np, nn, dp, dn));
39
ASSERT (! MPN_OVERLAP_P (qp, nn-dn+qxn, np, nn) || qp==np+dn+qxn);
40
ASSERT (! MPN_OVERLAP_P (qp, nn-dn+qxn, dp, dn));
50
q2p = (mp_ptr) TMP_ALLOC ((nn + qxn) * BYTES_PER_MP_LIMB);
52
np[0] = mpn_divrem_1 (q2p, qxn, np, nn, dp[0]);
54
MPN_COPY (qp, q2p, qn);
62
return mpn_divrem_2 (qp, qxn, np, nn, dp);
75
n2p = (mp_ptr) TMP_ALLOC ((nn + qxn) * BYTES_PER_MP_LIMB);
77
MPN_COPY (n2p + qxn, np, nn);
78
q2p = (mp_ptr) TMP_ALLOC ((nn - dn + qxn + 1) * BYTES_PER_MP_LIMB);
79
rp = (mp_ptr) TMP_ALLOC (dn * BYTES_PER_MP_LIMB);
80
mpn_tdiv_qr (q2p, rp, 0L, n2p, nn + qxn, dp, dn);
81
MPN_COPY (np, rp, dn);
83
MPN_COPY (qp, q2p, qn);
88
q2p = (mp_ptr) TMP_ALLOC ((nn - dn + 1) * BYTES_PER_MP_LIMB);
89
rp = (mp_ptr) TMP_ALLOC (dn * BYTES_PER_MP_LIMB);
90
mpn_tdiv_qr (q2p, rp, 0L, np, nn, dp, dn);
91
MPN_COPY (np, rp, dn); /* overwrite np area with remainder */
93
MPN_COPY (qp, q2p, qn);