1 /* mpfr_ui_div -- divide a machine integer by a floating-point number
2 mpfr_si_div -- divide a machine number by a floating-point number
4 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
5 Contributed by the Arenaire and Caramel projects, INRIA.
7 This file is part of the GNU MPFR Library.
9 The GNU MPFR Library is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
14 The GNU MPFR Library is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
21 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
22 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
25 #define MPFR_NEED_LONGLONG_H
26 #include "mpfr-impl.h"
29 mpfr_ui_div (mpfr_ptr y, unsigned long int u, mpfr_srcptr x, mpfr_rnd_t rnd_mode)
36 (("u=%lu x[%Pu]=%.*Rg rnd=%d",
37 u, mpfr_get_prec(x), mpfr_log_prec, x, rnd_mode),
38 ("y[%Pu]=%.*Rg", mpfr_get_prec(y), mpfr_log_prec, y));
40 if (MPFR_UNLIKELY(MPFR_IS_SINGULAR(x)))
47 else if (MPFR_IS_INF(x)) /* u/Inf = 0 */
50 MPFR_SET_SAME_SIGN(y,x);
55 MPFR_ASSERTD(MPFR_IS_ZERO(x));
58 /* u > 0, so y = sign(x) * Inf */
59 MPFR_SET_SAME_SIGN(y, x);
72 else if (MPFR_LIKELY(u != 0))
74 MPFR_TMP_INIT1(up, uu, GMP_NUMB_BITS);
75 MPFR_ASSERTN(u == (mp_limb_t) u);
76 count_leading_zeros(cnt, (mp_limb_t) u);
77 up[0] = (mp_limb_t) u << cnt;
78 MPFR_SET_EXP (uu, GMP_NUMB_BITS - cnt);
79 return mpfr_div (y, uu, x, rnd_mode);
81 else /* u = 0, and x != 0 */
83 MPFR_SET_ZERO(y); /* if u=0, then set y to 0 */
84 MPFR_SET_SAME_SIGN(y, x); /* u considered as +0: sign(+0/x) = sign(x) */
91 mpfr_si_div (mpfr_ptr y, long int u, mpfr_srcptr x, mpfr_rnd_t rnd_mode)
96 res = mpfr_ui_div (y, u, x, rnd_mode);
99 res = -mpfr_ui_div (y, -u, x, MPFR_INVERT_RND(rnd_mode));
100 MPFR_CHANGE_SIGN (y);