source: clfs-embedded/patches/gmp-4.2.4-branch_update-1.patch @ 06beb7a

Last change on this file since 06beb7a was 06beb7a, checked in by Jim Gifford <clfs@…>, 15 years ago

Added: Patches

  • Property mode set to 100644
File size: 10.8 KB
  • doc/gmp.texi

    Submitted By: Jim Gifford (jim at cross-lfs dot org)
    Date: 2009-01-03
    Initial Package Version: 4.2.4
    Origin: GMP Website
    Upstream Status: Fixed
    Description: See http://gmplib.org Website Under Curent Status
     
    diff -Naur gmp-4.2.4.orig/doc/gmp.texi gmp-4.2.4/doc/gmp.texi
    old new  
    48494849equal, zero otherwise.  I.e., test if @var{op1} and @var{op2} are approximately
    48504850equal.
    48514851
    4852 Caution: Currently only whole limbs are compared, and only in an exact
    4853 fashion.  In the future values like 1000 and 0111 may be considered the same
    4854 to 3 bits (on the basis that their difference is that small).
     4852Caution 1: All version of GMP up to version 4.2.4 compared just whole limbs,
     4853meaning sometimes more than @var{op3} bits, sometimes fewer.
     4854
     4855Caution 2: This function will consider XXX11...111 and XX100...000 different,
     4856even if ... is replaced by a semi-infinite number of bits.  Such numbers are
     4857really just one ulp off, and should be considered equal.
    48554858@end deftypefun
    48564859
    48574860@deftypefun void mpf_reldiff (mpf_t @var{rop}, mpf_t @var{op1}, mpf_t @var{op2})
  • mpf/eq.c

    diff -Naur gmp-4.2.4.orig/mpf/eq.c gmp-4.2.4/mpf/eq.c
    old new  
    11/* mpf_eq -- Compare two floats up to a specified bit #.
    22
    3 Copyright 1993, 1995, 1996, 2001, 2002 Free Software Foundation, Inc.
     3Copyright 1993, 1995, 1996, 2001, 2002, 2008 Free Software Foundation, Inc.
    44
    55This file is part of the GNU MP Library.
    66
     
    1919
    2020#include "gmp.h"
    2121#include "gmp-impl.h"
     22#include "longlong.h"
    2223
    2324int
    2425mpf_eq (mpf_srcptr u, mpf_srcptr v, unsigned long int n_bits)
     
    2627  mp_srcptr up, vp;
    2728  mp_size_t usize, vsize, size, i;
    2829  mp_exp_t uexp, vexp;
     30  mp_limb_t diff;
     31  int cnt;
    2932
    3033  uexp = u->_mp_exp;
    3134  vexp = v->_mp_exp;
     
    5356  /* U and V have the same sign and are both non-zero.  */
    5457
    5558  /* 2. Are the exponents different?  */
    56   if (uexp > vexp)
    57     return 0;                   /* ??? handle (uexp = vexp + 1)   */
    58   if (vexp > uexp)
    59     return 0;                   /* ??? handle (vexp = uexp + 1)   */
     59  if (uexp != vexp)
     60    return 0;
    6061
    6162  usize = ABS (usize);
    6263  vsize = ABS (vsize);
     
    9394      size = usize;
    9495    }
    9596
    96   if (size > (n_bits + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS)
    97     size = (n_bits + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS;
     97  up += usize;                  /* point just above most significant limb */
     98  vp += vsize;                  /* point just above most significant limb */
    9899
    99   up += usize - size;
    100   vp += vsize - size;
     100  count_leading_zeros (cnt, up[-1]);
     101  if ((vp[-1] >> (GMP_LIMB_BITS - 1 - cnt)) != 1)
     102    return 0;                   /* msb positions different */
    101103
    102   for (i = size - 1; i >= 0; i--)
     104  n_bits += cnt - GMP_NAIL_BITS;
     105
     106  size = MIN (size, (n_bits + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS);
     107
     108  up -= size;                   /* point at least significant relevant limb */
     109  vp -= size;                   /* point at least significant relevant limb */
     110
     111  for (i = size - 1; i > 0; i--)
    103112    {
    104113      if (up[i] != vp[i])
    105114        return 0;
    106115    }
    107116
    108   return 1;
     117  diff = (up[0] ^ vp[0]) >> GMP_NUMB_BITS - 1 - (n_bits - 1) % GMP_NUMB_BITS;
     118  return diff == 0;
    109119}
  • mpf/set_str.c

    diff -Naur gmp-4.2.4.orig/mpf/set_str.c gmp-4.2.4/mpf/set_str.c
    old new  
    137137      c = (unsigned char) *++str;
    138138    }
    139139
     140  /* Default base to decimal.  */
     141  if (base == 0)
     142    base = 10;
     143
    140144  exp_base = base;
     145
    141146  if (base < 0)
    142147    {
    143148      exp_base = 10;
     
    165170        return -1;
    166171    }
    167172
    168   /* Default base to decimal.  */
    169   if (base == 0)
    170     base = 10;
    171 
    172173  /* Locate exponent part of the input.  Look from the right of the string,
    173174     since the exponent is usually a lot shorter than the mantissa.  */
    174175  expptr = NULL;
  • mpz/perfpow.c

    diff -Naur gmp-4.2.4.orig/mpz/perfpow.c gmp-4.2.4/mpz/perfpow.c
    old new  
    11/* mpz_perfect_power_p(arg) -- Return non-zero if ARG is a perfect power,
    22   zero otherwise.
    33
    4 Copyright 1998, 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
     4Copyright 1998, 1999, 2000, 2001, 2005, 2008 Free Software Foundation, Inc.
    55
    66This file is part of the GNU MP Library.
    77
     
    5959#define SMALLEST_OMITTED_PRIME 1009
    6060
    6161
     62#define POW2P(a) (((a) & ((a) - 1)) == 0)
     63
    6264int
    6365mpz_perfect_power_p (mpz_srcptr u)
    6466{
     
    7274  mp_size_t usize = SIZ (u);
    7375  TMP_DECL;
    7476
    75   if (usize == 0)
    76     return 1;                   /* consider 0 a perfect power */
     77  if (mpz_cmpabs_ui (u, 1) <= 0)
     78    return 1;                   /* -1, 0, and +1 are perfect powers */
    7779
    7880  n2 = mpz_scan1 (u, 0);
    7981  if (n2 == 1)
    8082    return 0;                   /* 2 divides exactly once.  */
    8183
    82   if (n2 != 0 && (n2 & 1) == 0 && usize < 0)
    83     return 0;                   /* 2 has even multiplicity with negative U */
    84 
    8584  TMP_MARK;
    8685
    8786  uns = ABS (usize) - n2 / BITS_PER_MP_LIMB;
     
    8988  MPZ_TMP_INIT (u2, uns);
    9089
    9190  mpz_tdiv_q_2exp (u2, u, n2);
     91  mpz_abs (u2, u2);
     92
     93  if (mpz_cmp_ui (u2, 1) == 0)
     94    {
     95      TMP_FREE;
     96      /* factoring completed; consistent power */
     97      return ! (usize < 0 && POW2P(n2));
     98    }
    9299
    93100  if (isprime (n2))
    94101    goto n2prime;
     
    97104    {
    98105      prime = primes[i];
    99106
     107      if (mpz_cmp_ui (u2, prime) < 0)
     108        break;
     109
    100110      if (mpz_divisible_ui_p (u2, prime))       /* divisible by this prime? */
    101111        {
    102112          rem = mpz_tdiv_q_ui (q, u2, prime * prime);
     
    115125              n++;
    116126            }
    117127
    118           if ((n & 1) == 0 && usize < 0)
    119             {
    120               TMP_FREE;
    121               return 0;         /* even multiplicity with negative U, reject */
    122             }
    123 
    124128          n2 = gcd (n2, n);
    125129          if (n2 == 1)
    126130            {
     
    128132              return 0;         /* we have multiplicity 1 of some factor */
    129133            }
    130134
    131           if (mpz_cmpabs_ui (u2, 1) == 0)
     135          if (mpz_cmp_ui (u2, 1) == 0)
    132136            {
    133137              TMP_FREE;
    134               return 1;         /* factoring completed; consistent power */
     138              /* factoring completed; consistent power */
     139              return ! (usize < 0 && POW2P(n2));
    135140            }
    136141
    137142          /* As soon as n2 becomes a prime number, stop factoring.
     
    169174  else
    170175    {
    171176      unsigned long int nth;
     177
     178      if (usize < 0 && POW2P(n2))
     179        return 0;
     180
    172181      /* We found some factors above.  We just need to consider values of n
    173182         that divides n2.  */
    174183      for (nth = 2; nth <= n2; nth++)
     
    184193            exact = mpz_root (q, u2, nth);
    185194          if (exact)
    186195            {
    187               TMP_FREE;
    188               return 1;
     196              if (! (usize < 0 && POW2P(nth)))
     197                {
     198                  TMP_FREE;
     199                  return 1;
     200                }
    189201            }
    190202          if (mpz_cmp_ui (q, SMALLEST_OMITTED_PRIME) < 0)
    191203            {
     
    199211    }
    200212
    201213n2prime:
     214  if (usize < 0 && POW2P(n2))
     215    return 0;
     216
    202217  exact = mpz_root (NULL, u2, n2);
    203218  TMP_FREE;
    204219  return exact;
  • tests/cxx/t-prec.cc

    diff -Naur gmp-4.2.4.orig/tests/cxx/t-prec.cc gmp-4.2.4/tests/cxx/t-prec.cc
    old new  
    11/* Test precision of mpf_class expressions.
    22
    3 Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
     3Copyright 2001, 2002, 2003, 2008 Free Software Foundation, Inc.
    44
    55This file is part of the GNU MP Library.
    66
     
    6161    g = 1 / f;
    6262    ASSERT_ALWAYS_PREC
    6363      (g, "0.11111 11111 11111 11111 11111 11111 11111 11111 11111 11111"
    64        "     11111 11111 11111 11111 11111 11", very_large_prec);
     64       "     11111 11111 11111 11111 11111 111", very_large_prec);
    6565  }
    6666  {
    6767    mpf_class f(15.0, large_prec);
     
    6969    g = 1 / f;
    7070    ASSERT_ALWAYS_PREC
    7171      (g, "0.06666 66666 66666 66666 66666 66666 66666 66666 66666 66666"
    72        "     66666 66666 66666 66666 66666 67", very_large_prec);
     72       "     66666 66666 66666 66666 66666 667", very_large_prec);
    7373  }
    7474
    7575  // compound expressions
     
    9494    i = f / g + h;
    9595    ASSERT_ALWAYS_PREC
    9696      (i, "15.33333 33333 33333 33333 33333 33333 33333 33333 33333 33333"
    97        "      33333 33333 33333 333", very_large_prec);
     97       "      33333 33333 33333 33333 33333 3", very_large_prec);
    9898  }
    9999  {
    100100    mpf_class f(3.0, small_prec);
    101101    mpf_class g(-(1 + f) / 3, very_large_prec);
    102102    ASSERT_ALWAYS_PREC
    103103      (g, "-1.33333 33333 33333 33333 33333 33333 33333 33333 33333 33333"
    104        "      33333 33333 33333 333", very_large_prec);
     104       "      33333 33333 33333 33333 33333 33", very_large_prec);
    105105  }
    106106  {
    107107    mpf_class f(9.0, medium_prec);
     
    117117    g = hypot(1 + 5 / f, 1.0);
    118118    ASSERT_ALWAYS_PREC
    119119      (g, "1.66666 66666 66666 66666 66666 66666 66666 66666 66666 66666"
    120        "     66666 66666 66666 667", very_large_prec);
     120       "     66666 66666 66666 66666 66666 67", very_large_prec);
    121121  }
    122122
    123123  // compound assignments
     
    142142    mpf_class g(0.0, very_large_prec);
    143143    g = mpf_class(1 / f);
    144144    ASSERT_ALWAYS_PREC
    145       (g, "0.11111 11111 11111 11111 11111 11111 11111 111", medium_prec);
     145      (g, "0.11111 11111 11111 11111 11111 11111 11111 1111", medium_prec);
    146146  }
    147147  {
    148148    mpf_class f(15.0, large_prec);
     
    150150    g = mpf_class(1 / f);
    151151    ASSERT_ALWAYS_PREC
    152152      (g, "0.06666 66666 66666 66666 66666 66666 66666 66666 66666 66666"
    153        "     66666 667", large_prec);
     153       "     66666 6667", large_prec);
    154154  }
    155155
    156156  {
     
    158158    mpf_class h(0.0, very_large_prec);
    159159    h = mpf_class(f / g + 1, large_prec);
    160160    ASSERT_ALWAYS_PREC
    161       (h, "1.33333 33333 33333 33333 33333 33333 33333 33333 33333 3333",
     161      (h, "1.33333 33333 33333 33333 33333 33333 33333 33333 33333 33333"
     162       "     33333 333",
    162163       large_prec);
    163164  }
    164165
     
    170171    g = f - q;
    171172    ASSERT_ALWAYS_PREC
    172173      (g, "2.66666 66666 66666 66666 66666 66666 66666 66666 66666 66666"
    173        "     66666 66666 66666 667", very_large_prec);
     174       "     66666 66666 66666 66666 66666 67", very_large_prec);
    174175  }
    175176
    176177  {
     
    179180    mpf_class g(0.0, very_large_prec);
    180181    g = mpf_class(f - q, large_prec);
    181182    ASSERT_ALWAYS_PREC
    182       (g, "2.66666 66666 66666 66666 66666 66666 66666 66666 66666 6667",
     183      (g, "2.66666 66666 66666 66666 66666 66666 66666 66666 66666 66666"
     184       "     66666 667",
    183185       large_prec);
    184186  }
    185187  {
     
    188190    mpf_class g(0.0, very_large_prec);
    189191    g = mpf_class(f - q);
    190192    ASSERT_ALWAYS_PREC
    191       (g, "2.66666 66666 66666 66666 66666 6667", medium_prec);
     193      (g, "2.66666 66666 66666 66666 66666 66666 66666 667", medium_prec);
    192194  }
    193195  {
    194196    mpf_class f(15.0, large_prec);
     
    196198    mpf_class g(0.0, very_large_prec);
    197199    g = mpf_class(f + q);
    198200    ASSERT_ALWAYS_PREC
    199       (g, "15.33333 33333 33333 33333 33333 33333 33333 33333 33333 3333",
     201      (g, "15.33333 33333 33333 33333 33333 33333 33333 33333 33333 33333"
     202       "      33333 33",
    200203       large_prec);
    201204  }
    202205}
Note: See TracBrowser for help on using the repository browser.