beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / mpn / generic / pre_mod_1.c
blobcb38f4a48f4ae85c40bf76e116d568b67bbc52dd
1 /* mpn_preinv_mod_1 (up, un, d, dinv) -- Divide (UP,,UN) by the normalized D.
2 DINV should be 2^(2*GMP_LIMB_BITS) / D - 2^GMP_LIMB_BITS.
3 Return the single-limb remainder.
5 Copyright 1991, 1993, 1994, 2000-2002, 2004, 2005 Free Software Foundation,
6 Inc.
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 either:
13 * the GNU Lesser General Public License as published by the Free
14 Software Foundation; either version 3 of the License, or (at your
15 option) any later version.
19 * the GNU General Public License as published by the Free Software
20 Foundation; either version 2 of the License, or (at your option) any
21 later version.
23 or both in parallel, as here.
25 The GNU MP Library is distributed in the hope that it will be useful, but
26 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
27 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 for more details.
30 You should have received copies of the GNU General Public License and the
31 GNU Lesser General Public License along with the GNU MP Library. If not,
32 see https://www.gnu.org/licenses/. */
34 #include "gmp.h"
35 #include "gmp-impl.h"
36 #include "longlong.h"
39 /* This function used to be documented, but is now considered obsolete. It
40 continues to exist for binary compatibility, even when not required
41 internally. */
43 mp_limb_t
44 mpn_preinv_mod_1 (mp_srcptr up, mp_size_t un, mp_limb_t d, mp_limb_t dinv)
46 mp_size_t i;
47 mp_limb_t n0, r;
49 ASSERT (un >= 1);
50 ASSERT (d & GMP_LIMB_HIGHBIT);
52 r = up[un - 1];
53 if (r >= d)
54 r -= d;
56 for (i = un - 2; i >= 0; i--)
58 n0 = up[i];
59 udiv_rnnd_preinv (r, r, n0, d, dinv);
61 return r;