Annotation of OpenXM_contrib/gmp/mpz/tdiv_ui.c, Revision 1.1.1.2
1.1.1.2 ! ohara 1: /* mpz_tdiv_ui(dividend, divisor_limb) -- Return DIVDEND mod DIVISOR_LIMB.
1.1 maekawa 2:
1.1.1.2 ! ohara 3: Copyright 1991, 1993, 1994, 1996, 1997, 1998, 2001, 2002 Free Software
! 4: Foundation, Inc.
1.1 maekawa 5:
6: This file is part of the GNU MP Library.
7:
8: The GNU MP Library is free software; you can redistribute it and/or modify
9: it under the terms of the GNU Lesser General Public License as published by
10: the Free Software Foundation; either version 2.1 of the License, or (at your
11: option) any later version.
12:
13: The GNU MP Library is distributed in the hope that it will be useful, but
14: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16: License for more details.
17:
18: You should have received a copy of the GNU Lesser General Public License
19: along with the GNU MP Library; see the file COPYING.LIB. If not, write to
20: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21: MA 02111-1307, USA. */
22:
23: #include "gmp.h"
24: #include "gmp-impl.h"
1.1.1.2 ! ohara 25: #include "longlong.h"
1.1 maekawa 26:
27: unsigned long int
28: mpz_tdiv_ui (mpz_srcptr dividend, unsigned long int divisor)
29: {
1.1.1.2 ! ohara 30: mp_size_t ns, nn;
! 31: mp_ptr np;
! 32: mp_limb_t rl;
1.1 maekawa 33:
34: if (divisor == 0)
35: DIVIDE_BY_ZERO;
36:
1.1.1.2 ! ohara 37: ns = SIZ(dividend);
! 38: if (ns == 0)
! 39: {
! 40: return 0;
! 41: }
! 42:
! 43: nn = ABS(ns);
! 44: np = PTR(dividend);
! 45:
! 46: #if GMP_NAIL_BITS != 0
! 47: if (divisor > GMP_NUMB_MAX)
! 48: {
! 49: mp_limb_t dp[2], rp[2];
! 50: mp_ptr qp;
! 51: mp_size_t rn;
! 52: TMP_DECL (mark);
! 53:
! 54: if (nn == 1) /* tdiv_qr requirements; tested above for 0 */
! 55: {
! 56: rl = np[0];
! 57: return rl;
! 58: }
! 59:
! 60: TMP_MARK (mark);
! 61: dp[0] = divisor & GMP_NUMB_MASK;
! 62: dp[1] = divisor >> GMP_NUMB_BITS;
! 63: qp = TMP_ALLOC_LIMBS (nn - 2 + 1);
! 64: mpn_tdiv_qr (qp, rp, (mp_size_t) 0, np, nn, dp, (mp_size_t) 2);
! 65: TMP_FREE (mark);
! 66: rl = rp[0] + (rp[1] << GMP_NUMB_BITS);
! 67: rn = 2 - (rp[1] == 0); rn -= (rp[rn - 1] == 0);
! 68: }
! 69: else
! 70: #endif
! 71: {
! 72: rl = mpn_mod_1 (np, nn, (mp_limb_t) divisor);
! 73: }
1.1 maekawa 74:
1.1.1.2 ! ohara 75: return rl;
1.1 maekawa 76: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>