1 /* mpf_eq -- Compare two floats up to a specified bit #.
3 Copyright 1993, 1995, 1996, 2001, 2002, 2008 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
25 mpf_eq (mpf_srcptr u, mpf_srcptr v, unsigned long int n_bits)
28 mp_size_t usize, vsize, size, i;
39 /* 1. Are the signs different? */
40 if ((usize ^ vsize) >= 0)
42 /* U and V are both non-negative or both negative. */
52 /* Either U or V is negative, but not both. */
56 /* U and V have the same sign and are both non-zero. */
58 /* 2. Are the exponents different? */
68 /* Ignore zeroes at the low end of U and V. */
82 if (vsize * GMP_NUMB_BITS < n_bits)
83 return 0; /* surely too different */
86 else if (vsize > usize)
88 if (usize * GMP_NUMB_BITS < n_bits)
89 return 0; /* surely too different */
97 up += usize; /* point just above most significant limb */
98 vp += vsize; /* point just above most significant limb */
100 count_leading_zeros (cnt, up[-1]);
101 if ((vp[-1] >> (GMP_LIMB_BITS - 1 - cnt)) != 1)
102 return 0; /* msb positions different */
104 n_bits += cnt - GMP_NAIL_BITS;
106 size = MIN (size, (n_bits + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS);
108 up -= size; /* point at least significant relevant limb */
109 vp -= size; /* point at least significant relevant limb */
111 for (i = size - 1; i > 0; i--)
117 diff = (up[0] ^ vp[0]) >> (GMP_NUMB_BITS - 1 - (n_bits - 1) % GMP_NUMB_BITS);