beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / mpn / generic / bdiv_q.c
blob1fc1bb7c099dae5f323925feb83261f786f29377
1 /* mpn_bdiv_q -- Hensel division with precomputed inverse, returning quotient.
3 Contributed to the GNU project by Torbjorn Granlund.
5 THE FUNCTIONS IN THIS FILE ARE INTERNAL WITH MUTABLE INTERFACES. IT IS ONLY
6 SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS ALMOST
7 GUARANTEED THAT THEY WILL CHANGE OR DISAPPEAR IN A FUTURE GMP RELEASE.
9 Copyright 2006, 2007, 2009 Free Software Foundation, Inc.
11 This file is part of the GNU MP Library.
13 The GNU MP Library is free software; you can redistribute it and/or modify
14 it under the terms of either:
16 * the GNU Lesser General Public License as published by the Free
17 Software Foundation; either version 3 of the License, or (at your
18 option) any later version.
22 * the GNU General Public License as published by the Free Software
23 Foundation; either version 2 of the License, or (at your option) any
24 later version.
26 or both in parallel, as here.
28 The GNU MP Library is distributed in the hope that it will be useful, but
29 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
30 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
31 for more details.
33 You should have received copies of the GNU General Public License and the
34 GNU Lesser General Public License along with the GNU MP Library. If not,
35 see https://www.gnu.org/licenses/. */
37 #include "gmp.h"
38 #include "gmp-impl.h"
41 /* Computes Q = N / D mod B^n. */
43 void
44 mpn_bdiv_q (mp_ptr qp,
45 mp_srcptr np, mp_size_t nn,
46 mp_srcptr dp, mp_size_t dn,
47 mp_ptr tp)
49 mp_limb_t di;
51 if (BELOW_THRESHOLD (dn, DC_BDIV_Q_THRESHOLD))
53 MPN_COPY (tp, np, nn);
54 binvert_limb (di, dp[0]); di = -di;
55 mpn_sbpi1_bdiv_q (qp, tp, nn, dp, dn, di);
57 else if (BELOW_THRESHOLD (dn, MU_BDIV_Q_THRESHOLD))
59 MPN_COPY (tp, np, nn);
60 binvert_limb (di, dp[0]); di = -di;
61 mpn_dcpi1_bdiv_q (qp, tp, nn, dp, dn, di);
63 else
65 mpn_mu_bdiv_q (qp, np, nn, dp, dn, tp);
67 return;
70 mp_size_t
71 mpn_bdiv_q_itch (mp_size_t nn, mp_size_t dn)
73 if (BELOW_THRESHOLD (dn, MU_BDIV_Q_THRESHOLD))
74 return nn;
75 else
76 return mpn_mu_bdiv_q_itch (nn, dn);