summaryrefslogtreecommitdiff
path: root/div_ui.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2005-05-04 15:59:49 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2005-05-04 15:59:49 +0000
commitefc83a3e7d839e2552b416d6a1518610628f6161 (patch)
tree4cc74a40bd446705bd33670cba300f14693f005e /div_ui.c
parent198ce68734b7210f478fc188acf7d74b53d33f95 (diff)
downloadmpfr-efc83a3e7d839e2552b416d6a1518610628f6161.tar.gz
Reformatted the code.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@3529 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'div_ui.c')
-rw-r--r--div_ui.c172
1 files changed, 86 insertions, 86 deletions
diff --git a/div_ui.c b/div_ui.c
index 5a7c89a52..2dc69692d 100644
--- a/div_ui.c
+++ b/div_ui.c
@@ -39,30 +39,30 @@ mpfr_div_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode)
if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x)))
{
if (MPFR_IS_NAN (x))
- {
- MPFR_SET_NAN (y);
- MPFR_RET_NAN;
- }
+ {
+ MPFR_SET_NAN (y);
+ MPFR_RET_NAN;
+ }
else if (MPFR_IS_INF (x))
- {
- MPFR_SET_INF (y);
- MPFR_SET_SAME_SIGN (y, x);
- MPFR_RET (0);
- }
+ {
+ MPFR_SET_INF (y);
+ MPFR_SET_SAME_SIGN (y, x);
+ MPFR_RET (0);
+ }
else
- {
+ {
MPFR_ASSERTD (MPFR_IS_ZERO(x));
- if (u == 0) /* 0/0 is NaN */
- {
- MPFR_SET_NAN(y);
- MPFR_RET_NAN;
- }
- else
- {
- MPFR_SET_ZERO(y);
- MPFR_RET(0);
- }
- }
+ if (u == 0) /* 0/0 is NaN */
+ {
+ MPFR_SET_NAN(y);
+ MPFR_RET_NAN;
+ }
+ else
+ {
+ MPFR_SET_ZERO(y);
+ MPFR_RET(0);
+ }
+ }
}
else if (MPFR_UNLIKELY (u == 0))
{
@@ -99,7 +99,7 @@ mpfr_div_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode)
inexact = (c != 0);
- /* First pass in estimating next bit of the quotient, in case of RNDN *
+ /* First pass in estimating next bit of the quotient, in case of RNDN *
* In case we just have the right number of bits (postpone this ?), *
* we need to check whether the remainder is more or less than half *
* the divisor. The test must be performed with a subtraction, so as *
@@ -107,65 +107,65 @@ mpfr_div_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode)
if (MPFR_LIKELY (rnd_mode == GMP_RNDN))
{
- if (c < (mp_limb_t) u - c) /* We have u > c */
- middle = -1;
+ if (c < (mp_limb_t) u - c) /* We have u > c */
+ middle = -1;
else if (c > (mp_limb_t) u - c)
- middle = 1;
+ middle = 1;
else
- middle = 0; /* exactly in the middle */
+ middle = 0; /* exactly in the middle */
}
- /* If we believe that we are right in the middle or exact, we should check
- that we did not neglect any word of x (division large / 1 -> small). */
+ /* If we believe that we are right in the middle or exact, we should check
+ that we did not neglect any word of x (division large / 1 -> small). */
for (i=0; ((inexact == 0) || (middle == 0)) && (i < -dif); i++)
if (xp[i])
inexact = middle = 1; /* larger than middle */
- /*
- If the high limb of the result is 0 (xp[xn-1] < u), remove it.
- Otherwise, compute the left shift to be performed to normalize.
- In the latter case, we discard some low bits computed. They
+ /*
+ If the high limb of the result is 0 (xp[xn-1] < u), remove it.
+ Otherwise, compute the left shift to be performed to normalize.
+ In the latter case, we discard some low bits computed. They
contain information useful for the rounding, hence the updating
- of middle and inexact.
- */
+ of middle and inexact.
+ */
- if (tmp[yn] == 0)
+ if (tmp[yn] == 0)
{
- MPN_COPY(yp, tmp, yn);
+ MPN_COPY(yp, tmp, yn);
exp -= BITS_PER_MP_LIMB;
- sh = 0;
+ sh = 0;
}
- else
+ else
{
count_leading_zeros (sh, tmp[yn]);
- /* shift left to normalize */
+ /* shift left to normalize */
if (MPFR_LIKELY (sh))
- {
- mp_limb_t w = tmp[0] << sh;
-
- mpn_lshift (yp, tmp + 1, yn, sh);
- yp[0] += tmp[0] >> (BITS_PER_MP_LIMB - sh);
-
- if (w > (MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - 1)))
- { middle = 1; }
- else if (w < (MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - 1)))
- { middle = -1; }
- else
- { middle = (c != 0); }
-
- inexact = inexact || (w != 0);
- exp -= sh;
- }
+ {
+ mp_limb_t w = tmp[0] << sh;
+
+ mpn_lshift (yp, tmp + 1, yn, sh);
+ yp[0] += tmp[0] >> (BITS_PER_MP_LIMB - sh);
+
+ if (w > (MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - 1)))
+ { middle = 1; }
+ else if (w < (MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - 1)))
+ { middle = -1; }
+ else
+ { middle = (c != 0); }
+
+ inexact = inexact || (w != 0);
+ exp -= sh;
+ }
else
- { /* this happens only if u == 1 and xp[xn-1] >=
- 1<<(BITS_PER_MP_LIMB-1). It might be better to handle the
- u == 1 case seperately ?
- */
+ { /* this happens only if u == 1 and xp[xn-1] >=
+ 1<<(BITS_PER_MP_LIMB-1). It might be better to handle the
+ u == 1 case seperately ?
+ */
- MPN_COPY (yp, tmp + 1, yn);
- }
+ MPN_COPY (yp, tmp + 1, yn);
+ }
}
MPFR_UNSIGNED_MINUS_MODULO (sh, MPFR_PREC (y));
@@ -187,41 +187,41 @@ mpfr_div_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode)
case GMP_RNDU:
if (MPFR_IS_POS(y))
- mpfr_add_one_ulp (y, rnd_mode);
+ mpfr_add_one_ulp (y, rnd_mode);
MPFR_RET(1); /* result is inexact */
case GMP_RNDD:
if (MPFR_IS_NEG(y))
- mpfr_add_one_ulp (y, rnd_mode);
+ mpfr_add_one_ulp (y, rnd_mode);
MPFR_RET(-1); /* result is inexact */
default:
MPFR_ASSERTD(rnd_mode == GMP_RNDN);
- /* we have one more significant bit in yn */
- if (sh && d < (MPFR_LIMB_ONE << (sh - 1)))
- MPFR_RET(-MPFR_INT_SIGN(x));
+ /* we have one more significant bit in yn */
+ if (sh && d < (MPFR_LIMB_ONE << (sh - 1)))
+ MPFR_RET(-MPFR_INT_SIGN(x));
else if (sh && d > (MPFR_LIMB_ONE << (sh - 1)))
- {
- mpfr_add_one_ulp (y, rnd_mode);
- MPFR_RET(MPFR_INT_SIGN(x));
- }
+ {
+ mpfr_add_one_ulp (y, rnd_mode);
+ MPFR_RET(MPFR_INT_SIGN(x));
+ }
else /* sh = 0 or d = 1 << (sh-1) */
- {
- /* The first case is "false" even rounding (significant bits
- indicate even rounding, but the result is inexact, so up) ;
- The second case is the case where middle should be used to
- decide the direction of rounding (no further bit computed) ;
- The third is the true even rounding.
- */
- if ((sh && inexact) || (!sh && (middle > 0)) ||
- (!inexact && *yp & (MPFR_LIMB_ONE << sh)))
- {
- mpfr_add_one_ulp (y, rnd_mode);
- MPFR_RET(MPFR_INT_SIGN(x));
- }
- else
- MPFR_RET(-MPFR_INT_SIGN(x));
- }
+ {
+ /* The first case is "false" even rounding (significant bits
+ indicate even rounding, but the result is inexact, so up) ;
+ The second case is the case where middle should be used to
+ decide the direction of rounding (no further bit computed) ;
+ The third is the true even rounding.
+ */
+ if ((sh && inexact) || (!sh && (middle > 0)) ||
+ (!inexact && *yp & (MPFR_LIMB_ONE << sh)))
+ {
+ mpfr_add_one_ulp (y, rnd_mode);
+ MPFR_RET(MPFR_INT_SIGN(x));
+ }
+ else
+ MPFR_RET(-MPFR_INT_SIGN(x));
+ }
}
return 0; /* To avoid warning*/
}