Add patchset for MGP-4.2.4, from upstream.
author"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Mar 08 18:04:56 2009 +0000 (2009-03-08)
changeset 12507aca73e68147
parent 1249 e612e57b4249
child 1251 2d5bac83fd18
Add patchset for MGP-4.2.4, from upstream.

/trunk/patches/gmp/4.2.4/120-perfpow.patch | 149 149 0 0 ++++++++++++++++++++++
/trunk/patches/gmp/4.2.4/110-mpf_set_str.patch | 32 32 0 0 +++++
/trunk/patches/gmp/4.2.4/100-mpf_eq.patch | 219 219 0 0 ++++++++++++++++++++++++++++++++
3 files changed, 400 insertions(+)
patches/gmp/4.2.4/100-mpf_eq.patch
patches/gmp/4.2.4/110-mpf_set_str.patch
patches/gmp/4.2.4/120-perfpow.patch
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/patches/gmp/4.2.4/100-mpf_eq.patch	Sun Mar 08 18:04:56 2009 +0000
     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 + }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/patches/gmp/4.2.4/110-mpf_set_str.patch	Sun Mar 08 18:04:56 2009 +0000
     2.3 @@ -0,0 +1,32 @@
     2.4 +Original patch from: mpf_set_str.c.4.diff
     2.5 +
     2.6 +-= BEGIN original header =-
     2.7 +-= END original header =-
     2.8 +
     2.9 +diff -durN gmp-4.2.4.orig/mpf/set_str.c gmp-4.2.4/mpf/set_str.c
    2.10 +--- gmp-4.2.4.orig/mpf/set_str.c	2008-08-25 16:11:37.000000000 +0200
    2.11 ++++ gmp-4.2.4/mpf/set_str.c	2009-03-08 18:36:16.000000000 +0100
    2.12 +@@ -137,7 +137,12 @@
    2.13 +       c = (unsigned char) *++str;
    2.14 +     }
    2.15 + 
    2.16 ++  /* Default base to decimal.  */
    2.17 ++  if (base == 0)
    2.18 ++    base = 10;
    2.19 ++
    2.20 +   exp_base = base;
    2.21 ++
    2.22 +   if (base < 0)
    2.23 +     {
    2.24 +       exp_base = 10;
    2.25 +@@ -165,10 +170,6 @@
    2.26 + 	return -1;
    2.27 +     }
    2.28 + 
    2.29 +-  /* Default base to decimal.  */
    2.30 +-  if (base == 0)
    2.31 +-    base = 10;
    2.32 +-
    2.33 +   /* Locate exponent part of the input.  Look from the right of the string,
    2.34 +      since the exponent is usually a lot shorter than the mantissa.  */
    2.35 +   expptr = NULL;
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/patches/gmp/4.2.4/120-perfpow.patch	Sun Mar 08 18:04:56 2009 +0000
     3.3 @@ -0,0 +1,149 @@
     3.4 +Original patch from: perfpow.c.diff
     3.5 +
     3.6 +-= BEGIN original header =-
     3.7 +Copyright 1998, 1999, 2000, 2001, 2005, 2008 Free Software Foundation, Inc.
     3.8 +
     3.9 +This file is part of the GNU MP Library.
    3.10 +
    3.11 +The GNU MP Library is free software; you can redistribute it and/or modify
    3.12 +it under the terms of the GNU Lesser General Public License as published by
    3.13 +the Free Software Foundation; either version 3 of the License, or (at your
    3.14 +option) any later version.
    3.15 +
    3.16 +The GNU MP Library is distributed in the hope that it will be useful, but
    3.17 +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    3.18 +or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    3.19 +License for more details.
    3.20 +
    3.21 +You should have received a copy of the GNU Lesser General Public License
    3.22 +along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
    3.23 +
    3.24 +-= END original header =-
    3.25 +
    3.26 +diff -durN gmp-4.2.4.orig/mpz/perfpow.c gmp-4.2.4/mpz/perfpow.c
    3.27 +--- gmp-4.2.4.orig/mpz/perfpow.c	2007-08-30 20:31:41.000000000 +0200
    3.28 ++++ gmp-4.2.4/mpz/perfpow.c	2009-03-08 18:36:16.000000000 +0100
    3.29 +@@ -1,7 +1,7 @@
    3.30 + /* mpz_perfect_power_p(arg) -- Return non-zero if ARG is a perfect power,
    3.31 +    zero otherwise.
    3.32 + 
    3.33 +-Copyright 1998, 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
    3.34 ++Copyright 1998, 1999, 2000, 2001, 2005, 2008 Free Software Foundation, Inc.
    3.35 + 
    3.36 + This file is part of the GNU MP Library.
    3.37 + 
    3.38 +@@ -59,6 +59,8 @@
    3.39 + #define SMALLEST_OMITTED_PRIME 1009
    3.40 + 
    3.41 + 
    3.42 ++#define POW2P(a) (((a) & ((a) - 1)) == 0)
    3.43 ++
    3.44 + int
    3.45 + mpz_perfect_power_p (mpz_srcptr u)
    3.46 + {
    3.47 +@@ -72,16 +74,13 @@
    3.48 +   mp_size_t usize = SIZ (u);
    3.49 +   TMP_DECL;
    3.50 + 
    3.51 +-  if (usize == 0)
    3.52 +-    return 1;			/* consider 0 a perfect power */
    3.53 ++  if (mpz_cmpabs_ui (u, 1) <= 0)
    3.54 ++    return 1;			/* -1, 0, and +1 are perfect powers */
    3.55 + 
    3.56 +   n2 = mpz_scan1 (u, 0);
    3.57 +   if (n2 == 1)
    3.58 +     return 0;			/* 2 divides exactly once.  */
    3.59 + 
    3.60 +-  if (n2 != 0 && (n2 & 1) == 0 && usize < 0)
    3.61 +-    return 0;			/* 2 has even multiplicity with negative U */
    3.62 +-
    3.63 +   TMP_MARK;
    3.64 + 
    3.65 +   uns = ABS (usize) - n2 / BITS_PER_MP_LIMB;
    3.66 +@@ -89,6 +88,14 @@
    3.67 +   MPZ_TMP_INIT (u2, uns);
    3.68 + 
    3.69 +   mpz_tdiv_q_2exp (u2, u, n2);
    3.70 ++  mpz_abs (u2, u2);
    3.71 ++
    3.72 ++  if (mpz_cmp_ui (u2, 1) == 0)
    3.73 ++    {
    3.74 ++      TMP_FREE;
    3.75 ++      /* factoring completed; consistent power */
    3.76 ++      return ! (usize < 0 && POW2P(n2));
    3.77 ++    }
    3.78 + 
    3.79 +   if (isprime (n2))
    3.80 +     goto n2prime;
    3.81 +@@ -97,6 +104,9 @@
    3.82 +     {
    3.83 +       prime = primes[i];
    3.84 + 
    3.85 ++      if (mpz_cmp_ui (u2, prime) < 0)
    3.86 ++	break;
    3.87 ++
    3.88 +       if (mpz_divisible_ui_p (u2, prime))	/* divisible by this prime? */
    3.89 + 	{
    3.90 + 	  rem = mpz_tdiv_q_ui (q, u2, prime * prime);
    3.91 +@@ -115,12 +125,6 @@
    3.92 + 	      n++;
    3.93 + 	    }
    3.94 + 
    3.95 +-	  if ((n & 1) == 0 && usize < 0)
    3.96 +-	    {
    3.97 +-	      TMP_FREE;
    3.98 +-	      return 0;		/* even multiplicity with negative U, reject */
    3.99 +-	    }
   3.100 +-
   3.101 + 	  n2 = gcd (n2, n);
   3.102 + 	  if (n2 == 1)
   3.103 + 	    {
   3.104 +@@ -128,10 +132,11 @@
   3.105 + 	      return 0;		/* we have multiplicity 1 of some factor */
   3.106 + 	    }
   3.107 + 
   3.108 +-	  if (mpz_cmpabs_ui (u2, 1) == 0)
   3.109 ++	  if (mpz_cmp_ui (u2, 1) == 0)
   3.110 + 	    {
   3.111 + 	      TMP_FREE;
   3.112 +-	      return 1;		/* factoring completed; consistent power */
   3.113 ++	      /* factoring completed; consistent power */
   3.114 ++	      return ! (usize < 0 && POW2P(n2));
   3.115 + 	    }
   3.116 + 
   3.117 + 	  /* As soon as n2 becomes a prime number, stop factoring.
   3.118 +@@ -169,6 +174,10 @@
   3.119 +   else
   3.120 +     {
   3.121 +       unsigned long int nth;
   3.122 ++
   3.123 ++      if (usize < 0 && POW2P(n2))
   3.124 ++	return 0;
   3.125 ++
   3.126 +       /* We found some factors above.  We just need to consider values of n
   3.127 + 	 that divides n2.  */
   3.128 +       for (nth = 2; nth <= n2; nth++)
   3.129 +@@ -184,8 +193,11 @@
   3.130 + 	    exact = mpz_root (q, u2, nth);
   3.131 + 	  if (exact)
   3.132 + 	    {
   3.133 +-	      TMP_FREE;
   3.134 +-	      return 1;
   3.135 ++	      if (! (usize < 0 && POW2P(nth)))
   3.136 ++		{
   3.137 ++		  TMP_FREE;
   3.138 ++		  return 1;
   3.139 ++		}
   3.140 + 	    }
   3.141 + 	  if (mpz_cmp_ui (q, SMALLEST_OMITTED_PRIME) < 0)
   3.142 + 	    {
   3.143 +@@ -199,6 +211,9 @@
   3.144 +     }
   3.145 + 
   3.146 + n2prime:
   3.147 ++  if (usize < 0 && POW2P(n2))
   3.148 ++    return 0;
   3.149 ++
   3.150 +   exact = mpz_root (NULL, u2, n2);
   3.151 +   TMP_FREE;
   3.152 +   return exact;