summaryrefslogtreecommitdiff
path: root/mpf/eq.c
diff options
context:
space:
mode:
authorTorbjorn Granlund <tege@gmplib.org>2008-11-08 22:03:41 +0100
committerTorbjorn Granlund <tege@gmplib.org>2008-11-08 22:03:41 +0100
commit033b9934c2d240e6907c7e3b60185460200e58e6 (patch)
treeb8ed9003617b93fa244f67b701d53d65c88fc47a /mpf/eq.c
parent812fed15ca7a809c80b8a9f1805612da2653203e (diff)
downloadgmp-033b9934c2d240e6907c7e3b60185460200e58e6.tar.gz
Compare limb[0] just up to the specified bit.
Diffstat (limited to 'mpf/eq.c')
-rw-r--r--mpf/eq.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/mpf/eq.c b/mpf/eq.c
index e10daf28b..4de142c98 100644
--- a/mpf/eq.c
+++ b/mpf/eq.c
@@ -1,6 +1,6 @@
/* mpf_eq -- Compare two floats up to a specified bit #.
-Copyright 1993, 1995, 1996, 2001, 2002 Free Software Foundation, Inc.
+Copyright 1993, 1995, 1996, 2001, 2002, 2008 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -26,6 +26,7 @@ mpf_eq (mpf_srcptr u, mpf_srcptr v, unsigned long int n_bits)
mp_srcptr up, vp;
mp_size_t usize, vsize, size, i;
mp_exp_t uexp, vexp;
+ mp_limb_t diff;
uexp = u->_mp_exp;
vexp = v->_mp_exp;
@@ -99,11 +100,12 @@ mpf_eq (mpf_srcptr u, mpf_srcptr v, unsigned long int 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;
+ diff = (up[0] ^ vp[0]) >> GMP_NUMB_BITS - 1 - (n_bits - 1) % GMP_NUMB_BITS;
+ return diff == 0;
}