summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mpf/eq.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/mpf/eq.c b/mpf/eq.c
index 4de142c98..432ae9483 100644
--- a/mpf/eq.c
+++ b/mpf/eq.c
@@ -19,6 +19,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include "gmp.h"
#include "gmp-impl.h"
+#include "longlong.h"
int
mpf_eq (mpf_srcptr u, mpf_srcptr v, unsigned long int n_bits)
@@ -27,6 +28,7 @@ mpf_eq (mpf_srcptr u, mpf_srcptr v, unsigned long int n_bits)
mp_size_t usize, vsize, size, i;
mp_exp_t uexp, vexp;
mp_limb_t diff;
+ int cnt;
uexp = u->_mp_exp;
vexp = v->_mp_exp;
@@ -54,10 +56,8 @@ mpf_eq (mpf_srcptr u, mpf_srcptr v, unsigned long int n_bits)
/* U and V have the same sign and are both non-zero. */
/* 2. Are the exponents different? */
- if (uexp > vexp)
- return 0; /* ??? handle (uexp = vexp + 1) */
- if (vexp > uexp)
- return 0; /* ??? handle (vexp = uexp + 1) */
+ if (uexp != vexp)
+ return 0;
usize = ABS (usize);
vsize = ABS (vsize);
@@ -94,11 +94,19 @@ mpf_eq (mpf_srcptr u, mpf_srcptr v, unsigned long int n_bits)
size = usize;
}
- if (size > (n_bits + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS)
- size = (n_bits + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS;
+ up += usize; /* point just above most significant limb */
+ vp += vsize; /* point just above most significant limb */
- up += usize - size;
- vp += vsize - size;
+ count_leading_zeros (cnt, up[-1]);
+ if ((vp[-1] >> (GMP_LIMB_BITS - 1 - cnt)) != 1)
+ return 0; /* msb positions different */
+
+ n_bits += cnt - GMP_NAIL_BITS;
+
+ size = MIN (size, (n_bits + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS);
+
+ up -= size; /* point at least significant relevant limb */
+ vp -= size; /* point at least significant relevant limb */
for (i = size - 1; i > 0; i--)
{