drm/i915: Use dev->pdev to get PCI device revisions
[dragonfly.git] / contrib / gmp / mpf / div_ui.c
blob2f4de1511e33588883cd7c5b43ce5b2524bcab14
1 /* mpf_div_ui -- Divide a float with an unsigned integer.
3 Copyright 1993, 1994, 1996, 2000, 2001, 2002, 2004, 2005 Free Software
4 Foundation, Inc.
6 This file is part of the GNU MP Library.
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 3 of the License, or (at your
11 option) any later version.
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.
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
21 #include "gmp.h"
22 #include "gmp-impl.h"
23 #include "longlong.h"
25 void
26 mpf_div_ui (mpf_ptr r, mpf_srcptr u, unsigned long int v)
28 mp_srcptr up;
29 mp_ptr rp, tp, rtp;
30 mp_size_t usize;
31 mp_size_t rsize, tsize;
32 mp_size_t sign_quotient;
33 mp_size_t prec;
34 mp_limb_t q_limb;
35 mp_exp_t rexp;
36 TMP_DECL;
38 #if BITS_PER_ULONG > GMP_NUMB_BITS /* avoid warnings about shift amount */
39 if (v > GMP_NUMB_MAX)
41 mpf_t vf;
42 mp_limb_t vl[2];
43 SIZ(vf) = 2;
44 EXP(vf) = 2;
45 PTR(vf) = vl;
46 vl[0] = v & GMP_NUMB_MASK;
47 vl[1] = v >> GMP_NUMB_BITS;
48 mpf_div (r, u, vf);
49 return;
51 #endif
53 usize = u->_mp_size;
54 sign_quotient = usize;
55 usize = ABS (usize);
56 prec = r->_mp_prec;
58 if (v == 0)
59 DIVIDE_BY_ZERO;
61 if (usize == 0)
63 r->_mp_size = 0;
64 r->_mp_exp = 0;
65 return;
68 TMP_MARK;
70 rp = r->_mp_d;
71 up = u->_mp_d;
73 tsize = 1 + prec;
74 tp = TMP_ALLOC_LIMBS (tsize + 1);
76 if (usize > tsize)
78 up += usize - tsize;
79 usize = tsize;
80 rtp = tp;
82 else
84 MPN_ZERO (tp, tsize - usize);
85 rtp = tp + (tsize - usize);
88 /* Move the dividend to the remainder. */
89 MPN_COPY (rtp, up, usize);
91 mpn_divmod_1 (rp, tp, tsize, (mp_limb_t) v);
92 q_limb = rp[tsize - 1];
94 rsize = tsize - (q_limb == 0);
95 rexp = u->_mp_exp - (q_limb == 0);
96 r->_mp_size = sign_quotient >= 0 ? rsize : -rsize;
97 r->_mp_exp = rexp;
98 TMP_FREE;