diff options
Diffstat (limited to 'round_raw_generic.c')
-rw-r--r-- | round_raw_generic.c | 196 |
1 files changed, 98 insertions, 98 deletions
diff --git a/round_raw_generic.c b/round_raw_generic.c index d46c35445..6408506fc 100644 --- a/round_raw_generic.c +++ b/round_raw_generic.c @@ -53,14 +53,14 @@ MA 02110-1301, USA. */ int mpfr_round_raw_generic( #if flag == 0 - mp_limb_t *yp, + mp_limb_t *yp, #endif - const mp_limb_t *xp, mp_prec_t xprec, + const mp_limb_t *xp, mp_prec_t xprec, int neg, mp_prec_t yprec, mp_rnd_t rnd_mode #if use_inexp != 0 - , int *inexp + , int *inexp #endif - ) + ) { mp_size_t xsize, nw; mp_limb_t himask, lomask, sb; @@ -88,7 +88,7 @@ mpfr_round_raw_generic( { /* No rounding is necessary. */ /* if yp=xp, maybe an overlap: MPN_COPY_DECR is ok when src <= dst */ if (MPFR_LIKELY(rw)) - nw++; + nw++; MPFR_ASSERTD(nw >= 1); MPFR_ASSERTD(nw >= xsize); if (use_inexp) @@ -105,134 +105,134 @@ mpfr_round_raw_generic( mp_size_t k = xsize - nw - 1; if (MPFR_LIKELY(rw)) - { - nw++; - lomask = MPFR_LIMB_MASK (BITS_PER_MP_LIMB - rw); - himask = ~lomask; - } + { + nw++; + lomask = MPFR_LIMB_MASK (BITS_PER_MP_LIMB - rw); + himask = ~lomask; + } else - { - lomask = ~(mp_limb_t) 0; - himask = ~(mp_limb_t) 0; - } + { + lomask = ~(mp_limb_t) 0; + himask = ~(mp_limb_t) 0; + } MPFR_ASSERTD(k >= 0); sb = xp[k] & lomask; /* First non-significant bits */ /* Rounding to nearest ? */ if (MPFR_LIKELY( rnd_mode == GMP_RNDN) ) - { - /* Rounding to nearest */ - mp_limb_t rbmask = MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - 1 - rw); - if (sb & rbmask) /* rounding bit */ - sb &= ~rbmask; /* it is 1, clear it */ - else - { - /* Rounding bit is 0, behave like rounding to 0 */ - goto rnd_RNDZ; - } - while (MPFR_UNLIKELY(sb == 0) && k > 0) - sb = xp[--k]; - /* rounding to nearest, with rounding bit = 1 */ - if (MPFR_UNLIKELY(sb == 0)) /* Even rounding. */ - { - /* sb == 0 && rnd_mode == GMP_RNDN */ - sb = xp[xsize - nw] & (himask ^ (himask << 1)); - if (sb == 0) - { - if (use_inexp) - *inexp = 2*MPFR_EVEN_INEX*neg-MPFR_EVEN_INEX; - /* ((neg!=0)^(sb!=0)) ? MPFR_EVEN_INEX : -MPFR_EVEN_INEX;*/ - /* Since neg = 0 or 1 and sb=0*/ + { + /* Rounding to nearest */ + mp_limb_t rbmask = MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - 1 - rw); + if (sb & rbmask) /* rounding bit */ + sb &= ~rbmask; /* it is 1, clear it */ + else + { + /* Rounding bit is 0, behave like rounding to 0 */ + goto rnd_RNDZ; + } + while (MPFR_UNLIKELY(sb == 0) && k > 0) + sb = xp[--k]; + /* rounding to nearest, with rounding bit = 1 */ + if (MPFR_UNLIKELY(sb == 0)) /* Even rounding. */ + { + /* sb == 0 && rnd_mode == GMP_RNDN */ + sb = xp[xsize - nw] & (himask ^ (himask << 1)); + if (sb == 0) + { + if (use_inexp) + *inexp = 2*MPFR_EVEN_INEX*neg-MPFR_EVEN_INEX; + /* ((neg!=0)^(sb!=0)) ? MPFR_EVEN_INEX : -MPFR_EVEN_INEX;*/ + /* Since neg = 0 or 1 and sb=0*/ #if flag == 1 - return 0 /*sb != 0 && rnd_mode != GMP_RNDZ */; + return 0 /*sb != 0 && rnd_mode != GMP_RNDZ */; #else - MPN_COPY_INCR(yp, xp + xsize - nw, nw); - yp[0] &= himask; - return 0; + MPN_COPY_INCR(yp, xp + xsize - nw, nw); + yp[0] &= himask; + return 0; #endif - } - else - { - /* sb != 0 && rnd_mode == GMP_RNDN */ + } + else + { + /* sb != 0 && rnd_mode == GMP_RNDN */ if (use_inexp) *inexp = MPFR_EVEN_INEX-2*MPFR_EVEN_INEX*neg; - /*((neg!=0)^(sb!=0))? MPFR_EVEN_INEX : -MPFR_EVEN_INEX; */ - /*Since neg= 0 or 1 and sb != 0 */ - goto rnd_RNDN_add_one_ulp; - } - } - else /* sb != 0 && rnd_mode == GMP_RNDN*/ - { - if (use_inexp) - /* *inexp = (neg == 0) ? 1 : -1; but since neg = 0 or 1 */ - *inexp = 1-2*neg; - rnd_RNDN_add_one_ulp: + /*((neg!=0)^(sb!=0))? MPFR_EVEN_INEX : -MPFR_EVEN_INEX; */ + /*Since neg= 0 or 1 and sb != 0 */ + goto rnd_RNDN_add_one_ulp; + } + } + else /* sb != 0 && rnd_mode == GMP_RNDN*/ + { + if (use_inexp) + /* *inexp = (neg == 0) ? 1 : -1; but since neg = 0 or 1 */ + *inexp = 1-2*neg; + rnd_RNDN_add_one_ulp: #if flag == 1 - return 1; /*sb != 0 && rnd_mode != GMP_RNDZ;*/ + return 1; /*sb != 0 && rnd_mode != GMP_RNDZ;*/ #else - carry = mpn_add_1 (yp, xp + xsize - nw, nw, + carry = mpn_add_1 (yp, xp + xsize - nw, nw, rw ? MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - rw) : MPFR_LIMB_ONE); - yp[0] &= himask; - return carry; + yp[0] &= himask; + return carry; #endif - } - } + } + } /* Rounding to Zero ? */ else if (MPFR_IS_LIKE_RNDZ(rnd_mode, neg)) - { - /* rnd_mode == GMP_RNDZ */ - rnd_RNDZ: - while (MPFR_UNLIKELY(sb == 0) && k > 0) - sb = xp[--k]; - if (use_inexp) - /* rnd_mode == GMP_RNDZ and neg = 0 or 1 */ - /* (neg != 0) ^ (rnd_mode != GMP_RNDZ)) ? 1 : -1);*/ - *inexp = MPFR_UNLIKELY(sb == 0) ? 0 : (2*neg-1); + { + /* rnd_mode == GMP_RNDZ */ + rnd_RNDZ: + while (MPFR_UNLIKELY(sb == 0) && k > 0) + sb = xp[--k]; + if (use_inexp) + /* rnd_mode == GMP_RNDZ and neg = 0 or 1 */ + /* (neg != 0) ^ (rnd_mode != GMP_RNDZ)) ? 1 : -1);*/ + *inexp = MPFR_UNLIKELY(sb == 0) ? 0 : (2*neg-1); #if flag == 1 - return 0; /*sb != 0 && rnd_mode != GMP_RNDZ;*/ + return 0; /*sb != 0 && rnd_mode != GMP_RNDZ;*/ #else - MPN_COPY_INCR(yp, xp + xsize - nw, nw); - yp[0] &= himask; - return 0; + MPN_COPY_INCR(yp, xp + xsize - nw, nw); + yp[0] &= himask; + return 0; #endif - } + } else - { - /* rnd_mode = Away */ + { + /* rnd_mode = Away */ while (MPFR_UNLIKELY(sb == 0) && k > 0) sb = xp[--k]; - if (MPFR_UNLIKELY(sb == 0)) - { - /* sb = 0 && rnd_mode != GMP_RNDZ */ - if (use_inexp) - /* (neg != 0) ^ (rnd_mode != GMP_RNDZ)) ? 1 : -1);*/ - *inexp = 0; + if (MPFR_UNLIKELY(sb == 0)) + { + /* sb = 0 && rnd_mode != GMP_RNDZ */ + if (use_inexp) + /* (neg != 0) ^ (rnd_mode != GMP_RNDZ)) ? 1 : -1);*/ + *inexp = 0; #if flag == 1 - return 0; + return 0; #else - MPN_COPY_INCR(yp, xp + xsize - nw, nw); - yp[0] &= himask; - return 0; + MPN_COPY_INCR(yp, xp + xsize - nw, nw); + yp[0] &= himask; + return 0; #endif - } - else - { + } + else + { /* sb != 0 && rnd_mode != GMP_RNDZ */ if (use_inexp) /* (neg != 0) ^ (rnd_mode != GMP_RNDZ)) ? 1 : -1);*/ *inexp = 1-2*neg; #if flag == 1 - return 1; + return 1; #else - carry = mpn_add_1(yp, xp + xsize - nw, nw, - rw ? MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - rw) - : 1); + carry = mpn_add_1(yp, xp + xsize - nw, nw, + rw ? MPFR_LIMB_ONE << (BITS_PER_MP_LIMB - rw) + : 1); yp[0] &= himask; return carry; #endif - } - } + } + } } else { @@ -246,7 +246,7 @@ mpfr_round_raw_generic( himask = ~MPFR_LIMB_MASK (BITS_PER_MP_LIMB - rw); } else - himask = ~(mp_limb_t) 0; + himask = ~(mp_limb_t) 0; MPN_COPY_INCR(yp, xp + xsize - nw, nw); yp[0] &= himask; return 0; |