wok diff mpfr/stuff/mpfr-3.1.2-upstream_fixes-3.patch @ rev 19452

Up fasm (1.71.57)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Oct 20 16:31:20 2016 +0200 (2016-10-20)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mpfr/stuff/mpfr-3.1.2-upstream_fixes-3.patch	Thu Oct 20 16:31:20 2016 +0200
     1.3 @@ -0,0 +1,1199 @@
     1.4 +Submitted By:            Bruce Dubbs <bdubbs_at_linuxfromscratch_dot_org>
     1.5 +Updated By:              Armin K. <krejzi at email dot com>
     1.6 +Date:                    2015-02-06
     1.7 +Initial Package Version: 3.1.2
     1.8 +Upstream Status:         Already in upstream patch repo
     1.9 +Origin:                  Upstream
    1.10 +Description:             This patch contains patches for several bugs in MPFR.
    1.11 +                         Note that the patch for configure.ac has been 
    1.12 +                         removed to prevent unneeded regeneration of build
    1.13 +                         files.
    1.14 +                         See http://www.mpfr.org/mpfr-current/allpatches
    1.15 +
    1.16 +--- a/PATCHES	2013-03-13 16:37:38.000000000 +0100
    1.17 ++++ b/PATCHES	2014-12-31 14:56:02.685641958 +0100
    1.18 +@@ -0,0 +1,11 @@
    1.19 ++strtofr
    1.20 ++vasprintf
    1.21 ++div-overflow
    1.22 ++gmp6-compat
    1.23 ++exp3
    1.24 ++li2-return
    1.25 ++custom_init_set
    1.26 ++printf-alt0
    1.27 ++clang-divby0
    1.28 ++fits-smallneg
    1.29 ++exp_2
    1.30 +--- a/src/div.c	2013-03-13 16:37:33.000000000 +0100
    1.31 ++++ b/src/div.c	2014-12-31 14:56:02.686641971 +0100
    1.32 +@@ -750,7 +750,9 @@
    1.33 +  truncate_check_qh:
    1.34 +   if (qh)
    1.35 +     {
    1.36 +-      qexp ++;
    1.37 ++      if (MPFR_LIKELY (qexp < MPFR_EXP_MAX))
    1.38 ++        qexp ++;
    1.39 ++      /* else qexp is now incorrect, but one will still get an overflow */
    1.40 +       q0p[q0size - 1] = MPFR_LIMB_HIGHBIT;
    1.41 +     }
    1.42 +   goto truncate;
    1.43 +@@ -765,7 +767,9 @@
    1.44 +   inex = 1; /* always here */
    1.45 +   if (mpn_add_1 (q0p, q0p, q0size, MPFR_LIMB_ONE << sh))
    1.46 +     {
    1.47 +-      qexp ++;
    1.48 ++      if (MPFR_LIKELY (qexp < MPFR_EXP_MAX))
    1.49 ++        qexp ++;
    1.50 ++      /* else qexp is now incorrect, but one will still get an overflow */
    1.51 +       q0p[q0size - 1] = MPFR_LIMB_HIGHBIT;
    1.52 +     }
    1.53 + 
    1.54 +--- a/src/exp_2.c	2013-03-13 16:37:28.000000000 +0100
    1.55 ++++ b/src/exp_2.c	2014-12-31 14:56:02.686641971 +0100
    1.56 +@@ -204,7 +204,7 @@
    1.57 +           for (k = 0; k < K; k++)
    1.58 +             {
    1.59 +               mpz_mul (ss, ss, ss);
    1.60 +-              exps <<= 1;
    1.61 ++              exps *= 2;
    1.62 +               exps += mpz_normalize (ss, ss, q);
    1.63 +             }
    1.64 +           mpfr_set_z (s, ss, MPFR_RNDN);
    1.65 +--- a/src/exp3.c	2013-03-13 16:37:34.000000000 +0100
    1.66 ++++ b/src/exp3.c	2014-12-31 14:56:02.686641971 +0100
    1.67 +@@ -283,7 +283,7 @@
    1.68 +             }
    1.69 +         }
    1.70 + 
    1.71 +-      if (mpfr_can_round (shift_x > 0 ? t : tmp, realprec, MPFR_RNDD, MPFR_RNDZ,
    1.72 ++      if (mpfr_can_round (shift_x > 0 ? t : tmp, realprec, MPFR_RNDN, MPFR_RNDZ,
    1.73 +                           MPFR_PREC(y) + (rnd_mode == MPFR_RNDN)))
    1.74 +         {
    1.75 +           inexact = mpfr_set (y, shift_x > 0 ? t : tmp, rnd_mode);
    1.76 +--- a/src/fits_u.h	2013-03-13 16:37:35.000000000 +0100
    1.77 ++++ b/src/fits_u.h	2014-12-31 14:56:02.686641971 +0100
    1.78 +@@ -32,17 +32,20 @@
    1.79 +   int res;
    1.80 + 
    1.81 +   if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f)))
    1.82 +-    /* Zero always fit */
    1.83 +-    return MPFR_IS_ZERO (f) ? 1 : 0;
    1.84 +-  else if (MPFR_IS_NEG (f))
    1.85 +-    /* Negative numbers don't fit */
    1.86 +-    return 0;
    1.87 +-  /* now it fits if
    1.88 +-     (a) f <= MAXIMUM
    1.89 +-     (b) round(f, prec(slong), rnd) <= MAXIMUM */
    1.90 ++    return MPFR_IS_ZERO (f) ? 1 : 0;  /* Zero always fits */
    1.91 + 
    1.92 +   e = MPFR_GET_EXP (f);
    1.93 + 
    1.94 ++  if (MPFR_IS_NEG (f))
    1.95 ++    return e >= 1 ? 0  /* f <= -1 does not fit */
    1.96 ++      : rnd != MPFR_RNDN ? MPFR_IS_LIKE_RNDU (rnd, -1)  /* directed mode */
    1.97 ++      : e < 0 ? 1  /* f > -1/2 fits in MPFR_RNDN */
    1.98 ++      : mpfr_powerof2_raw(f);  /* -1/2 fits, -1 < f < -1/2 don't */
    1.99 ++
   1.100 ++  /* Now it fits if
   1.101 ++     (a) f <= MAXIMUM
   1.102 ++     (b) round(f, prec(slong), rnd) <= MAXIMUM */
   1.103 ++
   1.104 +   /* first compute prec(MAXIMUM); fits in an int */
   1.105 +   for (s = MAXIMUM, prec = 0; s != 0; s /= 2, prec ++);
   1.106 + 
   1.107 +--- a/src/fits_uintmax.c	2013-03-13 16:37:33.000000000 +0100
   1.108 ++++ b/src/fits_uintmax.c	2014-12-31 14:56:02.686641971 +0100
   1.109 +@@ -27,51 +27,19 @@
   1.110 + #include "mpfr-intmax.h"
   1.111 + #include "mpfr-impl.h"
   1.112 + 
   1.113 +-#ifdef _MPFR_H_HAVE_INTMAX_T
   1.114 +-
   1.115 +-/* We can't use fits_u.h <= mpfr_cmp_ui */
   1.116 +-int
   1.117 +-mpfr_fits_uintmax_p (mpfr_srcptr f, mpfr_rnd_t rnd)
   1.118 +-{
   1.119 +-  mpfr_exp_t e;
   1.120 +-  int prec;
   1.121 +-  uintmax_t s;
   1.122 +-  mpfr_t x;
   1.123 +-  int res;
   1.124 +-
   1.125 +-  if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f)))
   1.126 +-    /* Zero always fit */
   1.127 +-    return MPFR_IS_ZERO (f) ? 1 : 0;
   1.128 +-  else if (MPFR_IS_NEG (f))
   1.129 +-    /* Negative numbers don't fit */
   1.130 +-    return 0;
   1.131 +-  /* now it fits if
   1.132 +-     (a) f <= MAXIMUM
   1.133 +-     (b) round(f, prec(slong), rnd) <= MAXIMUM */
   1.134 +-
   1.135 +-  e = MPFR_GET_EXP (f);
   1.136 ++/* Note: though mpfr-impl.h is included in fits_u.h, we also include it
   1.137 ++   above so that it gets included even when _MPFR_H_HAVE_INTMAX_T is not
   1.138 ++   defined; this is necessary to avoid an empty translation unit, which
   1.139 ++   is forbidden by ISO C. Without this, a failing test can be reproduced
   1.140 ++   by creating an invalid stdint.h somewhere in the default include path
   1.141 ++   and by compiling MPFR with "gcc -ansi -pedantic-errors". */
   1.142 + 
   1.143 +-  /* first compute prec(MAXIMUM); fits in an int */
   1.144 +-  for (s = MPFR_UINTMAX_MAX, prec = 0; s != 0; s /= 2, prec ++);
   1.145 +-
   1.146 +-  /* MAXIMUM needs prec bits, i.e. MAXIMUM = 2^prec - 1 */
   1.147 +-
   1.148 +-  /* if e <= prec - 1, then f < 2^(prec-1) < MAXIMUM */
   1.149 +-  if (e <= prec - 1)
   1.150 +-    return 1;
   1.151 +-
   1.152 +-  /* if e >= prec + 1, then f >= 2^prec > MAXIMUM */
   1.153 +-  if (e >= prec + 1)
   1.154 +-    return 0;
   1.155 ++#ifdef _MPFR_H_HAVE_INTMAX_T
   1.156 + 
   1.157 +-  MPFR_ASSERTD (e == prec);
   1.158 ++#define FUNCTION   mpfr_fits_uintmax_p
   1.159 ++#define MAXIMUM    MPFR_UINTMAX_MAX
   1.160 ++#define TYPE       uintmax_t
   1.161 + 
   1.162 +-  /* hard case: first round to prec bits, then check */
   1.163 +-  mpfr_init2 (x, prec);
   1.164 +-  mpfr_set (x, f, rnd);
   1.165 +-  res = MPFR_GET_EXP (x) == e;
   1.166 +-  mpfr_clear (x);
   1.167 +-  return res;
   1.168 +-}
   1.169 ++#include "fits_u.h"
   1.170 + 
   1.171 + #endif
   1.172 +--- a/src/init2.c	2013-03-13 16:37:32.000000000 +0100
   1.173 ++++ b/src/init2.c	2014-12-31 14:56:02.686641971 +0100
   1.174 +@@ -30,11 +30,11 @@
   1.175 + 
   1.176 +   /* Check if we can represent the number of limbs
   1.177 +    * associated to the maximum of mpfr_prec_t*/
   1.178 +-  MPFR_ASSERTN( MP_SIZE_T_MAX >= (MPFR_PREC_MAX/BYTES_PER_MP_LIMB) );
   1.179 ++  MPFR_ASSERTN( MP_SIZE_T_MAX >= (MPFR_PREC_MAX/MPFR_BYTES_PER_MP_LIMB) );
   1.180 + 
   1.181 +-  /* Check for correct GMP_NUMB_BITS and BYTES_PER_MP_LIMB */
   1.182 +-  MPFR_ASSERTN( GMP_NUMB_BITS == BYTES_PER_MP_LIMB * CHAR_BIT
   1.183 +-                && sizeof(mp_limb_t) == BYTES_PER_MP_LIMB );
   1.184 ++  /* Check for correct GMP_NUMB_BITS and MPFR_BYTES_PER_MP_LIMB */
   1.185 ++  MPFR_ASSERTN( GMP_NUMB_BITS == MPFR_BYTES_PER_MP_LIMB * CHAR_BIT
   1.186 ++                && sizeof(mp_limb_t) == MPFR_BYTES_PER_MP_LIMB );
   1.187 + 
   1.188 +   MPFR_ASSERTN (mp_bits_per_limb == GMP_NUMB_BITS);
   1.189 + 
   1.190 +--- a/src/li2.c	2013-03-13 16:37:32.000000000 +0100
   1.191 ++++ b/src/li2.c	2014-12-31 14:56:02.686641971 +0100
   1.192 +@@ -630,5 +630,5 @@
   1.193 +       return mpfr_check_range (y, inexact, rnd_mode);
   1.194 +     }
   1.195 + 
   1.196 +-  MPFR_ASSERTN (0);             /* should never reach this point */
   1.197 ++  MPFR_RET_NEVER_GO_HERE ();
   1.198 + }
   1.199 +--- a/src/mpfr-gmp.h	2013-03-13 16:37:32.000000000 +0100
   1.200 ++++ b/src/mpfr-gmp.h	2014-12-31 14:56:02.687641984 +0100
   1.201 +@@ -72,7 +72,6 @@
   1.202 + #endif
   1.203 + 
   1.204 + /* Define some macros */
   1.205 +-#define BYTES_PER_MP_LIMB (GMP_NUMB_BITS/CHAR_BIT)
   1.206 + 
   1.207 + #define MP_LIMB_T_MAX (~(mp_limb_t)0)
   1.208 + 
   1.209 +@@ -96,19 +95,19 @@
   1.210 + #define SHRT_HIGHBIT       SHRT_MIN
   1.211 + 
   1.212 + /* MP_LIMB macros */
   1.213 +-#define MPN_ZERO(dst, n) memset((dst), 0, (n)*BYTES_PER_MP_LIMB)
   1.214 +-#define MPN_COPY_DECR(dst,src,n) memmove((dst),(src),(n)*BYTES_PER_MP_LIMB)
   1.215 +-#define MPN_COPY_INCR(dst,src,n) memmove((dst),(src),(n)*BYTES_PER_MP_LIMB)
   1.216 ++#define MPN_ZERO(dst, n) memset((dst), 0, (n)*MPFR_BYTES_PER_MP_LIMB)
   1.217 ++#define MPN_COPY_DECR(dst,src,n) memmove((dst),(src),(n)*MPFR_BYTES_PER_MP_LIMB)
   1.218 ++#define MPN_COPY_INCR(dst,src,n) memmove((dst),(src),(n)*MPFR_BYTES_PER_MP_LIMB)
   1.219 + #define MPN_COPY(dst,src,n) \
   1.220 +   do                                                                  \
   1.221 +     {                                                                 \
   1.222 +       if ((dst) != (src))                                             \
   1.223 +         {                                                             \
   1.224 +           MPFR_ASSERTD ((char *) (dst) >= (char *) (src) +            \
   1.225 +-                                          (n) * BYTES_PER_MP_LIMB ||  \
   1.226 ++                                     (n) * MPFR_BYTES_PER_MP_LIMB ||  \
   1.227 +                         (char *) (src) >= (char *) (dst) +            \
   1.228 +-                                          (n) * BYTES_PER_MP_LIMB);   \
   1.229 +-          memcpy ((dst), (src), (n) * BYTES_PER_MP_LIMB);             \
   1.230 ++                                     (n) * MPFR_BYTES_PER_MP_LIMB);   \
   1.231 ++          memcpy ((dst), (src), (n) * MPFR_BYTES_PER_MP_LIMB);        \
   1.232 +         }                                                             \
   1.233 +     }                                                                 \
   1.234 +   while (0)
   1.235 +--- a/src/mpfr.h	2013-03-13 16:37:37.000000000 +0100
   1.236 ++++ b/src/mpfr.h	2014-12-31 14:56:02.687641984 +0100
   1.237 +@@ -27,7 +27,7 @@
   1.238 + #define MPFR_VERSION_MAJOR 3
   1.239 + #define MPFR_VERSION_MINOR 1
   1.240 + #define MPFR_VERSION_PATCHLEVEL 2
   1.241 +-#define MPFR_VERSION_STRING "3.1.2"
   1.242 ++#define MPFR_VERSION_STRING "3.1.2-p11"
   1.243 + 
   1.244 + /* Macros dealing with MPFR VERSION */
   1.245 + #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
   1.246 +@@ -861,7 +861,7 @@
   1.247 +     _t = (mpfr_kind_t) _k;                                     \
   1.248 +     _s = 1;                                                    \
   1.249 +   } else {                                                     \
   1.250 +-    _t = (mpfr_kind_t) -k;                                     \
   1.251 ++    _t = (mpfr_kind_t) - _k;                                   \
   1.252 +     _s = -1;                                                   \
   1.253 +   }                                                            \
   1.254 +   _e = _t == MPFR_REGULAR_KIND ? (e) :                         \
   1.255 +--- a/src/mpfr-impl.h	2013-03-13 16:37:36.000000000 +0100
   1.256 ++++ b/src/mpfr-impl.h	2014-12-31 14:56:02.687641984 +0100
   1.257 +@@ -191,7 +191,7 @@
   1.258 + # endif
   1.259 + #endif
   1.260 + 
   1.261 +-
   1.262 ++#define MPFR_BYTES_PER_MP_LIMB (GMP_NUMB_BITS/CHAR_BIT)
   1.263 + 
   1.264 + /******************************************************
   1.265 +  ******************** Check GMP ***********************
   1.266 +@@ -468,8 +468,16 @@
   1.267 + #define MPFR_LIMBS_PER_FLT ((IEEE_FLT_MANT_DIG-1)/GMP_NUMB_BITS+1)
   1.268 + 
   1.269 + /* Visual C++ doesn't support +1.0/0.0, -1.0/0.0 and 0.0/0.0
   1.270 +-   at compile time. */
   1.271 +-#if defined(_MSC_VER) && defined(_WIN32) && (_MSC_VER >= 1200)
   1.272 ++   at compile time.
   1.273 ++   Clang with -fsanitize=undefined is a bit similar due to a bug:
   1.274 ++     http://llvm.org/bugs/show_bug.cgi?id=17381
   1.275 ++   but even without its sanitizer, it may be better to use the
   1.276 ++   double_zero version until IEEE 754 division by zero is properly
   1.277 ++   supported:
   1.278 ++     http://llvm.org/bugs/show_bug.cgi?id=17000
   1.279 ++*/
   1.280 ++#if (defined(_MSC_VER) && defined(_WIN32) && (_MSC_VER >= 1200)) || \
   1.281 ++    defined(__clang__)
   1.282 + static double double_zero = 0.0;
   1.283 + # define DBL_NAN (double_zero/double_zero)
   1.284 + # define DBL_POS_INF ((double) 1.0/double_zero)
   1.285 +@@ -501,6 +509,8 @@
   1.286 +    (with Xcode 2.4.1, i.e. the latest one). */
   1.287 + #define LVALUE(x) (&(x) == &(x) || &(x) != &(x))
   1.288 + #define DOUBLE_ISINF(x) (LVALUE(x) && ((x) > DBL_MAX || (x) < -DBL_MAX))
   1.289 ++/* The DOUBLE_ISNAN(x) macro is also valid on long double x
   1.290 ++   (assuming that the compiler isn't too broken). */
   1.291 + #ifdef MPFR_NANISNAN
   1.292 + /* Avoid MIPSpro / IRIX64 / gcc -ffast-math (incorrect) optimizations.
   1.293 +    The + must not be replaced by a ||. With gcc -ffast-math, NaN is
   1.294 +@@ -920,7 +930,7 @@
   1.295 + #define MPFR_SET_ALLOC_SIZE(x, n) \
   1.296 +  ( ((mp_size_t*) MPFR_MANT(x))[-1] = n)
   1.297 + #define MPFR_MALLOC_SIZE(s) \
   1.298 +-  ( sizeof(mpfr_size_limb_t) + BYTES_PER_MP_LIMB * ((size_t) s) )
   1.299 ++  ( sizeof(mpfr_size_limb_t) + MPFR_BYTES_PER_MP_LIMB * ((size_t) s) )
   1.300 + #define MPFR_SET_MANT_PTR(x,p) \
   1.301 +    (MPFR_MANT(x) = (mp_limb_t*) ((mpfr_size_limb_t*) p + 1))
   1.302 + #define MPFR_GET_REAL_PTR(x) \
   1.303 +@@ -954,7 +964,7 @@
   1.304 + #endif
   1.305 + 
   1.306 + #define MPFR_TMP_LIMBS_ALLOC(N) \
   1.307 +-  ((mp_limb_t *) MPFR_TMP_ALLOC ((size_t) (N) * BYTES_PER_MP_LIMB))
   1.308 ++  ((mp_limb_t *) MPFR_TMP_ALLOC ((size_t) (N) * MPFR_BYTES_PER_MP_LIMB))
   1.309 + 
   1.310 + /* temporary allocate 1 limb at xp, and initialize mpfr variable x */
   1.311 + /* The temporary var doesn't have any size field, but it doesn't matter
   1.312 +--- a/src/mul.c	2013-03-13 16:37:37.000000000 +0100
   1.313 ++++ b/src/mul.c	2014-12-31 14:56:02.688641997 +0100
   1.314 +@@ -106,7 +106,7 @@
   1.315 +   MPFR_ASSERTD(tn <= k);
   1.316 + 
   1.317 +   /* Check for no size_t overflow*/
   1.318 +-  MPFR_ASSERTD((size_t) k <= ((size_t) -1) / BYTES_PER_MP_LIMB);
   1.319 ++  MPFR_ASSERTD((size_t) k <= ((size_t) -1) / MPFR_BYTES_PER_MP_LIMB);
   1.320 +   MPFR_TMP_MARK(marker);
   1.321 +   tmp = MPFR_TMP_LIMBS_ALLOC (k);
   1.322 + 
   1.323 +@@ -301,7 +301,7 @@
   1.324 +   MPFR_ASSERTD (tn <= k); /* tn <= k, thus no int overflow */
   1.325 + 
   1.326 +   /* Check for no size_t overflow*/
   1.327 +-  MPFR_ASSERTD ((size_t) k <= ((size_t) -1) / BYTES_PER_MP_LIMB);
   1.328 ++  MPFR_ASSERTD ((size_t) k <= ((size_t) -1) / MPFR_BYTES_PER_MP_LIMB);
   1.329 +   MPFR_TMP_MARK (marker);
   1.330 +   tmp = MPFR_TMP_LIMBS_ALLOC (k);
   1.331 + 
   1.332 +--- a/src/stack_interface.c	2013-03-13 16:37:32.000000000 +0100
   1.333 ++++ b/src/stack_interface.c	2014-12-31 14:56:02.688641997 +0100
   1.334 +@@ -26,7 +26,7 @@
   1.335 + size_t
   1.336 + mpfr_custom_get_size (mpfr_prec_t prec)
   1.337 + {
   1.338 +-  return MPFR_PREC2LIMBS (prec) * BYTES_PER_MP_LIMB;
   1.339 ++  return MPFR_PREC2LIMBS (prec) * MPFR_BYTES_PER_MP_LIMB;
   1.340 + }
   1.341 + 
   1.342 + #undef mpfr_custom_init
   1.343 +--- a/src/strtofr.c	2013-03-13 16:37:32.000000000 +0100
   1.344 ++++ b/src/strtofr.c	2014-12-31 14:56:02.688641997 +0100
   1.345 +@@ -473,8 +473,10 @@
   1.346 +       /* prec bits corresponds to ysize limbs */
   1.347 +       ysize_bits = ysize * GMP_NUMB_BITS;
   1.348 +       /* and to ysize_bits >= prec > MPFR_PREC (x) bits */
   1.349 +-      y = MPFR_TMP_LIMBS_ALLOC (2 * ysize + 1);
   1.350 +-      y += ysize; /* y has (ysize+1) allocated limbs */
   1.351 ++      /* we need to allocate one more limb to work around bug
   1.352 ++         https://gmplib.org/list-archives/gmp-bugs/2013-December/003267.html */
   1.353 ++      y = MPFR_TMP_LIMBS_ALLOC (2 * ysize + 2);
   1.354 ++      y += ysize; /* y has (ysize+2) allocated limbs */
   1.355 + 
   1.356 +       /* pstr_size is the number of characters we read in pstr->mant
   1.357 +          to have at least ysize full limbs.
   1.358 +--- a/src/vasprintf.c	2013-03-13 16:37:37.000000000 +0100
   1.359 ++++ b/src/vasprintf.c	2014-12-31 14:56:02.688641997 +0100
   1.360 +@@ -884,14 +884,18 @@
   1.361 +            first digit, we want the exponent for radix two and the decimal
   1.362 +            point AFTER the first digit. */
   1.363 +         {
   1.364 +-          MPFR_ASSERTN (exp > MPFR_EMIN_MIN /4); /* possible overflow */
   1.365 ++          /* An integer overflow is normally not possible since MPFR_EXP_MIN
   1.366 ++             is twice as large as MPFR_EMIN_MIN. */
   1.367 ++          MPFR_ASSERTN (exp > (MPFR_EXP_MIN + 3) / 4);
   1.368 +           exp = (exp - 1) * 4;
   1.369 +         }
   1.370 +       else
   1.371 +         /* EXP is the exponent for decimal point BEFORE the first digit, we
   1.372 +            want the exponent for decimal point AFTER the first digit. */
   1.373 +         {
   1.374 +-          MPFR_ASSERTN (exp > MPFR_EMIN_MIN); /* possible overflow */
   1.375 ++          /* An integer overflow is normally not possible since MPFR_EXP_MIN
   1.376 ++             is twice as large as MPFR_EMIN_MIN. */
   1.377 ++          MPFR_ASSERTN (exp > MPFR_EXP_MIN);
   1.378 +           --exp;
   1.379 +         }
   1.380 +     }
   1.381 +@@ -1040,7 +1044,7 @@
   1.382 + }
   1.383 + 
   1.384 + /* Determine the different parts of the string representation of the regular
   1.385 +-   number P when SPEC.SPEC is 'e', 'E', 'g', or 'G'.
   1.386 ++   number P when spec.spec is 'e', 'E', 'g', or 'G'.
   1.387 +    DEC_INFO contains the previously computed exponent and string or is NULL.
   1.388 + 
   1.389 +    return -1 if some field > INT_MAX */
   1.390 +@@ -1167,7 +1171,7 @@
   1.391 + }
   1.392 + 
   1.393 + /* Determine the different parts of the string representation of the regular
   1.394 +-   number P when SPEC.SPEC is 'f', 'F', 'g', or 'G'.
   1.395 ++   number P when spec.spec is 'f', 'F', 'g', or 'G'.
   1.396 +    DEC_INFO contains the previously computed exponent and string or is NULL.
   1.397 + 
   1.398 +    return -1 if some field of number_parts is greater than INT_MAX */
   1.399 +@@ -1559,7 +1563,7 @@
   1.400 +             /* fractional part */
   1.401 +             {
   1.402 +               np->point = MPFR_DECIMAL_POINT;
   1.403 +-              np->fp_trailing_zeros = (spec.spec == 'g' && spec.spec == 'G') ?
   1.404 ++              np->fp_trailing_zeros = (spec.spec == 'g' || spec.spec == 'G') ?
   1.405 +                 spec.prec - 1 : spec.prec;
   1.406 +             }
   1.407 +           else if (spec.alt)
   1.408 +--- a/src/version.c	2013-03-13 16:37:34.000000000 +0100
   1.409 ++++ b/src/version.c	2014-12-31 14:56:02.688641997 +0100
   1.410 +@@ -25,5 +25,5 @@
   1.411 + const char *
   1.412 + mpfr_get_version (void)
   1.413 + {
   1.414 +-  return "3.1.2";
   1.415 ++  return "3.1.2-p11";
   1.416 + }
   1.417 +--- a/tests/tdiv.c	2013-03-13 16:37:44.000000000 +0100
   1.418 ++++ b/tests/tdiv.c	2014-12-31 14:56:02.689642010 +0100
   1.419 +@@ -1104,6 +1104,96 @@
   1.420 + #define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), randlimb () % 100, RANDS)
   1.421 + #include "tgeneric.c"
   1.422 + 
   1.423 ++static void
   1.424 ++test_extreme (void)
   1.425 ++{
   1.426 ++  mpfr_t x, y, z;
   1.427 ++  mpfr_exp_t emin, emax;
   1.428 ++  mpfr_prec_t p[4] = { 8, 32, 64, 256 };
   1.429 ++  int xi, yi, zi, j, r;
   1.430 ++  unsigned int flags, ex_flags;
   1.431 ++
   1.432 ++  emin = mpfr_get_emin ();
   1.433 ++  emax = mpfr_get_emax ();
   1.434 ++
   1.435 ++  mpfr_set_emin (MPFR_EMIN_MIN);
   1.436 ++  mpfr_set_emax (MPFR_EMAX_MAX);
   1.437 ++
   1.438 ++  for (xi = 0; xi < 4; xi++)
   1.439 ++    {
   1.440 ++      mpfr_init2 (x, p[xi]);
   1.441 ++      mpfr_setmax (x, MPFR_EMAX_MAX);
   1.442 ++      MPFR_ASSERTN (mpfr_check (x));
   1.443 ++      for (yi = 0; yi < 4; yi++)
   1.444 ++        {
   1.445 ++          mpfr_init2 (y, p[yi]);
   1.446 ++          mpfr_setmin (y, MPFR_EMIN_MIN);
   1.447 ++          for (j = 0; j < 2; j++)
   1.448 ++            {
   1.449 ++              MPFR_ASSERTN (mpfr_check (y));
   1.450 ++              for (zi = 0; zi < 4; zi++)
   1.451 ++                {
   1.452 ++                  mpfr_init2 (z, p[zi]);
   1.453 ++                  RND_LOOP (r)
   1.454 ++                    {
   1.455 ++                      mpfr_clear_flags ();
   1.456 ++                      mpfr_div (z, x, y, (mpfr_rnd_t) r);
   1.457 ++                      flags = __gmpfr_flags;
   1.458 ++                      MPFR_ASSERTN (mpfr_check (z));
   1.459 ++                      ex_flags = MPFR_FLAGS_OVERFLOW | MPFR_FLAGS_INEXACT;
   1.460 ++                      if (flags != ex_flags)
   1.461 ++                        {
   1.462 ++                          printf ("Bad flags in test_extreme on z = a/b"
   1.463 ++                                  " with %s and\n",
   1.464 ++                                  mpfr_print_rnd_mode ((mpfr_rnd_t) r));
   1.465 ++                          printf ("a = ");
   1.466 ++                          mpfr_dump (x);
   1.467 ++                          printf ("b = ");
   1.468 ++                          mpfr_dump (y);
   1.469 ++                          printf ("Expected flags:");
   1.470 ++                          flags_out (ex_flags);
   1.471 ++                          printf ("Got flags:     ");
   1.472 ++                          flags_out (flags);
   1.473 ++                          printf ("z = ");
   1.474 ++                          mpfr_dump (z);
   1.475 ++                          exit (1);
   1.476 ++                        }
   1.477 ++                      mpfr_clear_flags ();
   1.478 ++                      mpfr_div (z, y, x, (mpfr_rnd_t) r);
   1.479 ++                      flags = __gmpfr_flags;
   1.480 ++                      MPFR_ASSERTN (mpfr_check (z));
   1.481 ++                      ex_flags = MPFR_FLAGS_UNDERFLOW | MPFR_FLAGS_INEXACT;
   1.482 ++                      if (flags != ex_flags)
   1.483 ++                        {
   1.484 ++                          printf ("Bad flags in test_extreme on z = a/b"
   1.485 ++                                  " with %s and\n",
   1.486 ++                                  mpfr_print_rnd_mode ((mpfr_rnd_t) r));
   1.487 ++                          printf ("a = ");
   1.488 ++                          mpfr_dump (y);
   1.489 ++                          printf ("b = ");
   1.490 ++                          mpfr_dump (x);
   1.491 ++                          printf ("Expected flags:");
   1.492 ++                          flags_out (ex_flags);
   1.493 ++                          printf ("Got flags:     ");
   1.494 ++                          flags_out (flags);
   1.495 ++                          printf ("z = ");
   1.496 ++                          mpfr_dump (z);
   1.497 ++                          exit (1);
   1.498 ++                        }
   1.499 ++                    }
   1.500 ++                  mpfr_clear (z);
   1.501 ++                }  /* zi */
   1.502 ++              mpfr_nextabove (y);
   1.503 ++            }  /* j */
   1.504 ++          mpfr_clear (y);
   1.505 ++        }  /* yi */
   1.506 ++      mpfr_clear (x);
   1.507 ++    }  /* xi */
   1.508 ++
   1.509 ++  set_emin (emin);
   1.510 ++  set_emax (emax);
   1.511 ++}
   1.512 ++
   1.513 + int
   1.514 + main (int argc, char *argv[])
   1.515 + {
   1.516 +@@ -1130,6 +1220,7 @@
   1.517 +   test_20070603 ();
   1.518 +   test_20070628 ();
   1.519 +   test_generic (2, 800, 50);
   1.520 ++  test_extreme ();
   1.521 + 
   1.522 +   tests_end_mpfr ();
   1.523 +   return 0;
   1.524 +--- a/tests/texp.c	2013-03-13 16:37:44.000000000 +0100
   1.525 ++++ b/tests/texp.c	2014-12-31 14:56:02.689642010 +0100
   1.526 +@@ -150,6 +150,22 @@
   1.527 +       exit (1);
   1.528 +     }
   1.529 + 
   1.530 ++  mpfr_set_prec (x, 118);
   1.531 ++  mpfr_set_str_binary (x, "0.1110010100011101010000111110011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E-86");
   1.532 ++  mpfr_set_prec (y, 118);
   1.533 ++  mpfr_exp_2 (y, x, MPFR_RNDU);
   1.534 ++  mpfr_exp_3 (x, x, MPFR_RNDU);
   1.535 ++  if (mpfr_cmp (x, y))
   1.536 ++    {
   1.537 ++      printf ("mpfr_exp_2 and mpfr_exp_3 differ for prec=118\n");
   1.538 ++      printf ("mpfr_exp_2 gives ");
   1.539 ++      mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN);
   1.540 ++      printf ("\nmpfr_exp_3 gives ");
   1.541 ++      mpfr_out_str (stdout, 2, 0, x, MPFR_RNDN);
   1.542 ++      printf ("\n");
   1.543 ++      exit (1);
   1.544 ++    }
   1.545 ++
   1.546 +   mpfr_clear (x);
   1.547 +   mpfr_clear (y);
   1.548 +   return 0;
   1.549 +--- a/tests/tfits.c	2013-03-13 16:37:45.000000000 +0100
   1.550 ++++ b/tests/tfits.c	2014-12-31 14:56:02.689642010 +0100
   1.551 +@@ -33,155 +33,176 @@
   1.552 + #include "mpfr-intmax.h"
   1.553 + #include "mpfr-test.h"
   1.554 + 
   1.555 +-#define ERROR1 { printf("Initial error for x="); mpfr_dump(x); exit(1); }
   1.556 +-#define ERROR2 { printf("Error for x="); mpfr_dump(x); exit(1); }
   1.557 ++#define ERROR1(N)                                               \
   1.558 ++  do                                                            \
   1.559 ++    {                                                           \
   1.560 ++      printf("Error %d for rnd = %s and x = ", N,               \
   1.561 ++             mpfr_print_rnd_mode ((mpfr_rnd_t) r));             \
   1.562 ++      mpfr_dump(x);                                             \
   1.563 ++      exit(1);                                                  \
   1.564 ++    }                                                           \
   1.565 ++  while (0)
   1.566 + 
   1.567 + static void check_intmax (void);
   1.568 + 
   1.569 + int
   1.570 + main (void)
   1.571 + {
   1.572 +-  mpfr_t x;
   1.573 ++  mpfr_t x, y;
   1.574 ++  int i, r;
   1.575 + 
   1.576 +   tests_start_mpfr ();
   1.577 + 
   1.578 +   mpfr_init2 (x, 256);
   1.579 ++  mpfr_init2 (y, 8);
   1.580 + 
   1.581 +-  /* Check NAN */
   1.582 +-  mpfr_set_nan (x);
   1.583 +-  if (mpfr_fits_ulong_p (x, MPFR_RNDN))
   1.584 +-    ERROR1;
   1.585 +-  if (mpfr_fits_slong_p (x, MPFR_RNDN))
   1.586 +-    ERROR1;
   1.587 +-  if (mpfr_fits_uint_p (x, MPFR_RNDN))
   1.588 +-    ERROR1;
   1.589 +-  if (mpfr_fits_sint_p (x, MPFR_RNDN))
   1.590 +-    ERROR1;
   1.591 +-  if (mpfr_fits_ushort_p (x, MPFR_RNDN))
   1.592 +-    ERROR1;
   1.593 +-  if (mpfr_fits_sshort_p (x, MPFR_RNDN))
   1.594 +-    ERROR1;
   1.595 +-
   1.596 +-  /* Check INF */
   1.597 +-  mpfr_set_inf (x, 1);
   1.598 +-  if (mpfr_fits_ulong_p (x, MPFR_RNDN))
   1.599 +-    ERROR1;
   1.600 +-  if (mpfr_fits_slong_p (x, MPFR_RNDN))
   1.601 +-    ERROR1;
   1.602 +-  if (mpfr_fits_uint_p (x, MPFR_RNDN))
   1.603 +-    ERROR1;
   1.604 +-  if (mpfr_fits_sint_p (x, MPFR_RNDN))
   1.605 +-    ERROR1;
   1.606 +-  if (mpfr_fits_ushort_p (x, MPFR_RNDN))
   1.607 +-    ERROR1;
   1.608 +-  if (mpfr_fits_sshort_p (x, MPFR_RNDN))
   1.609 +-    ERROR1;
   1.610 +-
   1.611 +-  /* Check Zero */
   1.612 +-  MPFR_SET_ZERO (x);
   1.613 +-  if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
   1.614 +-    ERROR2;
   1.615 +-  if (!mpfr_fits_slong_p (x, MPFR_RNDN))
   1.616 +-    ERROR2;
   1.617 +-  if (!mpfr_fits_uint_p (x, MPFR_RNDN))
   1.618 +-    ERROR2;
   1.619 +-  if (!mpfr_fits_sint_p (x, MPFR_RNDN))
   1.620 +-    ERROR2;
   1.621 +-  if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
   1.622 +-    ERROR2;
   1.623 +-  if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
   1.624 +-    ERROR2;
   1.625 +-
   1.626 +-  /* Check small op */
   1.627 +-  mpfr_set_str1 (x, "1@-1");
   1.628 +-  if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
   1.629 +-    ERROR2;
   1.630 +-  if (!mpfr_fits_slong_p (x, MPFR_RNDN))
   1.631 +-    ERROR2;
   1.632 +-  if (!mpfr_fits_uint_p (x, MPFR_RNDN))
   1.633 +-    ERROR2;
   1.634 +-  if (!mpfr_fits_sint_p (x, MPFR_RNDN))
   1.635 +-    ERROR2;
   1.636 +-  if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
   1.637 +-    ERROR2;
   1.638 +-  if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
   1.639 +-    ERROR2;
   1.640 +-
   1.641 +-  /* Check 17 */
   1.642 +-  mpfr_set_ui (x, 17, MPFR_RNDN);
   1.643 +-  if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
   1.644 +-    ERROR2;
   1.645 +-  if (!mpfr_fits_slong_p (x, MPFR_RNDN))
   1.646 +-    ERROR2;
   1.647 +-  if (!mpfr_fits_uint_p (x, MPFR_RNDN))
   1.648 +-    ERROR2;
   1.649 +-  if (!mpfr_fits_sint_p (x, MPFR_RNDN))
   1.650 +-    ERROR2;
   1.651 +-  if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
   1.652 +-    ERROR2;
   1.653 +-  if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
   1.654 +-    ERROR2;
   1.655 +-
   1.656 +-  /* Check all other values */
   1.657 +-  mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
   1.658 +-  mpfr_mul_2exp (x, x, 1, MPFR_RNDN);
   1.659 +-  if (mpfr_fits_ulong_p (x, MPFR_RNDN))
   1.660 +-    ERROR1;
   1.661 +-  if (mpfr_fits_slong_p (x, MPFR_RNDN))
   1.662 +-    ERROR1;
   1.663 +-  mpfr_mul_2exp (x, x, 40, MPFR_RNDN);
   1.664 +-  if (mpfr_fits_ulong_p (x, MPFR_RNDN))
   1.665 +-    ERROR1;
   1.666 +-  if (mpfr_fits_uint_p (x, MPFR_RNDN))
   1.667 +-    ERROR1;
   1.668 +-  if (mpfr_fits_sint_p (x, MPFR_RNDN))
   1.669 +-    ERROR1;
   1.670 +-  if (mpfr_fits_ushort_p (x, MPFR_RNDN))
   1.671 +-    ERROR1;
   1.672 +-  if (mpfr_fits_sshort_p (x, MPFR_RNDN))
   1.673 +-    ERROR1;
   1.674 +-
   1.675 +-  mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
   1.676 +-  if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
   1.677 +-    ERROR2;
   1.678 +-  mpfr_set_ui (x, LONG_MAX, MPFR_RNDN);
   1.679 +-  if (!mpfr_fits_slong_p (x, MPFR_RNDN))
   1.680 +-    ERROR2;
   1.681 +-  mpfr_set_ui (x, UINT_MAX, MPFR_RNDN);
   1.682 +-  if (!mpfr_fits_uint_p (x, MPFR_RNDN))
   1.683 +-    ERROR2;
   1.684 +-  mpfr_set_ui (x, INT_MAX, MPFR_RNDN);
   1.685 +-  if (!mpfr_fits_sint_p (x, MPFR_RNDN))
   1.686 +-    ERROR2;
   1.687 +-  mpfr_set_ui (x, USHRT_MAX, MPFR_RNDN);
   1.688 +-  if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
   1.689 +-    ERROR2;
   1.690 +-  mpfr_set_ui (x, SHRT_MAX, MPFR_RNDN);
   1.691 +-  if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
   1.692 +-    ERROR2;
   1.693 +-
   1.694 +-  mpfr_set_si (x, 1, MPFR_RNDN);
   1.695 +-  if (!mpfr_fits_sint_p (x, MPFR_RNDN))
   1.696 +-    ERROR2;
   1.697 +-  if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
   1.698 +-    ERROR2;
   1.699 +-
   1.700 +-  /* Check negative value */
   1.701 +-  mpfr_set_si (x, -1, MPFR_RNDN);
   1.702 +-  if (!mpfr_fits_sint_p (x, MPFR_RNDN))
   1.703 +-    ERROR2;
   1.704 +-  if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
   1.705 +-    ERROR2;
   1.706 +-  if (!mpfr_fits_slong_p (x, MPFR_RNDN))
   1.707 +-    ERROR2;
   1.708 +-  if (mpfr_fits_uint_p (x, MPFR_RNDN))
   1.709 +-    ERROR1;
   1.710 +-  if (mpfr_fits_ushort_p (x, MPFR_RNDN))
   1.711 +-    ERROR1;
   1.712 +-  if (mpfr_fits_ulong_p (x, MPFR_RNDN))
   1.713 +-    ERROR1;
   1.714 ++  RND_LOOP (r)
   1.715 ++    {
   1.716 ++
   1.717 ++      /* Check NAN */
   1.718 ++      mpfr_set_nan (x);
   1.719 ++      if (mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
   1.720 ++        ERROR1 (1);
   1.721 ++      if (mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
   1.722 ++        ERROR1 (2);
   1.723 ++      if (mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
   1.724 ++        ERROR1 (3);
   1.725 ++      if (mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
   1.726 ++        ERROR1 (4);
   1.727 ++      if (mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
   1.728 ++        ERROR1 (5);
   1.729 ++      if (mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
   1.730 ++        ERROR1 (6);
   1.731 ++
   1.732 ++      /* Check INF */
   1.733 ++      mpfr_set_inf (x, 1);
   1.734 ++      if (mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
   1.735 ++        ERROR1 (7);
   1.736 ++      if (mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
   1.737 ++        ERROR1 (8);
   1.738 ++      if (mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
   1.739 ++        ERROR1 (9);
   1.740 ++      if (mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
   1.741 ++        ERROR1 (10);
   1.742 ++      if (mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
   1.743 ++        ERROR1 (11);
   1.744 ++      if (mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
   1.745 ++        ERROR1 (12);
   1.746 ++
   1.747 ++      /* Check Zero */
   1.748 ++      MPFR_SET_ZERO (x);
   1.749 ++      if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
   1.750 ++        ERROR1 (13);
   1.751 ++      if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
   1.752 ++        ERROR1 (14);
   1.753 ++      if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
   1.754 ++        ERROR1 (15);
   1.755 ++      if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
   1.756 ++        ERROR1 (16);
   1.757 ++      if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
   1.758 ++        ERROR1 (17);
   1.759 ++      if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
   1.760 ++        ERROR1 (18);
   1.761 ++
   1.762 ++      /* Check small positive op */
   1.763 ++      mpfr_set_str1 (x, "1@-1");
   1.764 ++      if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
   1.765 ++        ERROR1 (19);
   1.766 ++      if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
   1.767 ++        ERROR1 (20);
   1.768 ++      if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
   1.769 ++        ERROR1 (21);
   1.770 ++      if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
   1.771 ++        ERROR1 (22);
   1.772 ++      if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
   1.773 ++        ERROR1 (23);
   1.774 ++      if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
   1.775 ++        ERROR1 (24);
   1.776 ++
   1.777 ++      /* Check 17 */
   1.778 ++      mpfr_set_ui (x, 17, MPFR_RNDN);
   1.779 ++      if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
   1.780 ++        ERROR1 (25);
   1.781 ++      if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
   1.782 ++        ERROR1 (26);
   1.783 ++      if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
   1.784 ++        ERROR1 (27);
   1.785 ++      if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
   1.786 ++        ERROR1 (28);
   1.787 ++      if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
   1.788 ++        ERROR1 (29);
   1.789 ++      if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
   1.790 ++        ERROR1 (30);
   1.791 ++
   1.792 ++      /* Check all other values */
   1.793 ++      mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
   1.794 ++      mpfr_mul_2exp (x, x, 1, MPFR_RNDN);
   1.795 ++      if (mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
   1.796 ++        ERROR1 (31);
   1.797 ++      if (mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
   1.798 ++        ERROR1 (32);
   1.799 ++      mpfr_mul_2exp (x, x, 40, MPFR_RNDN);
   1.800 ++      if (mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
   1.801 ++        ERROR1 (33);
   1.802 ++      if (mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
   1.803 ++        ERROR1 (34);
   1.804 ++      if (mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
   1.805 ++        ERROR1 (35);
   1.806 ++      if (mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
   1.807 ++        ERROR1 (36);
   1.808 ++      if (mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
   1.809 ++        ERROR1 (37);
   1.810 ++
   1.811 ++      mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
   1.812 ++      if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
   1.813 ++        ERROR1 (38);
   1.814 ++      mpfr_set_ui (x, LONG_MAX, MPFR_RNDN);
   1.815 ++      if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
   1.816 ++        ERROR1 (39);
   1.817 ++      mpfr_set_ui (x, UINT_MAX, MPFR_RNDN);
   1.818 ++      if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
   1.819 ++        ERROR1 (40);
   1.820 ++      mpfr_set_ui (x, INT_MAX, MPFR_RNDN);
   1.821 ++      if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
   1.822 ++        ERROR1 (41);
   1.823 ++      mpfr_set_ui (x, USHRT_MAX, MPFR_RNDN);
   1.824 ++      if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
   1.825 ++        ERROR1 (42);
   1.826 ++      mpfr_set_ui (x, SHRT_MAX, MPFR_RNDN);
   1.827 ++      if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
   1.828 ++        ERROR1 (43);
   1.829 ++
   1.830 ++      mpfr_set_si (x, 1, MPFR_RNDN);
   1.831 ++      if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
   1.832 ++        ERROR1 (44);
   1.833 ++      if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
   1.834 ++        ERROR1 (45);
   1.835 ++
   1.836 ++      /* Check negative op */
   1.837 ++      for (i = 1; i <= 4; i++)
   1.838 ++        {
   1.839 ++          int inv;
   1.840 ++
   1.841 ++          mpfr_set_si_2exp (x, -i, -2, MPFR_RNDN);
   1.842 ++          mpfr_rint (y, x, (mpfr_rnd_t) r);
   1.843 ++          inv = MPFR_NOTZERO (y);
   1.844 ++          if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r) ^ inv)
   1.845 ++            ERROR1 (46);
   1.846 ++          if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
   1.847 ++            ERROR1 (47);
   1.848 ++          if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r) ^ inv)
   1.849 ++            ERROR1 (48);
   1.850 ++          if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
   1.851 ++            ERROR1 (49);
   1.852 ++          if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r) ^ inv)
   1.853 ++            ERROR1 (50);
   1.854 ++          if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
   1.855 ++            ERROR1 (51);
   1.856 ++        }
   1.857 ++    }
   1.858 + 
   1.859 +   mpfr_clear (x);
   1.860 ++  mpfr_clear (y);
   1.861 + 
   1.862 +   check_intmax ();
   1.863 + 
   1.864 +@@ -189,85 +210,98 @@
   1.865 +   return 0;
   1.866 + }
   1.867 + 
   1.868 +-static void check_intmax (void)
   1.869 ++static void
   1.870 ++check_intmax (void)
   1.871 + {
   1.872 + #ifdef _MPFR_H_HAVE_INTMAX_T
   1.873 +-  mpfr_t x;
   1.874 ++  mpfr_t x, y;
   1.875 ++  int i, r;
   1.876 + 
   1.877 +-  mpfr_init2 (x, sizeof (uintmax_t)*CHAR_BIT);
   1.878 ++  mpfr_init2 (x, sizeof (uintmax_t) * CHAR_BIT);
   1.879 ++  mpfr_init2 (y, 8);
   1.880 + 
   1.881 +-  /* Check NAN */
   1.882 +-  mpfr_set_nan (x);
   1.883 +-  if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
   1.884 +-    ERROR1;
   1.885 +-  if (mpfr_fits_intmax_p (x, MPFR_RNDN))
   1.886 +-    ERROR1;
   1.887 +-
   1.888 +-  /* Check INF */
   1.889 +-  mpfr_set_inf (x, 1);
   1.890 +-  if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
   1.891 +-    ERROR1;
   1.892 +-  if (mpfr_fits_intmax_p (x, MPFR_RNDN))
   1.893 +-    ERROR1;
   1.894 +-
   1.895 +-  /* Check Zero */
   1.896 +-  MPFR_SET_ZERO (x);
   1.897 +-  if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
   1.898 +-    ERROR2;
   1.899 +-  if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
   1.900 +-    ERROR2;
   1.901 +-
   1.902 +-  /* Check small op */
   1.903 +-  mpfr_set_str1 (x, "1@-1");
   1.904 +-  if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
   1.905 +-    ERROR2;
   1.906 +-  if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
   1.907 +-    ERROR2;
   1.908 +-
   1.909 +-  /* Check 17 */
   1.910 +-  mpfr_set_ui (x, 17, MPFR_RNDN);
   1.911 +-  if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
   1.912 +-    ERROR2;
   1.913 +-  if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
   1.914 +-    ERROR2;
   1.915 +-
   1.916 +-  /* Check hugest */
   1.917 +-  mpfr_set_ui_2exp (x, 42, sizeof (uintmax_t) * 32, MPFR_RNDN);
   1.918 +-  if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
   1.919 +-    ERROR1;
   1.920 +-  if (mpfr_fits_intmax_p (x, MPFR_RNDN))
   1.921 +-    ERROR1;
   1.922 +-
   1.923 +-  /* Check all other values */
   1.924 +-  mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
   1.925 +-  mpfr_add_ui (x, x, 1, MPFR_RNDN);
   1.926 +-  if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
   1.927 +-    ERROR1;
   1.928 +-  mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
   1.929 +-  if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
   1.930 +-    ERROR2;
   1.931 +-  mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
   1.932 +-  mpfr_add_ui (x, x, 1, MPFR_RNDN);
   1.933 +-  if (mpfr_fits_intmax_p (x, MPFR_RNDN))
   1.934 +-    ERROR1;
   1.935 +-  mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
   1.936 +-  if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
   1.937 +-    ERROR2;
   1.938 +-  mpfr_set_sj (x, MPFR_INTMAX_MIN, MPFR_RNDN);
   1.939 +-  if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
   1.940 +-    ERROR2;
   1.941 +-  mpfr_sub_ui (x, x, 1, MPFR_RNDN);
   1.942 +-  if (mpfr_fits_intmax_p (x, MPFR_RNDN))
   1.943 +-    ERROR1;
   1.944 +-
   1.945 +-  /* Check negative value */
   1.946 +-  mpfr_set_si (x, -1, MPFR_RNDN);
   1.947 +-  if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
   1.948 +-    ERROR2;
   1.949 +-  if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
   1.950 +-    ERROR1;
   1.951 ++  RND_LOOP (r)
   1.952 ++    {
   1.953 ++      /* Check NAN */
   1.954 ++      mpfr_set_nan (x);
   1.955 ++      if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
   1.956 ++        ERROR1 (52);
   1.957 ++      if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
   1.958 ++        ERROR1 (53);
   1.959 ++
   1.960 ++      /* Check INF */
   1.961 ++      mpfr_set_inf (x, 1);
   1.962 ++      if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
   1.963 ++        ERROR1 (54);
   1.964 ++      if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
   1.965 ++        ERROR1 (55);
   1.966 ++
   1.967 ++      /* Check Zero */
   1.968 ++      MPFR_SET_ZERO (x);
   1.969 ++      if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
   1.970 ++        ERROR1 (56);
   1.971 ++      if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
   1.972 ++        ERROR1 (57);
   1.973 ++
   1.974 ++      /* Check positive small op */
   1.975 ++      mpfr_set_str1 (x, "1@-1");
   1.976 ++      if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
   1.977 ++        ERROR1 (58);
   1.978 ++      if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
   1.979 ++        ERROR1 (59);
   1.980 ++
   1.981 ++      /* Check 17 */
   1.982 ++      mpfr_set_ui (x, 17, MPFR_RNDN);
   1.983 ++      if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
   1.984 ++        ERROR1 (60);
   1.985 ++      if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
   1.986 ++        ERROR1 (61);
   1.987 ++
   1.988 ++      /* Check hugest */
   1.989 ++      mpfr_set_ui_2exp (x, 42, sizeof (uintmax_t) * 32, MPFR_RNDN);
   1.990 ++      if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
   1.991 ++        ERROR1 (62);
   1.992 ++      if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
   1.993 ++        ERROR1 (63);
   1.994 ++
   1.995 ++      /* Check all other values */
   1.996 ++      mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
   1.997 ++      mpfr_add_ui (x, x, 1, MPFR_RNDN);
   1.998 ++      if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
   1.999 ++        ERROR1 (64);
  1.1000 ++      mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
  1.1001 ++      if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
  1.1002 ++        ERROR1 (65);
  1.1003 ++      mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
  1.1004 ++      mpfr_add_ui (x, x, 1, MPFR_RNDN);
  1.1005 ++      if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
  1.1006 ++        ERROR1 (66);
  1.1007 ++      mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
  1.1008 ++      if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
  1.1009 ++        ERROR1 (67);
  1.1010 ++      mpfr_set_sj (x, MPFR_INTMAX_MIN, MPFR_RNDN);
  1.1011 ++      if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
  1.1012 ++        ERROR1 (68);
  1.1013 ++      mpfr_sub_ui (x, x, 1, MPFR_RNDN);
  1.1014 ++      if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
  1.1015 ++        ERROR1 (69);
  1.1016 ++
  1.1017 ++      /* Check negative op */
  1.1018 ++      for (i = 1; i <= 4; i++)
  1.1019 ++        {
  1.1020 ++          int inv;
  1.1021 ++
  1.1022 ++          mpfr_set_si_2exp (x, -i, -2, MPFR_RNDN);
  1.1023 ++          mpfr_rint (y, x, (mpfr_rnd_t) r);
  1.1024 ++          inv = MPFR_NOTZERO (y);
  1.1025 ++          if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r) ^ inv)
  1.1026 ++            ERROR1 (70);
  1.1027 ++          if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
  1.1028 ++            ERROR1 (71);
  1.1029 ++        }
  1.1030 ++    }
  1.1031 + 
  1.1032 +   mpfr_clear (x);
  1.1033 ++  mpfr_clear (y);
  1.1034 + #endif
  1.1035 + }
  1.1036 +-
  1.1037 +--- a/tests/tget_flt.c	2013-03-13 16:37:44.000000000 +0100
  1.1038 ++++ b/tests/tget_flt.c	2014-12-31 14:56:02.690642023 +0100
  1.1039 +@@ -28,9 +28,17 @@
  1.1040 + main (void)
  1.1041 + {
  1.1042 +   mpfr_t x, y;
  1.1043 +-  float f, g, infp;
  1.1044 ++  float f, g;
  1.1045 +   int i;
  1.1046 ++#if !defined(MPFR_ERRDIVZERO)
  1.1047 ++  float infp;
  1.1048 ++#endif
  1.1049 + 
  1.1050 ++  tests_start_mpfr ();
  1.1051 ++
  1.1052 ++#if !defined(MPFR_ERRDIVZERO)
  1.1053 ++  /* The definition of DBL_POS_INF involves a division by 0. This makes
  1.1054 ++     "clang -O2 -fsanitize=undefined -fno-sanitize-recover" fail. */
  1.1055 +   infp = (float) DBL_POS_INF;
  1.1056 +   if (infp * 0.5 != infp)
  1.1057 +     {
  1.1058 +@@ -38,8 +46,7 @@
  1.1059 +       fprintf (stderr, "(this is probably a compiler bug, please report)\n");
  1.1060 +       exit (1);
  1.1061 +     }
  1.1062 +-
  1.1063 +-  tests_start_mpfr ();
  1.1064 ++#endif
  1.1065 + 
  1.1066 +   mpfr_init2 (x, 24);
  1.1067 +   mpfr_init2 (y, 24);
  1.1068 +@@ -353,6 +360,7 @@
  1.1069 +       printf ("expected %.8e, got %.8e\n", g, f);
  1.1070 +       exit (1);
  1.1071 +     }
  1.1072 ++#if !defined(MPFR_ERRDIVZERO)
  1.1073 +   f = mpfr_get_flt (x, MPFR_RNDN); /* first round to 2^128 (even rule),
  1.1074 +                                       thus we should get +Inf */
  1.1075 +   g = infp;
  1.1076 +@@ -376,6 +384,7 @@
  1.1077 +       printf ("expected %.8e, got %.8e\n", g, f);
  1.1078 +       exit (1);
  1.1079 +     }
  1.1080 ++#endif
  1.1081 + 
  1.1082 +   mpfr_clear (x);
  1.1083 +   mpfr_clear (y);
  1.1084 +--- a/tests/tset_ld.c	2013-03-13 16:37:44.000000000 +0100
  1.1085 ++++ b/tests/tset_ld.c	2014-12-31 14:56:02.690642023 +0100
  1.1086 +@@ -47,8 +47,11 @@
  1.1087 + static int
  1.1088 + Isnan_ld (long double d)
  1.1089 + {
  1.1090 +-  double e = (double) d;
  1.1091 +-  if (DOUBLE_ISNAN (e))
  1.1092 ++  /* Do not convert d to double as this can give an overflow, which
  1.1093 ++     may confuse compilers without IEEE 754 support (such as clang
  1.1094 ++     -fsanitize=undefined), or trigger a trap if enabled.
  1.1095 ++     The DOUBLE_ISNAN macro should work fine on long double. */
  1.1096 ++  if (DOUBLE_ISNAN (d))
  1.1097 +     return 1;
  1.1098 +   LONGDOUBLE_NAN_ACTION (d, goto yes);
  1.1099 +   return 0;
  1.1100 +--- a/tests/tsprintf.c	2013-03-13 16:37:44.000000000 +0100
  1.1101 ++++ b/tests/tsprintf.c	2014-12-31 14:56:02.690642023 +0100
  1.1102 +@@ -456,10 +456,16 @@
  1.1103 +   check_sprintf ("1.999900  ", "%-#10.7RG", x);
  1.1104 +   check_sprintf ("1.9999    ", "%-10.7RG", x);
  1.1105 +   mpfr_set_ui (x, 1, MPFR_RNDN);
  1.1106 ++  check_sprintf ("1.", "%#.1Rg", x);
  1.1107 ++  check_sprintf ("1.   ", "%-#5.1Rg", x);
  1.1108 ++  check_sprintf ("  1.0", "%#5.2Rg", x);
  1.1109 +   check_sprintf ("1.00000000000000000000000000000", "%#.30Rg", x);
  1.1110 +   check_sprintf ("1", "%.30Rg", x);
  1.1111 +   mpfr_set_ui (x, 0, MPFR_RNDN);
  1.1112 +-  check_sprintf ("0.000000000000000000000000000000", "%#.30Rg", x);
  1.1113 ++  check_sprintf ("0.", "%#.1Rg", x);
  1.1114 ++  check_sprintf ("0.   ", "%-#5.1Rg", x);
  1.1115 ++  check_sprintf ("  0.0", "%#5.2Rg", x);
  1.1116 ++  check_sprintf ("0.00000000000000000000000000000", "%#.30Rg", x);
  1.1117 +   check_sprintf ("0", "%.30Rg", x);
  1.1118 + 
  1.1119 +   /* following tests with precision 53 bits */
  1.1120 +@@ -1178,6 +1184,69 @@
  1.1121 +   check_emax_aux (MPFR_EMAX_MAX);
  1.1122 + }
  1.1123 + 
  1.1124 ++static void
  1.1125 ++check_emin_aux (mpfr_exp_t e)
  1.1126 ++{
  1.1127 ++  mpfr_t x;
  1.1128 ++  char *s1, s2[256];
  1.1129 ++  int i;
  1.1130 ++  mpfr_exp_t emin;
  1.1131 ++  mpz_t ee;
  1.1132 ++
  1.1133 ++  MPFR_ASSERTN (e >= LONG_MIN);
  1.1134 ++  emin = mpfr_get_emin ();
  1.1135 ++  set_emin (e);
  1.1136 ++
  1.1137 ++  mpfr_init2 (x, 16);
  1.1138 ++  mpz_init (ee);
  1.1139 ++
  1.1140 ++  mpfr_setmin (x, e);
  1.1141 ++  mpz_set_si (ee, e);
  1.1142 ++  mpz_sub_ui (ee, ee, 1);
  1.1143 ++
  1.1144 ++  i = mpfr_asprintf (&s1, "%Ra", x);
  1.1145 ++  MPFR_ASSERTN (i > 0);
  1.1146 ++
  1.1147 ++  gmp_snprintf (s2, 256, "0x1p%Zd", ee);
  1.1148 ++
  1.1149 ++  if (strcmp (s1, s2) != 0)
  1.1150 ++    {
  1.1151 ++      printf ("Error in check_emin_aux for emin = %ld\n", (long) e);
  1.1152 ++      printf ("Expected %s\n", s2);
  1.1153 ++      printf ("Got      %s\n", s1);
  1.1154 ++      exit (1);
  1.1155 ++    }
  1.1156 ++
  1.1157 ++  mpfr_free_str (s1);
  1.1158 ++
  1.1159 ++  i = mpfr_asprintf (&s1, "%Rb", x);
  1.1160 ++  MPFR_ASSERTN (i > 0);
  1.1161 ++
  1.1162 ++  gmp_snprintf (s2, 256, "1p%Zd", ee);
  1.1163 ++
  1.1164 ++  if (strcmp (s1, s2) != 0)
  1.1165 ++    {
  1.1166 ++      printf ("Error in check_emin_aux for emin = %ld\n", (long) e);
  1.1167 ++      printf ("Expected %s\n", s2);
  1.1168 ++      printf ("Got      %s\n", s1);
  1.1169 ++      exit (1);
  1.1170 ++    }
  1.1171 ++
  1.1172 ++  mpfr_free_str (s1);
  1.1173 ++
  1.1174 ++  mpfr_clear (x);
  1.1175 ++  mpz_clear (ee);
  1.1176 ++  set_emin (emin);
  1.1177 ++}
  1.1178 ++
  1.1179 ++static void
  1.1180 ++check_emin (void)
  1.1181 ++{
  1.1182 ++  check_emin_aux (-15);
  1.1183 ++  check_emin_aux (mpfr_get_emin ());
  1.1184 ++  check_emin_aux (MPFR_EMIN_MIN);
  1.1185 ++}
  1.1186 ++
  1.1187 + int
  1.1188 + main (int argc, char **argv)
  1.1189 + {
  1.1190 +@@ -1197,6 +1266,7 @@
  1.1191 +   decimal ();
  1.1192 +   mixed ();
  1.1193 +   check_emax ();
  1.1194 ++  check_emin ();
  1.1195 + 
  1.1196 + #if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)
  1.1197 +   locale_da_DK ();
  1.1198 +--- a/VERSION	2013-03-13 16:37:28.000000000 +0100
  1.1199 ++++ b/VERSION	2014-12-31 14:56:02.690642023 +0100
  1.1200 +@@ -1 +1 @@
  1.1201 +-3.1.2
  1.1202 ++3.1.2-p11