summaryrefslogtreecommitdiff
path: root/mpf
diff options
context:
space:
mode:
authorTorbjorn Granlund <tege@gmplib.org>2009-07-13 23:16:04 +0200
committerTorbjorn Granlund <tege@gmplib.org>2009-07-13 23:16:04 +0200
commitd15e944bb01dc43a6decabd81d3e7a0037969ad2 (patch)
treef708d67bbe19066cf5e92bb15ea35bf258b21457 /mpf
parentbc3956b4c933b381d978ff5b59c6c7c996a1e435 (diff)
downloadgmp-d15e944bb01dc43a6decabd81d3e7a0037969ad2.tar.gz
Simplify.
Diffstat (limited to 'mpf')
-rw-r--r--mpf/eq.c43
1 files changed, 24 insertions, 19 deletions
diff --git a/mpf/eq.c b/mpf/eq.c
index 3832c0b33..5f4d9b642 100644
--- a/mpf/eq.c
+++ b/mpf/eq.c
@@ -26,7 +26,7 @@ int
mpf_eq (mpf_srcptr u, mpf_srcptr v, unsigned long int n_bits)
{
mp_srcptr up, vp, p;
- mp_size_t usize, vsize, minsize, maxsize, n_limbs, i;
+ mp_size_t usize, vsize, minsize, maxsize, n_limbs, i, size;
mp_exp_t uexp, vexp;
mp_limb_t diff;
int cnt;
@@ -100,32 +100,37 @@ mpf_eq (mpf_srcptr u, mpf_srcptr v, unsigned long int n_bits)
return 0;
}
- if (minsize != maxsize)
+ n_bits -= (maxsize - 1) * GMP_NUMB_BITS;
+
+ size = maxsize - minsize;
+ if (size != 0)
{
if (up[0] != vp[0])
return 0;
- }
- /* Now either U or V has its limbs consumed. Check the the other operand
- has just zeros in the corresponding, relevant part. */
+ /* Now either U or V has its limbs consumed, i.e, continues with an
+ infinite number of implicit zero limbs. Check that the other operand
+ has just zeros in the corresponding, relevant part. */
- if (usize > vsize)
- p = up + minsize - maxsize;
- else
- p = vp + minsize - maxsize;
+ if (usize > vsize)
+ p = up - size;
+ else
+ p = vp - size;
- for (i = maxsize - minsize - 1; i > 0; i--)
- {
- if (p[i] != 0)
- return 0;
- }
+ for (i = size - 1; i > 0; i--)
+ {
+ if (p[i] != 0)
+ return 0;
+ }
- n_bits -= (maxsize - 1) * GMP_NUMB_BITS;
-
- if (minsize != maxsize)
- diff = p[0];
+ diff = p[0];
+ }
else
- diff = up[0] ^ vp[0];
+ {
+ /* Both U or V has its limbs consumed. */
+
+ diff = up[0] ^ vp[0];
+ }
if (n_bits < GMP_NUMB_BITS)
diff >>= GMP_NUMB_BITS - n_bits;