wok-next view mpfr/stuff/mpfr-3.1.2-upstream_fixes-3.patch @ rev 18918
Add brotli
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Feb 24 16:36:21 2016 +0100 (2016-02-24) |
parents | |
children |
line source
1 Submitted By: Bruce Dubbs <bdubbs_at_linuxfromscratch_dot_org>
2 Updated By: Armin K. <krejzi at email dot com>
3 Date: 2015-02-06
4 Initial Package Version: 3.1.2
5 Upstream Status: Already in upstream patch repo
6 Origin: Upstream
7 Description: This patch contains patches for several bugs in MPFR.
8 Note that the patch for configure.ac has been
9 removed to prevent unneeded regeneration of build
10 files.
11 See http://www.mpfr.org/mpfr-current/allpatches
13 --- a/PATCHES 2013-03-13 16:37:38.000000000 +0100
14 +++ b/PATCHES 2014-12-31 14:56:02.685641958 +0100
15 @@ -0,0 +1,11 @@
16 +strtofr
17 +vasprintf
18 +div-overflow
19 +gmp6-compat
20 +exp3
21 +li2-return
22 +custom_init_set
23 +printf-alt0
24 +clang-divby0
25 +fits-smallneg
26 +exp_2
27 --- a/src/div.c 2013-03-13 16:37:33.000000000 +0100
28 +++ b/src/div.c 2014-12-31 14:56:02.686641971 +0100
29 @@ -750,7 +750,9 @@
30 truncate_check_qh:
31 if (qh)
32 {
33 - qexp ++;
34 + if (MPFR_LIKELY (qexp < MPFR_EXP_MAX))
35 + qexp ++;
36 + /* else qexp is now incorrect, but one will still get an overflow */
37 q0p[q0size - 1] = MPFR_LIMB_HIGHBIT;
38 }
39 goto truncate;
40 @@ -765,7 +767,9 @@
41 inex = 1; /* always here */
42 if (mpn_add_1 (q0p, q0p, q0size, MPFR_LIMB_ONE << sh))
43 {
44 - qexp ++;
45 + if (MPFR_LIKELY (qexp < MPFR_EXP_MAX))
46 + qexp ++;
47 + /* else qexp is now incorrect, but one will still get an overflow */
48 q0p[q0size - 1] = MPFR_LIMB_HIGHBIT;
49 }
51 --- a/src/exp_2.c 2013-03-13 16:37:28.000000000 +0100
52 +++ b/src/exp_2.c 2014-12-31 14:56:02.686641971 +0100
53 @@ -204,7 +204,7 @@
54 for (k = 0; k < K; k++)
55 {
56 mpz_mul (ss, ss, ss);
57 - exps <<= 1;
58 + exps *= 2;
59 exps += mpz_normalize (ss, ss, q);
60 }
61 mpfr_set_z (s, ss, MPFR_RNDN);
62 --- a/src/exp3.c 2013-03-13 16:37:34.000000000 +0100
63 +++ b/src/exp3.c 2014-12-31 14:56:02.686641971 +0100
64 @@ -283,7 +283,7 @@
65 }
66 }
68 - if (mpfr_can_round (shift_x > 0 ? t : tmp, realprec, MPFR_RNDD, MPFR_RNDZ,
69 + if (mpfr_can_round (shift_x > 0 ? t : tmp, realprec, MPFR_RNDN, MPFR_RNDZ,
70 MPFR_PREC(y) + (rnd_mode == MPFR_RNDN)))
71 {
72 inexact = mpfr_set (y, shift_x > 0 ? t : tmp, rnd_mode);
73 --- a/src/fits_u.h 2013-03-13 16:37:35.000000000 +0100
74 +++ b/src/fits_u.h 2014-12-31 14:56:02.686641971 +0100
75 @@ -32,17 +32,20 @@
76 int res;
78 if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f)))
79 - /* Zero always fit */
80 - return MPFR_IS_ZERO (f) ? 1 : 0;
81 - else if (MPFR_IS_NEG (f))
82 - /* Negative numbers don't fit */
83 - return 0;
84 - /* now it fits if
85 - (a) f <= MAXIMUM
86 - (b) round(f, prec(slong), rnd) <= MAXIMUM */
87 + return MPFR_IS_ZERO (f) ? 1 : 0; /* Zero always fits */
89 e = MPFR_GET_EXP (f);
91 + if (MPFR_IS_NEG (f))
92 + return e >= 1 ? 0 /* f <= -1 does not fit */
93 + : rnd != MPFR_RNDN ? MPFR_IS_LIKE_RNDU (rnd, -1) /* directed mode */
94 + : e < 0 ? 1 /* f > -1/2 fits in MPFR_RNDN */
95 + : mpfr_powerof2_raw(f); /* -1/2 fits, -1 < f < -1/2 don't */
96 +
97 + /* Now it fits if
98 + (a) f <= MAXIMUM
99 + (b) round(f, prec(slong), rnd) <= MAXIMUM */
100 +
101 /* first compute prec(MAXIMUM); fits in an int */
102 for (s = MAXIMUM, prec = 0; s != 0; s /= 2, prec ++);
104 --- a/src/fits_uintmax.c 2013-03-13 16:37:33.000000000 +0100
105 +++ b/src/fits_uintmax.c 2014-12-31 14:56:02.686641971 +0100
106 @@ -27,51 +27,19 @@
107 #include "mpfr-intmax.h"
108 #include "mpfr-impl.h"
110 -#ifdef _MPFR_H_HAVE_INTMAX_T
111 -
112 -/* We can't use fits_u.h <= mpfr_cmp_ui */
113 -int
114 -mpfr_fits_uintmax_p (mpfr_srcptr f, mpfr_rnd_t rnd)
115 -{
116 - mpfr_exp_t e;
117 - int prec;
118 - uintmax_t s;
119 - mpfr_t x;
120 - int res;
121 -
122 - if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f)))
123 - /* Zero always fit */
124 - return MPFR_IS_ZERO (f) ? 1 : 0;
125 - else if (MPFR_IS_NEG (f))
126 - /* Negative numbers don't fit */
127 - return 0;
128 - /* now it fits if
129 - (a) f <= MAXIMUM
130 - (b) round(f, prec(slong), rnd) <= MAXIMUM */
131 -
132 - e = MPFR_GET_EXP (f);
133 +/* Note: though mpfr-impl.h is included in fits_u.h, we also include it
134 + above so that it gets included even when _MPFR_H_HAVE_INTMAX_T is not
135 + defined; this is necessary to avoid an empty translation unit, which
136 + is forbidden by ISO C. Without this, a failing test can be reproduced
137 + by creating an invalid stdint.h somewhere in the default include path
138 + and by compiling MPFR with "gcc -ansi -pedantic-errors". */
140 - /* first compute prec(MAXIMUM); fits in an int */
141 - for (s = MPFR_UINTMAX_MAX, prec = 0; s != 0; s /= 2, prec ++);
142 -
143 - /* MAXIMUM needs prec bits, i.e. MAXIMUM = 2^prec - 1 */
144 -
145 - /* if e <= prec - 1, then f < 2^(prec-1) < MAXIMUM */
146 - if (e <= prec - 1)
147 - return 1;
148 -
149 - /* if e >= prec + 1, then f >= 2^prec > MAXIMUM */
150 - if (e >= prec + 1)
151 - return 0;
152 +#ifdef _MPFR_H_HAVE_INTMAX_T
154 - MPFR_ASSERTD (e == prec);
155 +#define FUNCTION mpfr_fits_uintmax_p
156 +#define MAXIMUM MPFR_UINTMAX_MAX
157 +#define TYPE uintmax_t
159 - /* hard case: first round to prec bits, then check */
160 - mpfr_init2 (x, prec);
161 - mpfr_set (x, f, rnd);
162 - res = MPFR_GET_EXP (x) == e;
163 - mpfr_clear (x);
164 - return res;
165 -}
166 +#include "fits_u.h"
168 #endif
169 --- a/src/init2.c 2013-03-13 16:37:32.000000000 +0100
170 +++ b/src/init2.c 2014-12-31 14:56:02.686641971 +0100
171 @@ -30,11 +30,11 @@
173 /* Check if we can represent the number of limbs
174 * associated to the maximum of mpfr_prec_t*/
175 - MPFR_ASSERTN( MP_SIZE_T_MAX >= (MPFR_PREC_MAX/BYTES_PER_MP_LIMB) );
176 + MPFR_ASSERTN( MP_SIZE_T_MAX >= (MPFR_PREC_MAX/MPFR_BYTES_PER_MP_LIMB) );
178 - /* Check for correct GMP_NUMB_BITS and BYTES_PER_MP_LIMB */
179 - MPFR_ASSERTN( GMP_NUMB_BITS == BYTES_PER_MP_LIMB * CHAR_BIT
180 - && sizeof(mp_limb_t) == BYTES_PER_MP_LIMB );
181 + /* Check for correct GMP_NUMB_BITS and MPFR_BYTES_PER_MP_LIMB */
182 + MPFR_ASSERTN( GMP_NUMB_BITS == MPFR_BYTES_PER_MP_LIMB * CHAR_BIT
183 + && sizeof(mp_limb_t) == MPFR_BYTES_PER_MP_LIMB );
185 MPFR_ASSERTN (mp_bits_per_limb == GMP_NUMB_BITS);
187 --- a/src/li2.c 2013-03-13 16:37:32.000000000 +0100
188 +++ b/src/li2.c 2014-12-31 14:56:02.686641971 +0100
189 @@ -630,5 +630,5 @@
190 return mpfr_check_range (y, inexact, rnd_mode);
191 }
193 - MPFR_ASSERTN (0); /* should never reach this point */
194 + MPFR_RET_NEVER_GO_HERE ();
195 }
196 --- a/src/mpfr-gmp.h 2013-03-13 16:37:32.000000000 +0100
197 +++ b/src/mpfr-gmp.h 2014-12-31 14:56:02.687641984 +0100
198 @@ -72,7 +72,6 @@
199 #endif
201 /* Define some macros */
202 -#define BYTES_PER_MP_LIMB (GMP_NUMB_BITS/CHAR_BIT)
204 #define MP_LIMB_T_MAX (~(mp_limb_t)0)
206 @@ -96,19 +95,19 @@
207 #define SHRT_HIGHBIT SHRT_MIN
209 /* MP_LIMB macros */
210 -#define MPN_ZERO(dst, n) memset((dst), 0, (n)*BYTES_PER_MP_LIMB)
211 -#define MPN_COPY_DECR(dst,src,n) memmove((dst),(src),(n)*BYTES_PER_MP_LIMB)
212 -#define MPN_COPY_INCR(dst,src,n) memmove((dst),(src),(n)*BYTES_PER_MP_LIMB)
213 +#define MPN_ZERO(dst, n) memset((dst), 0, (n)*MPFR_BYTES_PER_MP_LIMB)
214 +#define MPN_COPY_DECR(dst,src,n) memmove((dst),(src),(n)*MPFR_BYTES_PER_MP_LIMB)
215 +#define MPN_COPY_INCR(dst,src,n) memmove((dst),(src),(n)*MPFR_BYTES_PER_MP_LIMB)
216 #define MPN_COPY(dst,src,n) \
217 do \
218 { \
219 if ((dst) != (src)) \
220 { \
221 MPFR_ASSERTD ((char *) (dst) >= (char *) (src) + \
222 - (n) * BYTES_PER_MP_LIMB || \
223 + (n) * MPFR_BYTES_PER_MP_LIMB || \
224 (char *) (src) >= (char *) (dst) + \
225 - (n) * BYTES_PER_MP_LIMB); \
226 - memcpy ((dst), (src), (n) * BYTES_PER_MP_LIMB); \
227 + (n) * MPFR_BYTES_PER_MP_LIMB); \
228 + memcpy ((dst), (src), (n) * MPFR_BYTES_PER_MP_LIMB); \
229 } \
230 } \
231 while (0)
232 --- a/src/mpfr.h 2013-03-13 16:37:37.000000000 +0100
233 +++ b/src/mpfr.h 2014-12-31 14:56:02.687641984 +0100
234 @@ -27,7 +27,7 @@
235 #define MPFR_VERSION_MAJOR 3
236 #define MPFR_VERSION_MINOR 1
237 #define MPFR_VERSION_PATCHLEVEL 2
238 -#define MPFR_VERSION_STRING "3.1.2"
239 +#define MPFR_VERSION_STRING "3.1.2-p11"
241 /* Macros dealing with MPFR VERSION */
242 #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
243 @@ -861,7 +861,7 @@
244 _t = (mpfr_kind_t) _k; \
245 _s = 1; \
246 } else { \
247 - _t = (mpfr_kind_t) -k; \
248 + _t = (mpfr_kind_t) - _k; \
249 _s = -1; \
250 } \
251 _e = _t == MPFR_REGULAR_KIND ? (e) : \
252 --- a/src/mpfr-impl.h 2013-03-13 16:37:36.000000000 +0100
253 +++ b/src/mpfr-impl.h 2014-12-31 14:56:02.687641984 +0100
254 @@ -191,7 +191,7 @@
255 # endif
256 #endif
258 -
259 +#define MPFR_BYTES_PER_MP_LIMB (GMP_NUMB_BITS/CHAR_BIT)
261 /******************************************************
262 ******************** Check GMP ***********************
263 @@ -468,8 +468,16 @@
264 #define MPFR_LIMBS_PER_FLT ((IEEE_FLT_MANT_DIG-1)/GMP_NUMB_BITS+1)
266 /* Visual C++ doesn't support +1.0/0.0, -1.0/0.0 and 0.0/0.0
267 - at compile time. */
268 -#if defined(_MSC_VER) && defined(_WIN32) && (_MSC_VER >= 1200)
269 + at compile time.
270 + Clang with -fsanitize=undefined is a bit similar due to a bug:
271 + http://llvm.org/bugs/show_bug.cgi?id=17381
272 + but even without its sanitizer, it may be better to use the
273 + double_zero version until IEEE 754 division by zero is properly
274 + supported:
275 + http://llvm.org/bugs/show_bug.cgi?id=17000
276 +*/
277 +#if (defined(_MSC_VER) && defined(_WIN32) && (_MSC_VER >= 1200)) || \
278 + defined(__clang__)
279 static double double_zero = 0.0;
280 # define DBL_NAN (double_zero/double_zero)
281 # define DBL_POS_INF ((double) 1.0/double_zero)
282 @@ -501,6 +509,8 @@
283 (with Xcode 2.4.1, i.e. the latest one). */
284 #define LVALUE(x) (&(x) == &(x) || &(x) != &(x))
285 #define DOUBLE_ISINF(x) (LVALUE(x) && ((x) > DBL_MAX || (x) < -DBL_MAX))
286 +/* The DOUBLE_ISNAN(x) macro is also valid on long double x
287 + (assuming that the compiler isn't too broken). */
288 #ifdef MPFR_NANISNAN
289 /* Avoid MIPSpro / IRIX64 / gcc -ffast-math (incorrect) optimizations.
290 The + must not be replaced by a ||. With gcc -ffast-math, NaN is
291 @@ -920,7 +930,7 @@
292 #define MPFR_SET_ALLOC_SIZE(x, n) \
293 ( ((mp_size_t*) MPFR_MANT(x))[-1] = n)
294 #define MPFR_MALLOC_SIZE(s) \
295 - ( sizeof(mpfr_size_limb_t) + BYTES_PER_MP_LIMB * ((size_t) s) )
296 + ( sizeof(mpfr_size_limb_t) + MPFR_BYTES_PER_MP_LIMB * ((size_t) s) )
297 #define MPFR_SET_MANT_PTR(x,p) \
298 (MPFR_MANT(x) = (mp_limb_t*) ((mpfr_size_limb_t*) p + 1))
299 #define MPFR_GET_REAL_PTR(x) \
300 @@ -954,7 +964,7 @@
301 #endif
303 #define MPFR_TMP_LIMBS_ALLOC(N) \
304 - ((mp_limb_t *) MPFR_TMP_ALLOC ((size_t) (N) * BYTES_PER_MP_LIMB))
305 + ((mp_limb_t *) MPFR_TMP_ALLOC ((size_t) (N) * MPFR_BYTES_PER_MP_LIMB))
307 /* temporary allocate 1 limb at xp, and initialize mpfr variable x */
308 /* The temporary var doesn't have any size field, but it doesn't matter
309 --- a/src/mul.c 2013-03-13 16:37:37.000000000 +0100
310 +++ b/src/mul.c 2014-12-31 14:56:02.688641997 +0100
311 @@ -106,7 +106,7 @@
312 MPFR_ASSERTD(tn <= k);
314 /* Check for no size_t overflow*/
315 - MPFR_ASSERTD((size_t) k <= ((size_t) -1) / BYTES_PER_MP_LIMB);
316 + MPFR_ASSERTD((size_t) k <= ((size_t) -1) / MPFR_BYTES_PER_MP_LIMB);
317 MPFR_TMP_MARK(marker);
318 tmp = MPFR_TMP_LIMBS_ALLOC (k);
320 @@ -301,7 +301,7 @@
321 MPFR_ASSERTD (tn <= k); /* tn <= k, thus no int overflow */
323 /* Check for no size_t overflow*/
324 - MPFR_ASSERTD ((size_t) k <= ((size_t) -1) / BYTES_PER_MP_LIMB);
325 + MPFR_ASSERTD ((size_t) k <= ((size_t) -1) / MPFR_BYTES_PER_MP_LIMB);
326 MPFR_TMP_MARK (marker);
327 tmp = MPFR_TMP_LIMBS_ALLOC (k);
329 --- a/src/stack_interface.c 2013-03-13 16:37:32.000000000 +0100
330 +++ b/src/stack_interface.c 2014-12-31 14:56:02.688641997 +0100
331 @@ -26,7 +26,7 @@
332 size_t
333 mpfr_custom_get_size (mpfr_prec_t prec)
334 {
335 - return MPFR_PREC2LIMBS (prec) * BYTES_PER_MP_LIMB;
336 + return MPFR_PREC2LIMBS (prec) * MPFR_BYTES_PER_MP_LIMB;
337 }
339 #undef mpfr_custom_init
340 --- a/src/strtofr.c 2013-03-13 16:37:32.000000000 +0100
341 +++ b/src/strtofr.c 2014-12-31 14:56:02.688641997 +0100
342 @@ -473,8 +473,10 @@
343 /* prec bits corresponds to ysize limbs */
344 ysize_bits = ysize * GMP_NUMB_BITS;
345 /* and to ysize_bits >= prec > MPFR_PREC (x) bits */
346 - y = MPFR_TMP_LIMBS_ALLOC (2 * ysize + 1);
347 - y += ysize; /* y has (ysize+1) allocated limbs */
348 + /* we need to allocate one more limb to work around bug
349 + https://gmplib.org/list-archives/gmp-bugs/2013-December/003267.html */
350 + y = MPFR_TMP_LIMBS_ALLOC (2 * ysize + 2);
351 + y += ysize; /* y has (ysize+2) allocated limbs */
353 /* pstr_size is the number of characters we read in pstr->mant
354 to have at least ysize full limbs.
355 --- a/src/vasprintf.c 2013-03-13 16:37:37.000000000 +0100
356 +++ b/src/vasprintf.c 2014-12-31 14:56:02.688641997 +0100
357 @@ -884,14 +884,18 @@
358 first digit, we want the exponent for radix two and the decimal
359 point AFTER the first digit. */
360 {
361 - MPFR_ASSERTN (exp > MPFR_EMIN_MIN /4); /* possible overflow */
362 + /* An integer overflow is normally not possible since MPFR_EXP_MIN
363 + is twice as large as MPFR_EMIN_MIN. */
364 + MPFR_ASSERTN (exp > (MPFR_EXP_MIN + 3) / 4);
365 exp = (exp - 1) * 4;
366 }
367 else
368 /* EXP is the exponent for decimal point BEFORE the first digit, we
369 want the exponent for decimal point AFTER the first digit. */
370 {
371 - MPFR_ASSERTN (exp > MPFR_EMIN_MIN); /* possible overflow */
372 + /* An integer overflow is normally not possible since MPFR_EXP_MIN
373 + is twice as large as MPFR_EMIN_MIN. */
374 + MPFR_ASSERTN (exp > MPFR_EXP_MIN);
375 --exp;
376 }
377 }
378 @@ -1040,7 +1044,7 @@
379 }
381 /* Determine the different parts of the string representation of the regular
382 - number P when SPEC.SPEC is 'e', 'E', 'g', or 'G'.
383 + number P when spec.spec is 'e', 'E', 'g', or 'G'.
384 DEC_INFO contains the previously computed exponent and string or is NULL.
386 return -1 if some field > INT_MAX */
387 @@ -1167,7 +1171,7 @@
388 }
390 /* Determine the different parts of the string representation of the regular
391 - number P when SPEC.SPEC is 'f', 'F', 'g', or 'G'.
392 + number P when spec.spec is 'f', 'F', 'g', or 'G'.
393 DEC_INFO contains the previously computed exponent and string or is NULL.
395 return -1 if some field of number_parts is greater than INT_MAX */
396 @@ -1559,7 +1563,7 @@
397 /* fractional part */
398 {
399 np->point = MPFR_DECIMAL_POINT;
400 - np->fp_trailing_zeros = (spec.spec == 'g' && spec.spec == 'G') ?
401 + np->fp_trailing_zeros = (spec.spec == 'g' || spec.spec == 'G') ?
402 spec.prec - 1 : spec.prec;
403 }
404 else if (spec.alt)
405 --- a/src/version.c 2013-03-13 16:37:34.000000000 +0100
406 +++ b/src/version.c 2014-12-31 14:56:02.688641997 +0100
407 @@ -25,5 +25,5 @@
408 const char *
409 mpfr_get_version (void)
410 {
411 - return "3.1.2";
412 + return "3.1.2-p11";
413 }
414 --- a/tests/tdiv.c 2013-03-13 16:37:44.000000000 +0100
415 +++ b/tests/tdiv.c 2014-12-31 14:56:02.689642010 +0100
416 @@ -1104,6 +1104,96 @@
417 #define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), randlimb () % 100, RANDS)
418 #include "tgeneric.c"
420 +static void
421 +test_extreme (void)
422 +{
423 + mpfr_t x, y, z;
424 + mpfr_exp_t emin, emax;
425 + mpfr_prec_t p[4] = { 8, 32, 64, 256 };
426 + int xi, yi, zi, j, r;
427 + unsigned int flags, ex_flags;
428 +
429 + emin = mpfr_get_emin ();
430 + emax = mpfr_get_emax ();
431 +
432 + mpfr_set_emin (MPFR_EMIN_MIN);
433 + mpfr_set_emax (MPFR_EMAX_MAX);
434 +
435 + for (xi = 0; xi < 4; xi++)
436 + {
437 + mpfr_init2 (x, p[xi]);
438 + mpfr_setmax (x, MPFR_EMAX_MAX);
439 + MPFR_ASSERTN (mpfr_check (x));
440 + for (yi = 0; yi < 4; yi++)
441 + {
442 + mpfr_init2 (y, p[yi]);
443 + mpfr_setmin (y, MPFR_EMIN_MIN);
444 + for (j = 0; j < 2; j++)
445 + {
446 + MPFR_ASSERTN (mpfr_check (y));
447 + for (zi = 0; zi < 4; zi++)
448 + {
449 + mpfr_init2 (z, p[zi]);
450 + RND_LOOP (r)
451 + {
452 + mpfr_clear_flags ();
453 + mpfr_div (z, x, y, (mpfr_rnd_t) r);
454 + flags = __gmpfr_flags;
455 + MPFR_ASSERTN (mpfr_check (z));
456 + ex_flags = MPFR_FLAGS_OVERFLOW | MPFR_FLAGS_INEXACT;
457 + if (flags != ex_flags)
458 + {
459 + printf ("Bad flags in test_extreme on z = a/b"
460 + " with %s and\n",
461 + mpfr_print_rnd_mode ((mpfr_rnd_t) r));
462 + printf ("a = ");
463 + mpfr_dump (x);
464 + printf ("b = ");
465 + mpfr_dump (y);
466 + printf ("Expected flags:");
467 + flags_out (ex_flags);
468 + printf ("Got flags: ");
469 + flags_out (flags);
470 + printf ("z = ");
471 + mpfr_dump (z);
472 + exit (1);
473 + }
474 + mpfr_clear_flags ();
475 + mpfr_div (z, y, x, (mpfr_rnd_t) r);
476 + flags = __gmpfr_flags;
477 + MPFR_ASSERTN (mpfr_check (z));
478 + ex_flags = MPFR_FLAGS_UNDERFLOW | MPFR_FLAGS_INEXACT;
479 + if (flags != ex_flags)
480 + {
481 + printf ("Bad flags in test_extreme on z = a/b"
482 + " with %s and\n",
483 + mpfr_print_rnd_mode ((mpfr_rnd_t) r));
484 + printf ("a = ");
485 + mpfr_dump (y);
486 + printf ("b = ");
487 + mpfr_dump (x);
488 + printf ("Expected flags:");
489 + flags_out (ex_flags);
490 + printf ("Got flags: ");
491 + flags_out (flags);
492 + printf ("z = ");
493 + mpfr_dump (z);
494 + exit (1);
495 + }
496 + }
497 + mpfr_clear (z);
498 + } /* zi */
499 + mpfr_nextabove (y);
500 + } /* j */
501 + mpfr_clear (y);
502 + } /* yi */
503 + mpfr_clear (x);
504 + } /* xi */
505 +
506 + set_emin (emin);
507 + set_emax (emax);
508 +}
509 +
510 int
511 main (int argc, char *argv[])
512 {
513 @@ -1130,6 +1220,7 @@
514 test_20070603 ();
515 test_20070628 ();
516 test_generic (2, 800, 50);
517 + test_extreme ();
519 tests_end_mpfr ();
520 return 0;
521 --- a/tests/texp.c 2013-03-13 16:37:44.000000000 +0100
522 +++ b/tests/texp.c 2014-12-31 14:56:02.689642010 +0100
523 @@ -150,6 +150,22 @@
524 exit (1);
525 }
527 + mpfr_set_prec (x, 118);
528 + mpfr_set_str_binary (x, "0.1110010100011101010000111110011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E-86");
529 + mpfr_set_prec (y, 118);
530 + mpfr_exp_2 (y, x, MPFR_RNDU);
531 + mpfr_exp_3 (x, x, MPFR_RNDU);
532 + if (mpfr_cmp (x, y))
533 + {
534 + printf ("mpfr_exp_2 and mpfr_exp_3 differ for prec=118\n");
535 + printf ("mpfr_exp_2 gives ");
536 + mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN);
537 + printf ("\nmpfr_exp_3 gives ");
538 + mpfr_out_str (stdout, 2, 0, x, MPFR_RNDN);
539 + printf ("\n");
540 + exit (1);
541 + }
542 +
543 mpfr_clear (x);
544 mpfr_clear (y);
545 return 0;
546 --- a/tests/tfits.c 2013-03-13 16:37:45.000000000 +0100
547 +++ b/tests/tfits.c 2014-12-31 14:56:02.689642010 +0100
548 @@ -33,155 +33,176 @@
549 #include "mpfr-intmax.h"
550 #include "mpfr-test.h"
552 -#define ERROR1 { printf("Initial error for x="); mpfr_dump(x); exit(1); }
553 -#define ERROR2 { printf("Error for x="); mpfr_dump(x); exit(1); }
554 +#define ERROR1(N) \
555 + do \
556 + { \
557 + printf("Error %d for rnd = %s and x = ", N, \
558 + mpfr_print_rnd_mode ((mpfr_rnd_t) r)); \
559 + mpfr_dump(x); \
560 + exit(1); \
561 + } \
562 + while (0)
564 static void check_intmax (void);
566 int
567 main (void)
568 {
569 - mpfr_t x;
570 + mpfr_t x, y;
571 + int i, r;
573 tests_start_mpfr ();
575 mpfr_init2 (x, 256);
576 + mpfr_init2 (y, 8);
578 - /* Check NAN */
579 - mpfr_set_nan (x);
580 - if (mpfr_fits_ulong_p (x, MPFR_RNDN))
581 - ERROR1;
582 - if (mpfr_fits_slong_p (x, MPFR_RNDN))
583 - ERROR1;
584 - if (mpfr_fits_uint_p (x, MPFR_RNDN))
585 - ERROR1;
586 - if (mpfr_fits_sint_p (x, MPFR_RNDN))
587 - ERROR1;
588 - if (mpfr_fits_ushort_p (x, MPFR_RNDN))
589 - ERROR1;
590 - if (mpfr_fits_sshort_p (x, MPFR_RNDN))
591 - ERROR1;
592 -
593 - /* Check INF */
594 - mpfr_set_inf (x, 1);
595 - if (mpfr_fits_ulong_p (x, MPFR_RNDN))
596 - ERROR1;
597 - if (mpfr_fits_slong_p (x, MPFR_RNDN))
598 - ERROR1;
599 - if (mpfr_fits_uint_p (x, MPFR_RNDN))
600 - ERROR1;
601 - if (mpfr_fits_sint_p (x, MPFR_RNDN))
602 - ERROR1;
603 - if (mpfr_fits_ushort_p (x, MPFR_RNDN))
604 - ERROR1;
605 - if (mpfr_fits_sshort_p (x, MPFR_RNDN))
606 - ERROR1;
607 -
608 - /* Check Zero */
609 - MPFR_SET_ZERO (x);
610 - if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
611 - ERROR2;
612 - if (!mpfr_fits_slong_p (x, MPFR_RNDN))
613 - ERROR2;
614 - if (!mpfr_fits_uint_p (x, MPFR_RNDN))
615 - ERROR2;
616 - if (!mpfr_fits_sint_p (x, MPFR_RNDN))
617 - ERROR2;
618 - if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
619 - ERROR2;
620 - if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
621 - ERROR2;
622 -
623 - /* Check small op */
624 - mpfr_set_str1 (x, "1@-1");
625 - if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
626 - ERROR2;
627 - if (!mpfr_fits_slong_p (x, MPFR_RNDN))
628 - ERROR2;
629 - if (!mpfr_fits_uint_p (x, MPFR_RNDN))
630 - ERROR2;
631 - if (!mpfr_fits_sint_p (x, MPFR_RNDN))
632 - ERROR2;
633 - if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
634 - ERROR2;
635 - if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
636 - ERROR2;
637 -
638 - /* Check 17 */
639 - mpfr_set_ui (x, 17, MPFR_RNDN);
640 - if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
641 - ERROR2;
642 - if (!mpfr_fits_slong_p (x, MPFR_RNDN))
643 - ERROR2;
644 - if (!mpfr_fits_uint_p (x, MPFR_RNDN))
645 - ERROR2;
646 - if (!mpfr_fits_sint_p (x, MPFR_RNDN))
647 - ERROR2;
648 - if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
649 - ERROR2;
650 - if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
651 - ERROR2;
652 -
653 - /* Check all other values */
654 - mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
655 - mpfr_mul_2exp (x, x, 1, MPFR_RNDN);
656 - if (mpfr_fits_ulong_p (x, MPFR_RNDN))
657 - ERROR1;
658 - if (mpfr_fits_slong_p (x, MPFR_RNDN))
659 - ERROR1;
660 - mpfr_mul_2exp (x, x, 40, MPFR_RNDN);
661 - if (mpfr_fits_ulong_p (x, MPFR_RNDN))
662 - ERROR1;
663 - if (mpfr_fits_uint_p (x, MPFR_RNDN))
664 - ERROR1;
665 - if (mpfr_fits_sint_p (x, MPFR_RNDN))
666 - ERROR1;
667 - if (mpfr_fits_ushort_p (x, MPFR_RNDN))
668 - ERROR1;
669 - if (mpfr_fits_sshort_p (x, MPFR_RNDN))
670 - ERROR1;
671 -
672 - mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
673 - if (!mpfr_fits_ulong_p (x, MPFR_RNDN))
674 - ERROR2;
675 - mpfr_set_ui (x, LONG_MAX, MPFR_RNDN);
676 - if (!mpfr_fits_slong_p (x, MPFR_RNDN))
677 - ERROR2;
678 - mpfr_set_ui (x, UINT_MAX, MPFR_RNDN);
679 - if (!mpfr_fits_uint_p (x, MPFR_RNDN))
680 - ERROR2;
681 - mpfr_set_ui (x, INT_MAX, MPFR_RNDN);
682 - if (!mpfr_fits_sint_p (x, MPFR_RNDN))
683 - ERROR2;
684 - mpfr_set_ui (x, USHRT_MAX, MPFR_RNDN);
685 - if (!mpfr_fits_ushort_p (x, MPFR_RNDN))
686 - ERROR2;
687 - mpfr_set_ui (x, SHRT_MAX, MPFR_RNDN);
688 - if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
689 - ERROR2;
690 -
691 - mpfr_set_si (x, 1, MPFR_RNDN);
692 - if (!mpfr_fits_sint_p (x, MPFR_RNDN))
693 - ERROR2;
694 - if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
695 - ERROR2;
696 -
697 - /* Check negative value */
698 - mpfr_set_si (x, -1, MPFR_RNDN);
699 - if (!mpfr_fits_sint_p (x, MPFR_RNDN))
700 - ERROR2;
701 - if (!mpfr_fits_sshort_p (x, MPFR_RNDN))
702 - ERROR2;
703 - if (!mpfr_fits_slong_p (x, MPFR_RNDN))
704 - ERROR2;
705 - if (mpfr_fits_uint_p (x, MPFR_RNDN))
706 - ERROR1;
707 - if (mpfr_fits_ushort_p (x, MPFR_RNDN))
708 - ERROR1;
709 - if (mpfr_fits_ulong_p (x, MPFR_RNDN))
710 - ERROR1;
711 + RND_LOOP (r)
712 + {
713 +
714 + /* Check NAN */
715 + mpfr_set_nan (x);
716 + if (mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
717 + ERROR1 (1);
718 + if (mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
719 + ERROR1 (2);
720 + if (mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
721 + ERROR1 (3);
722 + if (mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
723 + ERROR1 (4);
724 + if (mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
725 + ERROR1 (5);
726 + if (mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
727 + ERROR1 (6);
728 +
729 + /* Check INF */
730 + mpfr_set_inf (x, 1);
731 + if (mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
732 + ERROR1 (7);
733 + if (mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
734 + ERROR1 (8);
735 + if (mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
736 + ERROR1 (9);
737 + if (mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
738 + ERROR1 (10);
739 + if (mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
740 + ERROR1 (11);
741 + if (mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
742 + ERROR1 (12);
743 +
744 + /* Check Zero */
745 + MPFR_SET_ZERO (x);
746 + if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
747 + ERROR1 (13);
748 + if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
749 + ERROR1 (14);
750 + if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
751 + ERROR1 (15);
752 + if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
753 + ERROR1 (16);
754 + if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
755 + ERROR1 (17);
756 + if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
757 + ERROR1 (18);
758 +
759 + /* Check small positive op */
760 + mpfr_set_str1 (x, "1@-1");
761 + if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
762 + ERROR1 (19);
763 + if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
764 + ERROR1 (20);
765 + if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
766 + ERROR1 (21);
767 + if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
768 + ERROR1 (22);
769 + if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
770 + ERROR1 (23);
771 + if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
772 + ERROR1 (24);
773 +
774 + /* Check 17 */
775 + mpfr_set_ui (x, 17, MPFR_RNDN);
776 + if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
777 + ERROR1 (25);
778 + if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
779 + ERROR1 (26);
780 + if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
781 + ERROR1 (27);
782 + if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
783 + ERROR1 (28);
784 + if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
785 + ERROR1 (29);
786 + if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
787 + ERROR1 (30);
788 +
789 + /* Check all other values */
790 + mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
791 + mpfr_mul_2exp (x, x, 1, MPFR_RNDN);
792 + if (mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
793 + ERROR1 (31);
794 + if (mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
795 + ERROR1 (32);
796 + mpfr_mul_2exp (x, x, 40, MPFR_RNDN);
797 + if (mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
798 + ERROR1 (33);
799 + if (mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
800 + ERROR1 (34);
801 + if (mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
802 + ERROR1 (35);
803 + if (mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
804 + ERROR1 (36);
805 + if (mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
806 + ERROR1 (37);
807 +
808 + mpfr_set_ui (x, ULONG_MAX, MPFR_RNDN);
809 + if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r))
810 + ERROR1 (38);
811 + mpfr_set_ui (x, LONG_MAX, MPFR_RNDN);
812 + if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
813 + ERROR1 (39);
814 + mpfr_set_ui (x, UINT_MAX, MPFR_RNDN);
815 + if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r))
816 + ERROR1 (40);
817 + mpfr_set_ui (x, INT_MAX, MPFR_RNDN);
818 + if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
819 + ERROR1 (41);
820 + mpfr_set_ui (x, USHRT_MAX, MPFR_RNDN);
821 + if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r))
822 + ERROR1 (42);
823 + mpfr_set_ui (x, SHRT_MAX, MPFR_RNDN);
824 + if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
825 + ERROR1 (43);
826 +
827 + mpfr_set_si (x, 1, MPFR_RNDN);
828 + if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
829 + ERROR1 (44);
830 + if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
831 + ERROR1 (45);
832 +
833 + /* Check negative op */
834 + for (i = 1; i <= 4; i++)
835 + {
836 + int inv;
837 +
838 + mpfr_set_si_2exp (x, -i, -2, MPFR_RNDN);
839 + mpfr_rint (y, x, (mpfr_rnd_t) r);
840 + inv = MPFR_NOTZERO (y);
841 + if (!mpfr_fits_ulong_p (x, (mpfr_rnd_t) r) ^ inv)
842 + ERROR1 (46);
843 + if (!mpfr_fits_slong_p (x, (mpfr_rnd_t) r))
844 + ERROR1 (47);
845 + if (!mpfr_fits_uint_p (x, (mpfr_rnd_t) r) ^ inv)
846 + ERROR1 (48);
847 + if (!mpfr_fits_sint_p (x, (mpfr_rnd_t) r))
848 + ERROR1 (49);
849 + if (!mpfr_fits_ushort_p (x, (mpfr_rnd_t) r) ^ inv)
850 + ERROR1 (50);
851 + if (!mpfr_fits_sshort_p (x, (mpfr_rnd_t) r))
852 + ERROR1 (51);
853 + }
854 + }
856 mpfr_clear (x);
857 + mpfr_clear (y);
859 check_intmax ();
861 @@ -189,85 +210,98 @@
862 return 0;
863 }
865 -static void check_intmax (void)
866 +static void
867 +check_intmax (void)
868 {
869 #ifdef _MPFR_H_HAVE_INTMAX_T
870 - mpfr_t x;
871 + mpfr_t x, y;
872 + int i, r;
874 - mpfr_init2 (x, sizeof (uintmax_t)*CHAR_BIT);
875 + mpfr_init2 (x, sizeof (uintmax_t) * CHAR_BIT);
876 + mpfr_init2 (y, 8);
878 - /* Check NAN */
879 - mpfr_set_nan (x);
880 - if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
881 - ERROR1;
882 - if (mpfr_fits_intmax_p (x, MPFR_RNDN))
883 - ERROR1;
884 -
885 - /* Check INF */
886 - mpfr_set_inf (x, 1);
887 - if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
888 - ERROR1;
889 - if (mpfr_fits_intmax_p (x, MPFR_RNDN))
890 - ERROR1;
891 -
892 - /* Check Zero */
893 - MPFR_SET_ZERO (x);
894 - if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
895 - ERROR2;
896 - if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
897 - ERROR2;
898 -
899 - /* Check small op */
900 - mpfr_set_str1 (x, "1@-1");
901 - if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
902 - ERROR2;
903 - if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
904 - ERROR2;
905 -
906 - /* Check 17 */
907 - mpfr_set_ui (x, 17, MPFR_RNDN);
908 - if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
909 - ERROR2;
910 - if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
911 - ERROR2;
912 -
913 - /* Check hugest */
914 - mpfr_set_ui_2exp (x, 42, sizeof (uintmax_t) * 32, MPFR_RNDN);
915 - if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
916 - ERROR1;
917 - if (mpfr_fits_intmax_p (x, MPFR_RNDN))
918 - ERROR1;
919 -
920 - /* Check all other values */
921 - mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
922 - mpfr_add_ui (x, x, 1, MPFR_RNDN);
923 - if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
924 - ERROR1;
925 - mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
926 - if (!mpfr_fits_uintmax_p (x, MPFR_RNDN))
927 - ERROR2;
928 - mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
929 - mpfr_add_ui (x, x, 1, MPFR_RNDN);
930 - if (mpfr_fits_intmax_p (x, MPFR_RNDN))
931 - ERROR1;
932 - mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
933 - if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
934 - ERROR2;
935 - mpfr_set_sj (x, MPFR_INTMAX_MIN, MPFR_RNDN);
936 - if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
937 - ERROR2;
938 - mpfr_sub_ui (x, x, 1, MPFR_RNDN);
939 - if (mpfr_fits_intmax_p (x, MPFR_RNDN))
940 - ERROR1;
941 -
942 - /* Check negative value */
943 - mpfr_set_si (x, -1, MPFR_RNDN);
944 - if (!mpfr_fits_intmax_p (x, MPFR_RNDN))
945 - ERROR2;
946 - if (mpfr_fits_uintmax_p (x, MPFR_RNDN))
947 - ERROR1;
948 + RND_LOOP (r)
949 + {
950 + /* Check NAN */
951 + mpfr_set_nan (x);
952 + if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
953 + ERROR1 (52);
954 + if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
955 + ERROR1 (53);
956 +
957 + /* Check INF */
958 + mpfr_set_inf (x, 1);
959 + if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
960 + ERROR1 (54);
961 + if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
962 + ERROR1 (55);
963 +
964 + /* Check Zero */
965 + MPFR_SET_ZERO (x);
966 + if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
967 + ERROR1 (56);
968 + if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
969 + ERROR1 (57);
970 +
971 + /* Check positive small op */
972 + mpfr_set_str1 (x, "1@-1");
973 + if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
974 + ERROR1 (58);
975 + if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
976 + ERROR1 (59);
977 +
978 + /* Check 17 */
979 + mpfr_set_ui (x, 17, MPFR_RNDN);
980 + if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
981 + ERROR1 (60);
982 + if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
983 + ERROR1 (61);
984 +
985 + /* Check hugest */
986 + mpfr_set_ui_2exp (x, 42, sizeof (uintmax_t) * 32, MPFR_RNDN);
987 + if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
988 + ERROR1 (62);
989 + if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
990 + ERROR1 (63);
991 +
992 + /* Check all other values */
993 + mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
994 + mpfr_add_ui (x, x, 1, MPFR_RNDN);
995 + if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
996 + ERROR1 (64);
997 + mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN);
998 + if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r))
999 + ERROR1 (65);
1000 + mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
1001 + mpfr_add_ui (x, x, 1, MPFR_RNDN);
1002 + if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
1003 + ERROR1 (66);
1004 + mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN);
1005 + if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
1006 + ERROR1 (67);
1007 + mpfr_set_sj (x, MPFR_INTMAX_MIN, MPFR_RNDN);
1008 + if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
1009 + ERROR1 (68);
1010 + mpfr_sub_ui (x, x, 1, MPFR_RNDN);
1011 + if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
1012 + ERROR1 (69);
1013 +
1014 + /* Check negative op */
1015 + for (i = 1; i <= 4; i++)
1016 + {
1017 + int inv;
1018 +
1019 + mpfr_set_si_2exp (x, -i, -2, MPFR_RNDN);
1020 + mpfr_rint (y, x, (mpfr_rnd_t) r);
1021 + inv = MPFR_NOTZERO (y);
1022 + if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r) ^ inv)
1023 + ERROR1 (70);
1024 + if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r))
1025 + ERROR1 (71);
1026 + }
1027 + }
1029 mpfr_clear (x);
1030 + mpfr_clear (y);
1031 #endif
1032 }
1033 -
1034 --- a/tests/tget_flt.c 2013-03-13 16:37:44.000000000 +0100
1035 +++ b/tests/tget_flt.c 2014-12-31 14:56:02.690642023 +0100
1036 @@ -28,9 +28,17 @@
1037 main (void)
1038 {
1039 mpfr_t x, y;
1040 - float f, g, infp;
1041 + float f, g;
1042 int i;
1043 +#if !defined(MPFR_ERRDIVZERO)
1044 + float infp;
1045 +#endif
1047 + tests_start_mpfr ();
1048 +
1049 +#if !defined(MPFR_ERRDIVZERO)
1050 + /* The definition of DBL_POS_INF involves a division by 0. This makes
1051 + "clang -O2 -fsanitize=undefined -fno-sanitize-recover" fail. */
1052 infp = (float) DBL_POS_INF;
1053 if (infp * 0.5 != infp)
1054 {
1055 @@ -38,8 +46,7 @@
1056 fprintf (stderr, "(this is probably a compiler bug, please report)\n");
1057 exit (1);
1058 }
1059 -
1060 - tests_start_mpfr ();
1061 +#endif
1063 mpfr_init2 (x, 24);
1064 mpfr_init2 (y, 24);
1065 @@ -353,6 +360,7 @@
1066 printf ("expected %.8e, got %.8e\n", g, f);
1067 exit (1);
1068 }
1069 +#if !defined(MPFR_ERRDIVZERO)
1070 f = mpfr_get_flt (x, MPFR_RNDN); /* first round to 2^128 (even rule),
1071 thus we should get +Inf */
1072 g = infp;
1073 @@ -376,6 +384,7 @@
1074 printf ("expected %.8e, got %.8e\n", g, f);
1075 exit (1);
1076 }
1077 +#endif
1079 mpfr_clear (x);
1080 mpfr_clear (y);
1081 --- a/tests/tset_ld.c 2013-03-13 16:37:44.000000000 +0100
1082 +++ b/tests/tset_ld.c 2014-12-31 14:56:02.690642023 +0100
1083 @@ -47,8 +47,11 @@
1084 static int
1085 Isnan_ld (long double d)
1086 {
1087 - double e = (double) d;
1088 - if (DOUBLE_ISNAN (e))
1089 + /* Do not convert d to double as this can give an overflow, which
1090 + may confuse compilers without IEEE 754 support (such as clang
1091 + -fsanitize=undefined), or trigger a trap if enabled.
1092 + The DOUBLE_ISNAN macro should work fine on long double. */
1093 + if (DOUBLE_ISNAN (d))
1094 return 1;
1095 LONGDOUBLE_NAN_ACTION (d, goto yes);
1096 return 0;
1097 --- a/tests/tsprintf.c 2013-03-13 16:37:44.000000000 +0100
1098 +++ b/tests/tsprintf.c 2014-12-31 14:56:02.690642023 +0100
1099 @@ -456,10 +456,16 @@
1100 check_sprintf ("1.999900 ", "%-#10.7RG", x);
1101 check_sprintf ("1.9999 ", "%-10.7RG", x);
1102 mpfr_set_ui (x, 1, MPFR_RNDN);
1103 + check_sprintf ("1.", "%#.1Rg", x);
1104 + check_sprintf ("1. ", "%-#5.1Rg", x);
1105 + check_sprintf (" 1.0", "%#5.2Rg", x);
1106 check_sprintf ("1.00000000000000000000000000000", "%#.30Rg", x);
1107 check_sprintf ("1", "%.30Rg", x);
1108 mpfr_set_ui (x, 0, MPFR_RNDN);
1109 - check_sprintf ("0.000000000000000000000000000000", "%#.30Rg", x);
1110 + check_sprintf ("0.", "%#.1Rg", x);
1111 + check_sprintf ("0. ", "%-#5.1Rg", x);
1112 + check_sprintf (" 0.0", "%#5.2Rg", x);
1113 + check_sprintf ("0.00000000000000000000000000000", "%#.30Rg", x);
1114 check_sprintf ("0", "%.30Rg", x);
1116 /* following tests with precision 53 bits */
1117 @@ -1178,6 +1184,69 @@
1118 check_emax_aux (MPFR_EMAX_MAX);
1119 }
1121 +static void
1122 +check_emin_aux (mpfr_exp_t e)
1123 +{
1124 + mpfr_t x;
1125 + char *s1, s2[256];
1126 + int i;
1127 + mpfr_exp_t emin;
1128 + mpz_t ee;
1129 +
1130 + MPFR_ASSERTN (e >= LONG_MIN);
1131 + emin = mpfr_get_emin ();
1132 + set_emin (e);
1133 +
1134 + mpfr_init2 (x, 16);
1135 + mpz_init (ee);
1136 +
1137 + mpfr_setmin (x, e);
1138 + mpz_set_si (ee, e);
1139 + mpz_sub_ui (ee, ee, 1);
1140 +
1141 + i = mpfr_asprintf (&s1, "%Ra", x);
1142 + MPFR_ASSERTN (i > 0);
1143 +
1144 + gmp_snprintf (s2, 256, "0x1p%Zd", ee);
1145 +
1146 + if (strcmp (s1, s2) != 0)
1147 + {
1148 + printf ("Error in check_emin_aux for emin = %ld\n", (long) e);
1149 + printf ("Expected %s\n", s2);
1150 + printf ("Got %s\n", s1);
1151 + exit (1);
1152 + }
1153 +
1154 + mpfr_free_str (s1);
1155 +
1156 + i = mpfr_asprintf (&s1, "%Rb", x);
1157 + MPFR_ASSERTN (i > 0);
1158 +
1159 + gmp_snprintf (s2, 256, "1p%Zd", ee);
1160 +
1161 + if (strcmp (s1, s2) != 0)
1162 + {
1163 + printf ("Error in check_emin_aux for emin = %ld\n", (long) e);
1164 + printf ("Expected %s\n", s2);
1165 + printf ("Got %s\n", s1);
1166 + exit (1);
1167 + }
1168 +
1169 + mpfr_free_str (s1);
1170 +
1171 + mpfr_clear (x);
1172 + mpz_clear (ee);
1173 + set_emin (emin);
1174 +}
1175 +
1176 +static void
1177 +check_emin (void)
1178 +{
1179 + check_emin_aux (-15);
1180 + check_emin_aux (mpfr_get_emin ());
1181 + check_emin_aux (MPFR_EMIN_MIN);
1182 +}
1183 +
1184 int
1185 main (int argc, char **argv)
1186 {
1187 @@ -1197,6 +1266,7 @@
1188 decimal ();
1189 mixed ();
1190 check_emax ();
1191 + check_emin ();
1193 #if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)
1194 locale_da_DK ();
1195 --- a/VERSION 2013-03-13 16:37:28.000000000 +0100
1196 +++ b/VERSION 2014-12-31 14:56:02.690642023 +0100
1197 @@ -1 +1 @@
1198 -3.1.2
1199 +3.1.2-p11