summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2002-04-19 12:26:06 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2002-04-19 12:26:06 +0000
commit01a47f270cbdb4460adcee4d119bca071917e441 (patch)
tree40f9bf4f3a15ff0c4f1941981d30486beb0eb16a
parent73a7c65e1ebdfa0010e59ede641b50aa125483d7 (diff)
downloadmpfr-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.c1
-rw-r--r--div_ui.c1
-rw-r--r--mul_ui.c1
-rw-r--r--set_si.c1
-rw-r--r--set_ui.c1
-rw-r--r--sqrt_ui.c1
-rw-r--r--sub_ui.c1
-rw-r--r--ui_div.c1
-rw-r--r--ui_sub.c19
9 files changed, 18 insertions, 9 deletions
diff --git a/add_ui.c b/add_ui.c
index a5da63b8c..88de72071 100644
--- a/add_ui.c
+++ b/add_ui.c
@@ -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;
diff --git a/div_ui.c b/div_ui.c
index 0979ff75d..edb54803c 100644
--- a/div_ui.c
+++ b/div_ui.c
@@ -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 */
diff --git a/mul_ui.c b/mul_ui.c
index 2527ae215..7bceedd21 100644
--- a/mul_ui.c
+++ b/mul_ui.c
@@ -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] */
diff --git a/set_si.c b/set_si.c
index 89bae07b8..c3a2c94fb 100644
--- a/set_si.c
+++ b/set_si.c
@@ -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);
diff --git a/set_ui.c b/set_ui.c
index 1f225425c..4083fa9c6 100644
--- a/set_ui.c
+++ b/set_ui.c
@@ -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);
diff --git a/sqrt_ui.c b/sqrt_ui.c
index 46eff9f81..92c11b053 100644
--- a/sqrt_ui.c
+++ b/sqrt_ui.c
@@ -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;
diff --git a/sub_ui.c b/sub_ui.c
index 55c69f3d8..541c4af6b 100644
--- a/sub_ui.c
+++ b/sub_ui.c
@@ -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;
diff --git a/ui_div.c b/ui_div.c
index d0e8b15ef..c47c8ab93 100644
--- a/ui_div.c
+++ b/ui_div.c
@@ -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;
diff --git a/ui_sub.c b/ui_sub.c
index 5cc94df76..10f356d8d 100644
--- a/ui_sub.c
+++ b/ui_sub.c
@@ -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 */
}