diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2002-04-19 12:26:06 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2002-04-19 12:26:06 +0000 |
commit | 01a47f270cbdb4460adcee4d119bca071917e441 (patch) | |
tree | 40f9bf4f3a15ff0c4f1941981d30486beb0eb16a | |
parent | 73a7c65e1ebdfa0010e59ede641b50aa125483d7 (diff) | |
download | mpfr-01a47f270cbdb4460adcee4d119bca071917e441.tar.gz |
Added some assertions (any unsigned long must be representable
in a mp_limb_t).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1900 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | add_ui.c | 1 | ||||
-rw-r--r-- | div_ui.c | 1 | ||||
-rw-r--r-- | mul_ui.c | 1 | ||||
-rw-r--r-- | set_si.c | 1 | ||||
-rw-r--r-- | set_ui.c | 1 | ||||
-rw-r--r-- | sqrt_ui.c | 1 | ||||
-rw-r--r-- | sub_ui.c | 1 | ||||
-rw-r--r-- | ui_div.c | 1 | ||||
-rw-r--r-- | ui_sub.c | 19 |
9 files changed, 18 insertions, 9 deletions
@@ -37,6 +37,7 @@ mpfr_add_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode) int inex; MPFR_INIT1(up, uu, BITS_PER_MP_LIMB, 1); + MPFR_ASSERTN(u == (mp_limb_t) u); count_leading_zeros(cnt, (mp_limb_t) u); *up = (mp_limb_t) u << cnt; MPFR_EXP(uu) = BITS_PER_MP_LIMB - cnt; @@ -89,6 +89,7 @@ mpfr_div_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode) tmp = TMP_ALLOC((yn + 1) * BYTES_PER_MP_LIMB); c = (mp_limb_t) u; + MPFR_ASSERTN(u == c); if (dif >= 0) c = mpn_divrem_1 (tmp, dif, xp, xn, c); /* used all the dividend */ else /* dif < 0 i.e. xn > yn, don't use the (-dif) low limbs from x */ @@ -78,6 +78,7 @@ mpfr_mul_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode) if (yn < xn + 1) yp = (mp_ptr) TMP_ALLOC ((size_t) (xn + 1) * BYTES_PER_MP_LIMB); + MPFR_ASSERTN(u == (mp_limb_t) u); yp[xn] = mpn_mul_1 (yp, MPFR_MANT(x), xn, u); /* x * u is stored in yp[xn], ..., yp[0] */ @@ -43,6 +43,7 @@ mpfr_set_si (mpfr_ptr x, long i, mp_rnd_t rnd_mode) xn = (MPFR_PREC(x)-1)/BITS_PER_MP_LIMB; ai = SAFE_ABS(unsigned long, i); + MPFR_ASSERTN(SAFE_ABS(unsigned long, i) == ai); count_leading_zeros(cnt, ai); xp = MPFR_MANT(x); @@ -40,6 +40,7 @@ mpfr_set_ui (mpfr_ptr x, unsigned long i, mp_rnd_t rnd_mode) mp_limb_t *xp; xn = (MPFR_PREC(x)-1)/BITS_PER_MP_LIMB; + MPFR_ASSERTN(i == (mp_limb_t) i); count_leading_zeros(cnt, (mp_limb_t) i); xp = MPFR_MANT(x); @@ -36,6 +36,7 @@ mpfr_sqrt_ui (mpfr_ptr r, unsigned long u, mp_rnd_t rnd_mode) int inex; MPFR_INIT1(up, uu, BITS_PER_MP_LIMB, 1); + MPFR_ASSERTN(u == (mp_limb_t) u); count_leading_zeros (cnt, (mp_limb_t) u); *up = (mp_limb_t) u << cnt; MPFR_EXP(uu) = BITS_PER_MP_LIMB - cnt; @@ -36,6 +36,7 @@ mpfr_sub_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode) int inex; MPFR_INIT1(up, uu, BITS_PER_MP_LIMB, 1); + MPFR_ASSERTN(u == (mp_limb_t) u); count_leading_zeros(cnt, (mp_limb_t) u); *up = (mp_limb_t) u << cnt; MPFR_EXP(uu) = BITS_PER_MP_LIMB - cnt; @@ -55,6 +55,7 @@ mpfr_ui_div (mpfr_ptr y, unsigned long int u, mpfr_srcptr x, mp_rnd_t rnd_mode) if (u) { MPFR_INIT1(up, uu, BITS_PER_MP_LIMB, 1); + MPFR_ASSERTN(u == (mp_limb_t) u); count_leading_zeros(cnt, (mp_limb_t) u); *up = (mp_limb_t) u << cnt; MPFR_EXP(uu) = BITS_PER_MP_LIMB-cnt; @@ -32,7 +32,7 @@ mpfr_ui_sub (mpfr_ptr y, unsigned long int u, mpfr_srcptr x, mp_rnd_t rnd_mode) mp_limb_t up[1]; unsigned long cnt; - if (MPFR_IS_NAN(x)) + if (MPFR_IS_NAN(x)) { MPFR_SET_NAN(y); MPFR_RET_NAN; @@ -48,14 +48,15 @@ mpfr_ui_sub (mpfr_ptr y, unsigned long int u, mpfr_srcptr x, mp_rnd_t rnd_mode) MPFR_RET(0); /* +/-infinity is exact */ } - if (u) { - MPFR_INIT1 (up, uu, BITS_PER_MP_LIMB, 1); - count_leading_zeros (cnt, (mp_limb_t) u); - *up = (mp_limb_t) u << cnt; - MPFR_EXP(uu) = BITS_PER_MP_LIMB - cnt; - - return mpfr_sub (y, uu, x, rnd_mode); - } + if (u) + { + MPFR_INIT1 (up, uu, BITS_PER_MP_LIMB, 1); + MPFR_ASSERTN(u == (mp_limb_t) u); + count_leading_zeros (cnt, (mp_limb_t) u); + *up = (mp_limb_t) u << cnt; + MPFR_EXP(uu) = BITS_PER_MP_LIMB - cnt; + return mpfr_sub (y, uu, x, rnd_mode); + } else return mpfr_neg (y, x, rnd_mode); /* if u=0, then set y to -x */ } |