1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/patches/gmp/4.2.4/100-mpf_eq.patch Wed Aug 11 21:39:04 2010 +0200
1.3 @@ -0,0 +1,219 @@
1.4 +Original patch from: mpf_eq.diff
1.5 +
1.6 +-= BEGIN original header =-
1.7 +-= END original header =-
1.8 +
1.9 +diff -durN gmp-4.2.4.orig/doc/gmp.texi gmp-4.2.4/doc/gmp.texi
1.10 +--- gmp-4.2.4.orig/doc/gmp.texi 2008-09-18 17:36:14.000000000 +0200
1.11 ++++ gmp-4.2.4/doc/gmp.texi 2009-03-08 18:36:16.000000000 +0100
1.12 +@@ -4849,9 +4849,12 @@
1.13 + equal, zero otherwise. I.e., test if @var{op1} and @var{op2} are approximately
1.14 + equal.
1.15 +
1.16 +-Caution: Currently only whole limbs are compared, and only in an exact
1.17 +-fashion. In the future values like 1000 and 0111 may be considered the same
1.18 +-to 3 bits (on the basis that their difference is that small).
1.19 ++Caution 1: All version of GMP up to version 4.2.4 compared just whole limbs,
1.20 ++meaning sometimes more than @var{op3} bits, sometimes fewer.
1.21 ++
1.22 ++Caution 2: This function will consider XXX11...111 and XX100...000 different,
1.23 ++even if ... is replaced by a semi-infinite number of bits. Such numbers are
1.24 ++really just one ulp off, and should be considered equal.
1.25 + @end deftypefun
1.26 +
1.27 + @deftypefun void mpf_reldiff (mpf_t @var{rop}, mpf_t @var{op1}, mpf_t @var{op2})
1.28 +diff -durN gmp-4.2.4.orig/mpf/eq.c gmp-4.2.4/mpf/eq.c
1.29 +--- gmp-4.2.4.orig/mpf/eq.c 2007-08-30 20:31:40.000000000 +0200
1.30 ++++ gmp-4.2.4/mpf/eq.c 2009-03-08 18:36:16.000000000 +0100
1.31 +@@ -1,6 +1,6 @@
1.32 + /* mpf_eq -- Compare two floats up to a specified bit #.
1.33 +
1.34 +-Copyright 1993, 1995, 1996, 2001, 2002 Free Software Foundation, Inc.
1.35 ++Copyright 1993, 1995, 1996, 2001, 2002, 2008 Free Software Foundation, Inc.
1.36 +
1.37 + This file is part of the GNU MP Library.
1.38 +
1.39 +@@ -19,6 +19,7 @@
1.40 +
1.41 + #include "gmp.h"
1.42 + #include "gmp-impl.h"
1.43 ++#include "longlong.h"
1.44 +
1.45 + int
1.46 + mpf_eq (mpf_srcptr u, mpf_srcptr v, unsigned long int n_bits)
1.47 +@@ -26,6 +27,8 @@
1.48 + mp_srcptr up, vp;
1.49 + mp_size_t usize, vsize, size, i;
1.50 + mp_exp_t uexp, vexp;
1.51 ++ mp_limb_t diff;
1.52 ++ int cnt;
1.53 +
1.54 + uexp = u->_mp_exp;
1.55 + vexp = v->_mp_exp;
1.56 +@@ -53,10 +56,8 @@
1.57 + /* U and V have the same sign and are both non-zero. */
1.58 +
1.59 + /* 2. Are the exponents different? */
1.60 +- if (uexp > vexp)
1.61 +- return 0; /* ??? handle (uexp = vexp + 1) */
1.62 +- if (vexp > uexp)
1.63 +- return 0; /* ??? handle (vexp = uexp + 1) */
1.64 ++ if (uexp != vexp)
1.65 ++ return 0;
1.66 +
1.67 + usize = ABS (usize);
1.68 + vsize = ABS (vsize);
1.69 +@@ -93,17 +94,26 @@
1.70 + size = usize;
1.71 + }
1.72 +
1.73 +- if (size > (n_bits + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS)
1.74 +- size = (n_bits + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS;
1.75 ++ up += usize; /* point just above most significant limb */
1.76 ++ vp += vsize; /* point just above most significant limb */
1.77 +
1.78 +- up += usize - size;
1.79 +- vp += vsize - size;
1.80 ++ count_leading_zeros (cnt, up[-1]);
1.81 ++ if ((vp[-1] >> (GMP_LIMB_BITS - 1 - cnt)) != 1)
1.82 ++ return 0; /* msb positions different */
1.83 +
1.84 +- for (i = size - 1; i >= 0; i--)
1.85 ++ n_bits += cnt - GMP_NAIL_BITS;
1.86 ++
1.87 ++ size = MIN (size, (n_bits + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS);
1.88 ++
1.89 ++ up -= size; /* point at least significant relevant limb */
1.90 ++ vp -= size; /* point at least significant relevant limb */
1.91 ++
1.92 ++ for (i = size - 1; i > 0; i--)
1.93 + {
1.94 + if (up[i] != vp[i])
1.95 + return 0;
1.96 + }
1.97 +
1.98 +- return 1;
1.99 ++ diff = (up[0] ^ vp[0]) >> GMP_NUMB_BITS - 1 - (n_bits - 1) % GMP_NUMB_BITS;
1.100 ++ return diff == 0;
1.101 + }
1.102 +diff -durN gmp-4.2.4.orig/tests/cxx/t-prec.cc gmp-4.2.4/tests/cxx/t-prec.cc
1.103 +--- gmp-4.2.4.orig/tests/cxx/t-prec.cc 2007-09-01 12:09:03.000000000 +0200
1.104 ++++ gmp-4.2.4/tests/cxx/t-prec.cc 2009-03-08 18:36:16.000000000 +0100
1.105 +@@ -1,6 +1,6 @@
1.106 + /* Test precision of mpf_class expressions.
1.107 +
1.108 +-Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
1.109 ++Copyright 2001, 2002, 2003, 2008 Free Software Foundation, Inc.
1.110 +
1.111 + This file is part of the GNU MP Library.
1.112 +
1.113 +@@ -61,7 +61,7 @@
1.114 + g = 1 / f;
1.115 + ASSERT_ALWAYS_PREC
1.116 + (g, "0.11111 11111 11111 11111 11111 11111 11111 11111 11111 11111"
1.117 +- " 11111 11111 11111 11111 11111 11", very_large_prec);
1.118 ++ " 11111 11111 11111 11111 11111 111", very_large_prec);
1.119 + }
1.120 + {
1.121 + mpf_class f(15.0, large_prec);
1.122 +@@ -69,7 +69,7 @@
1.123 + g = 1 / f;
1.124 + ASSERT_ALWAYS_PREC
1.125 + (g, "0.06666 66666 66666 66666 66666 66666 66666 66666 66666 66666"
1.126 +- " 66666 66666 66666 66666 66666 67", very_large_prec);
1.127 ++ " 66666 66666 66666 66666 66666 667", very_large_prec);
1.128 + }
1.129 +
1.130 + // compound expressions
1.131 +@@ -94,14 +94,14 @@
1.132 + i = f / g + h;
1.133 + ASSERT_ALWAYS_PREC
1.134 + (i, "15.33333 33333 33333 33333 33333 33333 33333 33333 33333 33333"
1.135 +- " 33333 33333 33333 333", very_large_prec);
1.136 ++ " 33333 33333 33333 33333 33333 3", very_large_prec);
1.137 + }
1.138 + {
1.139 + mpf_class f(3.0, small_prec);
1.140 + mpf_class g(-(1 + f) / 3, very_large_prec);
1.141 + ASSERT_ALWAYS_PREC
1.142 + (g, "-1.33333 33333 33333 33333 33333 33333 33333 33333 33333 33333"
1.143 +- " 33333 33333 33333 333", very_large_prec);
1.144 ++ " 33333 33333 33333 33333 33333 33", very_large_prec);
1.145 + }
1.146 + {
1.147 + mpf_class f(9.0, medium_prec);
1.148 +@@ -117,7 +117,7 @@
1.149 + g = hypot(1 + 5 / f, 1.0);
1.150 + ASSERT_ALWAYS_PREC
1.151 + (g, "1.66666 66666 66666 66666 66666 66666 66666 66666 66666 66666"
1.152 +- " 66666 66666 66666 667", very_large_prec);
1.153 ++ " 66666 66666 66666 66666 66666 67", very_large_prec);
1.154 + }
1.155 +
1.156 + // compound assignments
1.157 +@@ -142,7 +142,7 @@
1.158 + mpf_class g(0.0, very_large_prec);
1.159 + g = mpf_class(1 / f);
1.160 + ASSERT_ALWAYS_PREC
1.161 +- (g, "0.11111 11111 11111 11111 11111 11111 11111 111", medium_prec);
1.162 ++ (g, "0.11111 11111 11111 11111 11111 11111 11111 1111", medium_prec);
1.163 + }
1.164 + {
1.165 + mpf_class f(15.0, large_prec);
1.166 +@@ -150,7 +150,7 @@
1.167 + g = mpf_class(1 / f);
1.168 + ASSERT_ALWAYS_PREC
1.169 + (g, "0.06666 66666 66666 66666 66666 66666 66666 66666 66666 66666"
1.170 +- " 66666 667", large_prec);
1.171 ++ " 66666 6667", large_prec);
1.172 + }
1.173 +
1.174 + {
1.175 +@@ -158,7 +158,8 @@
1.176 + mpf_class h(0.0, very_large_prec);
1.177 + h = mpf_class(f / g + 1, large_prec);
1.178 + ASSERT_ALWAYS_PREC
1.179 +- (h, "1.33333 33333 33333 33333 33333 33333 33333 33333 33333 3333",
1.180 ++ (h, "1.33333 33333 33333 33333 33333 33333 33333 33333 33333 33333"
1.181 ++ " 33333 333",
1.182 + large_prec);
1.183 + }
1.184 +
1.185 +@@ -170,7 +171,7 @@
1.186 + g = f - q;
1.187 + ASSERT_ALWAYS_PREC
1.188 + (g, "2.66666 66666 66666 66666 66666 66666 66666 66666 66666 66666"
1.189 +- " 66666 66666 66666 667", very_large_prec);
1.190 ++ " 66666 66666 66666 66666 66666 67", very_large_prec);
1.191 + }
1.192 +
1.193 + {
1.194 +@@ -179,7 +180,8 @@
1.195 + mpf_class g(0.0, very_large_prec);
1.196 + g = mpf_class(f - q, large_prec);
1.197 + ASSERT_ALWAYS_PREC
1.198 +- (g, "2.66666 66666 66666 66666 66666 66666 66666 66666 66666 6667",
1.199 ++ (g, "2.66666 66666 66666 66666 66666 66666 66666 66666 66666 66666"
1.200 ++ " 66666 667",
1.201 + large_prec);
1.202 + }
1.203 + {
1.204 +@@ -188,7 +190,7 @@
1.205 + mpf_class g(0.0, very_large_prec);
1.206 + g = mpf_class(f - q);
1.207 + ASSERT_ALWAYS_PREC
1.208 +- (g, "2.66666 66666 66666 66666 66666 6667", medium_prec);
1.209 ++ (g, "2.66666 66666 66666 66666 66666 66666 66666 667", medium_prec);
1.210 + }
1.211 + {
1.212 + mpf_class f(15.0, large_prec);
1.213 +@@ -196,7 +198,8 @@
1.214 + mpf_class g(0.0, very_large_prec);
1.215 + g = mpf_class(f + q);
1.216 + ASSERT_ALWAYS_PREC
1.217 +- (g, "15.33333 33333 33333 33333 33333 33333 33333 33333 33333 3333",
1.218 ++ (g, "15.33333 33333 33333 33333 33333 33333 33333 33333 33333 33333"
1.219 ++ " 33333 33",
1.220 + large_prec);
1.221 + }
1.222 + }