1 /* mpf_div_ui -- Divide a float with an unsigned integer.
3 Copyright 1993, 1994, 1996, 2000, 2001, 2002, 2004, 2005 Free Software
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/. */
26 mpf_div_ui (mpf_ptr r
, mpf_srcptr u
, unsigned long int v
)
31 mp_size_t rsize
, tsize
;
32 mp_size_t sign_quotient
;
38 #if BITS_PER_ULONG > GMP_NUMB_BITS /* avoid warnings about shift amount */
46 vl
[0] = v
& GMP_NUMB_MASK
;
47 vl
[1] = v
>> GMP_NUMB_BITS
;
54 sign_quotient
= usize
;
74 tp
= TMP_ALLOC_LIMBS (tsize
+ 1);
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
;