summaryrefslogtreecommitdiff
path: root/eq.c
diff options
context:
space:
mode:
authorhanrot <hanrot@280ebfd0-de03-0410-8827-d642c229c3f4>2000-06-15 08:11:54 +0000
committerhanrot <hanrot@280ebfd0-de03-0410-8827-d642c229c3f4>2000-06-15 08:11:54 +0000
commite1053102a747b37580bebeb9036051512463075c (patch)
treee8e9e410c9ea9ea85c461da03227c479599539c9 /eq.c
parent13b67119467d43eac919a254799d42b2ea05ff7f (diff)
downloadmpfr-e1053102a747b37580bebeb9036051512463075c.tar.gz
Patch a few incoherences of eq.c wrt the manual + adapt to mpfr usual semantics
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@605 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'eq.c')
-rw-r--r--eq.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/eq.c b/eq.c
index 55fb2e8c7..b80deafdb 100644
--- a/eq.c
+++ b/eq.c
@@ -39,22 +39,22 @@ mpfr_eq (u, v, n_bits)
mp_srcptr up, vp;
mp_size_t usize, vsize, size, i;
mp_exp_t uexp, vexp;
- int usign;
+ int usign, k;
uexp = u->_mp_exp;
vexp = v->_mp_exp;
- usize = u->_mp_size;
- vsize = v->_mp_size;
+ usize = (PREC(u)-1)/BITS_PER_MP_LIMB + 1;
+ vsize = (PREC(v)-1)/BITS_PER_MP_LIMB + 1;
/* 1. Are the signs different? */
- if ((usize ^ vsize) >= 0)
+ if (MPFR_SIGN(u) == MPFR_SIGN(v))
{
/* U and V are both non-negative or both negative. */
- if (usize == 0)
- return vsize == 0;
- if (vsize == 0)
- return 0;
+ if (!NOTZERO(u))
+ return !NOTZERO(v);
+ if (!NOTZERO(v))
+ return !NOTZERO(u);
/* Fall out. */
}
@@ -66,7 +66,7 @@ mpfr_eq (u, v, n_bits)
/* U and V have the same sign and are both non-zero. */
- usign = usize >= 0 ? 1 : -1;
+ usign = MPFR_SIGN(u);
/* 2. Are the exponents different? */
if (uexp > vexp)
@@ -80,28 +80,26 @@ mpfr_eq (u, v, n_bits)
up = u->_mp_d;
vp = v->_mp_d;
- /* Ignore zeroes at the low end of U and V. */
- while (up[0] == 0)
- {
- up++;
- usize--;
- }
- while (vp[0] == 0)
- {
- vp++;
- vsize--;
- }
-
if (usize > vsize)
{
if (vsize * BITS_PER_MP_LIMB < n_bits)
- return 0; /* surely too different */
+ {
+ k = usize - vsize - 1;
+ while (k >= 0 && !up[k]) --k;
+ if (k >= 0)
+ return 0; /* surely too different */
+ }
size = vsize;
}
else if (vsize > usize)
{
if (usize * BITS_PER_MP_LIMB < n_bits)
- return 0; /* surely too different */
+ {
+ k = vsize - usize - 1;
+ while (k >= 0 && !vp[k]) --k;
+ if (k >= 0)
+ return 0; /* surely too different */
+ }
size = usize;
}
else
@@ -115,11 +113,13 @@ mpfr_eq (u, v, n_bits)
up += usize - size;
vp += vsize - size;
- for (i = size - 1; i >= 0; i--)
+ for (i = size - 1; i > 0; i--)
{
if (up[i] != vp[i])
return 0;
}
- return 1;
+ return (up[i] >> (BITS_PER_MP_LIMB - (n_bits & (BITS_PER_MP_LIMB - 1))) ==
+ vp[i] >> (BITS_PER_MP_LIMB - (n_bits & (BITS_PER_MP_LIMB - 1))));
+
}