Annotation of OpenXM_contrib/gmp/mpbsd/sdiv.c, Revision 1.1.1.3
1.1 maekawa 1: /* sdiv -- Divide a MINT by a short integer. Produce a MINT quotient
2: and a short remainder.
3:
1.1.1.3 ! ohara 4: Copyright 1991, 1994, 1995, 2000, 2001 Free Software 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
1.1.1.2 maekawa 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
1.1 maekawa 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
1.1.1.2 maekawa 15: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
1.1 maekawa 16: License for more details.
17:
1.1.1.2 maekawa 18: You should have received a copy of the GNU Lesser General Public License
1.1 maekawa 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 "mp.h"
24: #include "gmp.h"
25: #include "gmp-impl.h"
26: #include "longlong.h"
27:
28: void
29: sdiv (const MINT *dividend, signed short int divisor_short, MINT *quot, short *rem_ptr)
30: {
31: mp_size_t sign_dividend;
32: signed long int sign_divisor;
33: mp_size_t dividend_size, quot_size;
34: mp_ptr dividend_ptr, quot_ptr;
35: mp_limb_t divisor_limb;
36: mp_limb_t remainder_limb;
37:
38: sign_dividend = dividend->_mp_size;
39: dividend_size = ABS (dividend->_mp_size);
40:
41: if (dividend_size == 0)
42: {
43: quot->_mp_size = 0;
44: *rem_ptr = 0;
45: return;
46: }
47:
48: sign_divisor = divisor_short;
1.1.1.2 maekawa 49: divisor_limb = (unsigned short) ABS (divisor_short);
1.1 maekawa 50:
51: /* No need for temporary allocation and copying even if QUOT == DIVIDEND
52: as the divisor is just one limb, and thus no intermediate remainders
53: need to be stored. */
54:
55: if (quot->_mp_alloc < dividend_size)
56: _mp_realloc (quot, dividend_size);
57:
58: quot_ptr = quot->_mp_d;
59: dividend_ptr = dividend->_mp_d;
60:
61: remainder_limb = mpn_divmod_1 (quot_ptr,
62: dividend_ptr, dividend_size, divisor_limb);
63:
64: *rem_ptr = sign_dividend >= 0 ? remainder_limb : -remainder_limb;
65: /* The quotient is DIVIDEND_SIZE limbs, but the most significant
66: might be zero. Set QUOT_SIZE properly. */
67: quot_size = dividend_size - (quot_ptr[dividend_size - 1] == 0);
68: quot->_mp_size = (sign_divisor ^ sign_dividend) >= 0 ? quot_size : -quot_size;
69: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>