archrelease: copy trunk to extra-x86_64
[arch-packages.git] / mpfr / trunk / patches.diff
blob91201f30f80d8de7a9b996fecdf74ddcf195642f
1 diff -Naurd mpfr-4.2.0-a/PATCHES mpfr-4.2.0-b/PATCHES
2 --- mpfr-4.2.0-a/PATCHES 2023-04-17 21:17:39.748645280 +0000
3 +++ mpfr-4.2.0-b/PATCHES 2023-04-17 21:17:39.792645218 +0000
4 @@ -0,0 +1 @@
5 +tsprintf-thousands
6 diff -Naurd mpfr-4.2.0-a/VERSION mpfr-4.2.0-b/VERSION
7 --- mpfr-4.2.0-a/VERSION 2023-01-06 10:55:57.000000000 +0000
8 +++ mpfr-4.2.0-b/VERSION 2023-04-17 21:17:39.792645218 +0000
9 @@ -1 +1 @@
10 -4.2.0
11 +4.2.0-p1
12 diff -Naurd mpfr-4.2.0-a/src/mpfr.h mpfr-4.2.0-b/src/mpfr.h
13 --- mpfr-4.2.0-a/src/mpfr.h 2023-01-06 10:55:57.000000000 +0000
14 +++ mpfr-4.2.0-b/src/mpfr.h 2023-04-17 21:17:39.788645224 +0000
15 @@ -27,7 +27,7 @@
16 #define MPFR_VERSION_MAJOR 4
17 #define MPFR_VERSION_MINOR 2
18 #define MPFR_VERSION_PATCHLEVEL 0
19 -#define MPFR_VERSION_STRING "4.2.0"
20 +#define MPFR_VERSION_STRING "4.2.0-p1"
22 /* User macros:
23 MPFR_USE_FILE: Define it to make MPFR define functions dealing
24 diff -Naurd mpfr-4.2.0-a/src/version.c mpfr-4.2.0-b/src/version.c
25 --- mpfr-4.2.0-a/src/version.c 2023-01-06 10:55:57.000000000 +0000
26 +++ mpfr-4.2.0-b/src/version.c 2023-04-17 21:17:39.792645218 +0000
27 @@ -25,5 +25,5 @@
28 const char *
29 mpfr_get_version (void)
31 - return "4.2.0";
32 + return "4.2.0-p1";
34 diff -Naurd mpfr-4.2.0-a/tests/tsprintf.c mpfr-4.2.0-b/tests/tsprintf.c
35 --- mpfr-4.2.0-a/tests/tsprintf.c 2023-01-05 17:09:48.000000000 +0000
36 +++ mpfr-4.2.0-b/tests/tsprintf.c 2023-04-17 21:17:39.784645229 +0000
37 @@ -1715,7 +1715,25 @@
38 check_sprintf ("000000001,000", "%'013.4Rg", x);
40 #ifdef PRINTF_GROUPFLAG
41 - check_vsprintf ("+01,234,567 :", "%0+ -'13.10Pd:", (mpfr_prec_t) 1234567);
42 + /* Do not test the thousands separator with a precision field larger
43 + than the number of digits (thus needing leading zeros), such as
44 + "%0+ -'13.10Pd:" (used up to MPFR 4.2.0), since the GNU libc is
45 + buggy: https://sourceware.org/bugzilla/show_bug.cgi?id=23432
46 + We don't know about the other implementations.
47 + This new test works fine with glibc up to 2.36, but fails with 2.37
48 + (as reported by Klaus Dittrich in the MPFR mailing-list); this is
49 + actually a bug introduced in glibc 2.37, not in MPFR:
50 + https://sourceware.org/bugzilla/show_bug.cgi?id=30068
51 + Since this bug can yield a buffer overflow (CVE-2023-25139), possibly
52 + affecting MPFR users, let us rather require a fix in glibc. This bug
53 + has been fixed in the 2.37 branch:
54 + https://sourceware.org/git/?p=glibc.git;a=commit;h=07b9521fc6
55 + If we wanted to check that and avoid a failure of the test because of
56 + a buggy C library (while MPFR would be consistent with the C library),
57 + we could compare the MPFR output with both the correct output and the
58 + output from the C library (possibly buggy). But to do that in a clean
59 + way, this would require a change in the check_vsprintf() call. */
60 + check_vsprintf ("+1,234,567 :", "%0+ -'13Pd:", (mpfr_prec_t) 1234567);
61 #endif
63 mpfr_clear (x);
64 diff -Naurd mpfr-4.2.0-a/PATCHES mpfr-4.2.0-b/PATCHES
65 --- mpfr-4.2.0-a/PATCHES 2023-04-17 21:18:00.464616127 +0000
66 +++ mpfr-4.2.0-b/PATCHES 2023-04-17 21:18:00.512616059 +0000
67 @@ -0,0 +1 @@
68 +ui_pow_ui-overflow
69 diff -Naurd mpfr-4.2.0-a/VERSION mpfr-4.2.0-b/VERSION
70 --- mpfr-4.2.0-a/VERSION 2023-04-17 21:17:39.792645218 +0000
71 +++ mpfr-4.2.0-b/VERSION 2023-04-17 21:18:00.512616059 +0000
72 @@ -1 +1 @@
73 -4.2.0-p1
74 +4.2.0-p2
75 diff -Naurd mpfr-4.2.0-a/src/mpfr.h mpfr-4.2.0-b/src/mpfr.h
76 --- mpfr-4.2.0-a/src/mpfr.h 2023-04-17 21:17:39.788645224 +0000
77 +++ mpfr-4.2.0-b/src/mpfr.h 2023-04-17 21:18:00.508616065 +0000
78 @@ -27,7 +27,7 @@
79 #define MPFR_VERSION_MAJOR 4
80 #define MPFR_VERSION_MINOR 2
81 #define MPFR_VERSION_PATCHLEVEL 0
82 -#define MPFR_VERSION_STRING "4.2.0-p1"
83 +#define MPFR_VERSION_STRING "4.2.0-p2"
85 /* User macros:
86 MPFR_USE_FILE: Define it to make MPFR define functions dealing
87 diff -Naurd mpfr-4.2.0-a/src/ui_pow_ui.c mpfr-4.2.0-b/src/ui_pow_ui.c
88 --- mpfr-4.2.0-a/src/ui_pow_ui.c 2023-01-05 17:09:48.000000000 +0000
89 +++ mpfr-4.2.0-b/src/ui_pow_ui.c 2023-04-17 21:18:00.504616070 +0000
90 @@ -23,7 +23,7 @@
91 #include "mpfr-impl.h"
93 int
94 -mpfr_ui_pow_ui (mpfr_ptr x, unsigned long int y, unsigned long int n,
95 +mpfr_ui_pow_ui (mpfr_ptr x, unsigned long int k, unsigned long int n,
96 mpfr_rnd_t rnd)
98 mpfr_exp_t err;
99 @@ -35,22 +35,28 @@
100 MPFR_ZIV_DECL (loop);
101 MPFR_SAVE_EXPO_DECL (expo);
103 + MPFR_LOG_FUNC
104 + (("k=%lu n=%lu rnd=%d", k, n, rnd),
105 + ("y[%Pu]=%.*Rg inexact=%d",
106 + mpfr_get_prec (x), mpfr_log_prec, x, inexact));
108 if (MPFR_UNLIKELY (n <= 1))
110 if (n == 1)
111 - return mpfr_set_ui (x, y, rnd); /* y^1 = y */
112 + return mpfr_set_ui (x, k, rnd); /* k^1 = k */
113 else
114 - return mpfr_set_ui (x, 1, rnd); /* y^0 = 1 for any y */
115 + return mpfr_set_ui (x, 1, rnd); /* k^0 = 1 for any k */
117 - else if (MPFR_UNLIKELY (y <= 1))
118 + else if (MPFR_UNLIKELY (k <= 1))
120 - if (y == 1)
121 + if (k == 1)
122 return mpfr_set_ui (x, 1, rnd); /* 1^n = 1 for any n > 0 */
123 else
124 return mpfr_set_ui (x, 0, rnd); /* 0^n = 0 for any n > 0 */
127 - for (size_n = 0, m = n; m; size_n++, m >>= 1);
128 + for (size_n = 0, m = n; m != 0; size_n++, m >>= 1)
131 MPFR_SAVE_EXPO_MARK (expo);
132 prec = MPFR_PREC (x) + 3 + size_n;
133 @@ -60,23 +66,55 @@
134 for (;;)
136 int i = size_n;
137 + unsigned int inex_res;
139 - inexact = mpfr_set_ui (res, y, MPFR_RNDU);
140 + inex_res = mpfr_set_ui (res, k, MPFR_RNDU);
141 err = 1;
142 /* now 2^(i-1) <= n < 2^i: i=1+floor(log2(n)) */
143 for (i -= 2; i >= 0; i--)
145 - inexact |= mpfr_sqr (res, res, MPFR_RNDU);
146 + inex_res |= mpfr_sqr (res, res, MPFR_RNDU);
147 err++;
148 if (n & (1UL << i))
149 - inexact |= mpfr_mul_ui (res, res, y, MPFR_RNDU);
150 + inex_res |= mpfr_mul_ui (res, res, k, MPFR_RNDU);
153 + if (MPFR_UNLIKELY (MPFR_IS_INF (res)))
155 + mpfr_t kf;
156 + mpz_t z;
157 + int size_k;
158 + MPFR_BLOCK_DECL (flags);
160 + /* Let's handle the overflow by calling mpfr_pow_z.
161 + Alternatively, we could call mpfr_pow_ui; this would
162 + need a bit shorter code below, but mpfr_pow_ui handles
163 + the overflow by calling mpfr_pow_z, so that calling
164 + mpfr_pow_z directly should be a bit more efficient. */
166 + MPFR_ZIV_FREE (loop);
167 + mpfr_clear (res);
168 + for (size_k = 0, m = k; m != 0; size_k++, m >>= 1)
170 + mpfr_init2 (kf, size_k);
171 + inexact = mpfr_set_ui (kf, k, MPFR_RNDN);
172 + MPFR_ASSERTD (inexact == 0);
173 + mpz_init (z);
174 + mpz_set_ui (z, n);
175 + MPFR_BLOCK (flags, inexact = mpfr_pow_z (x, kf, z, rnd););
176 + mpz_clear (z);
177 + mpfr_clear (kf);
178 + MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, flags);
179 + goto end;
182 /* since the loop is executed floor(log2(n)) times,
183 we have err = 1+floor(log2(n)).
184 Since prec >= MPFR_PREC(x) + 4 + floor(log2(n)), prec > err */
185 err = prec - err;
187 - if (MPFR_LIKELY (inexact == 0
188 + MPFR_LOG_VAR (res);
189 + if (MPFR_LIKELY (!inex_res
190 || MPFR_CAN_ROUND (res, err, MPFR_PREC (x), rnd)))
191 break;
193 @@ -90,6 +128,7 @@
195 mpfr_clear (res);
197 + end:
198 MPFR_SAVE_EXPO_FREE (expo);
199 return mpfr_check_range (x, inexact, rnd);
201 diff -Naurd mpfr-4.2.0-a/src/version.c mpfr-4.2.0-b/src/version.c
202 --- mpfr-4.2.0-a/src/version.c 2023-04-17 21:17:39.792645218 +0000
203 +++ mpfr-4.2.0-b/src/version.c 2023-04-17 21:18:00.512616059 +0000
204 @@ -25,5 +25,5 @@
205 const char *
206 mpfr_get_version (void)
208 - return "4.2.0-p1";
209 + return "4.2.0-p2";
211 diff -Naurd mpfr-4.2.0-a/tests/tlog10.c mpfr-4.2.0-b/tests/tlog10.c
212 --- mpfr-4.2.0-a/tests/tlog10.c 2023-01-05 17:09:48.000000000 +0000
213 +++ mpfr-4.2.0-b/tests/tlog10.c 2023-04-17 21:18:00.504616070 +0000
214 @@ -49,6 +49,60 @@
215 #define TEST_RANDOM_POS 8
216 #include "tgeneric.c"
218 +/* On 2023-02-13, one gets an infinite loop in mpfr_log10 on both
219 + 32-bit and 64-bit hosts when the precision is not large enough
220 + (precision 12 and below). */
221 +static void
222 +bug20230213 (void)
224 + mpfr_exp_t old_emin, old_emax, e;
225 + mpfr_t t, x, y0, y1, y2;
226 + int prec;
228 + old_emin = mpfr_get_emin ();
229 + old_emax = mpfr_get_emax ();
231 + set_emin (MPFR_EMIN_MIN);
232 + set_emax (MPFR_EMAX_MAX);
233 + e = mpfr_get_emax () - 1;
235 + /* The precisions of t and y0 should be large enough to avoid
236 + a hard-to-round case for the target precisions. */
237 + mpfr_inits2 (64, t, y0, (mpfr_ptr) 0);
238 + mpfr_set_exp_t (y0, e, MPFR_RNDN);
239 + mpfr_log_ui (t, 10, MPFR_RNDN);
240 + mpfr_div (y0, y0, t, MPFR_RNDN);
241 + mpfr_log_ui (t, 2, MPFR_RNDN);
242 + mpfr_mul (y0, y0, t, MPFR_RNDN);
244 + for (prec = 16; prec >= MPFR_PREC_MIN; prec--)
246 + mpfr_inits2 (prec, x, y1, y2, (mpfr_ptr) 0);
247 + mpfr_set (y1, y0, MPFR_RNDN);
249 + mpfr_set_ui_2exp (x, 1, e, MPFR_RNDN);
250 + mpfr_log10 (y2, x, MPFR_RNDN);
251 + MPFR_ASSERTN (MPFR_IS_PURE_FP (y2));
252 + MPFR_ASSERTN (MPFR_IS_POS (y2));
254 + if (! mpfr_equal_p (y1, y2))
256 + printf ("Error in bug20230213.\n");
257 + printf ("Expected ");
258 + mpfr_dump (y1);
259 + printf ("Got ");
260 + mpfr_dump (y2);
261 + exit (1);
263 + mpfr_clears (x, y1, y2, (mpfr_ptr) 0);
266 + mpfr_clears (t, y0, (mpfr_ptr) 0);
268 + set_emin (old_emin);
269 + set_emax (old_emax);
273 main (int argc, char *argv[])
275 @@ -112,6 +166,8 @@
276 mpfr_clear (x);
277 mpfr_clear (y);
279 + bug20230213 ();
281 data_check ("data/log10", mpfr_log10, "mpfr_log10");
283 tests_end_mpfr ();
284 diff -Naurd mpfr-4.2.0-a/tests/tui_pow.c mpfr-4.2.0-b/tests/tui_pow.c
285 --- mpfr-4.2.0-a/tests/tui_pow.c 2023-01-05 17:09:48.000000000 +0000
286 +++ mpfr-4.2.0-b/tests/tui_pow.c 2023-04-17 21:18:00.504616070 +0000
287 @@ -142,6 +142,37 @@
288 mpfr_clear (t);
291 +static void
292 +huge (void)
294 + mpfr_exp_t old_emin, old_emax;
295 + mpfr_t x;
297 + old_emin = mpfr_get_emin ();
298 + old_emax = mpfr_get_emax ();
300 + set_emin (MPFR_EMIN_MIN);
301 + set_emax (MPFR_EMAX_MAX);
303 + mpfr_init2 (x, 8);
305 + /* The purpose of this test is more to check that mpfr_ui_pow_ui
306 + terminates (without taking much memory) rather than checking
307 + the value of x. On 2023-02-13, the +Inf case was not handled
308 + in the Ziv iteration, yielding an infinite loop, affecting
309 + mpfr_log10 in particular. See
310 + commit 90de094f0d9c309daca707aa227470d810866616
311 + */
312 + mpfr_ui_pow_ui (x, 5, ULONG_MAX, MPFR_RNDN);
313 + if (MPFR_EMAX_MAX <= ULONG_MAX) /* true with default _MPFR_EXP_FORMAT */
314 + MPFR_ASSERTN (MPFR_IS_INF (x));
316 + mpfr_clear (x);
318 + set_emin (old_emin);
319 + set_emax (old_emax);
323 main (int argc, char *argv[])
325 @@ -180,6 +211,7 @@
328 test1 ();
329 + huge ();
332 mpfr_t z, t;
333 diff -Naurd mpfr-4.2.0-a/PATCHES mpfr-4.2.0-b/PATCHES
334 --- mpfr-4.2.0-a/PATCHES 2023-04-17 21:18:26.860579184 +0000
335 +++ mpfr-4.2.0-b/PATCHES 2023-04-17 21:18:26.904579122 +0000
336 @@ -0,0 +1 @@
337 +multibyte-decimal_point
338 diff -Naurd mpfr-4.2.0-a/VERSION mpfr-4.2.0-b/VERSION
339 --- mpfr-4.2.0-a/VERSION 2023-04-17 21:18:00.512616059 +0000
340 +++ mpfr-4.2.0-b/VERSION 2023-04-17 21:18:26.904579122 +0000
341 @@ -1 +1 @@
342 -4.2.0-p2
343 +4.2.0-p3
344 diff -Naurd mpfr-4.2.0-a/src/mpfr.h mpfr-4.2.0-b/src/mpfr.h
345 --- mpfr-4.2.0-a/src/mpfr.h 2023-04-17 21:18:00.508616065 +0000
346 +++ mpfr-4.2.0-b/src/mpfr.h 2023-04-17 21:18:26.900579128 +0000
347 @@ -27,7 +27,7 @@
348 #define MPFR_VERSION_MAJOR 4
349 #define MPFR_VERSION_MINOR 2
350 #define MPFR_VERSION_PATCHLEVEL 0
351 -#define MPFR_VERSION_STRING "4.2.0-p2"
352 +#define MPFR_VERSION_STRING "4.2.0-p3"
354 /* User macros:
355 MPFR_USE_FILE: Define it to make MPFR define functions dealing
356 diff -Naurd mpfr-4.2.0-a/src/version.c mpfr-4.2.0-b/src/version.c
357 --- mpfr-4.2.0-a/src/version.c 2023-04-17 21:18:00.512616059 +0000
358 +++ mpfr-4.2.0-b/src/version.c 2023-04-17 21:18:26.904579122 +0000
359 @@ -25,5 +25,5 @@
360 const char *
361 mpfr_get_version (void)
363 - return "4.2.0-p2";
364 + return "4.2.0-p3";
366 diff -Naurd mpfr-4.2.0-a/tests/tfprintf.c mpfr-4.2.0-b/tests/tfprintf.c
367 --- mpfr-4.2.0-a/tests/tfprintf.c 2023-01-05 17:09:48.000000000 +0000
368 +++ mpfr-4.2.0-b/tests/tfprintf.c 2023-04-17 21:18:26.896579133 +0000
369 @@ -61,6 +61,12 @@
370 exit (1); \
373 +#if MPFR_LCONV_DPTS
374 +#define DPLEN ((int) strlen (localeconv()->decimal_point))
375 +#else
376 +#define DPLEN 1
377 +#endif
379 /* limit for random precision in random() */
380 const int prec_max_printf = 5000;
382 @@ -195,12 +201,12 @@
383 lo, &ulo);
384 check_length (2, ulo, 36, lu);
385 check_vfprintf (fout, "a. %hi, b. %*f, c. %Re%hn", ush, 3, f, mpfr, &ush);
386 - check_length (3, ush, 46, hu);
387 + check_length (3, ush, 45 + DPLEN, hu);
388 check_vfprintf (fout, "a. %hi, b. %f, c. %#.2Rf%n", sh, d, mpfr, &i);
389 - check_length (4, i, 29, d);
390 + check_length (4, i, 28 + DPLEN, d);
391 check_vfprintf (fout, "a. %R*A, b. %Fe, c. %i%zn", rnd, mpfr, mpf, sz,
392 &sz);
393 - check_length (5, (unsigned long) sz, 34, lu); /* no format specifier "%zu" in C90 */
394 + check_length (5, (unsigned long) sz, 33 + DPLEN, lu); /* no format specifier "%zu" in C90 */
395 check_vfprintf (fout, "a. %Pu, b. %c, c. %Zi%Zn", prec, ch, mpz, &mpz);
396 check_length_with_cmp (6, mpz, 17, mpz_cmp_ui (mpz, 17), Zi);
397 check_vfprintf (fout, "%% a. %#.0RNg, b. %Qx%Rn, c. %p", mpfr, mpq, &mpfr,
398 @@ -224,7 +230,7 @@
400 #ifdef PRINTF_L
401 check_vfprintf (fout, "a. %RA, b. %Lf, c. %QX%zn", mpfr, ld, mpq, &sz);
402 - check_length (9, (unsigned long) sz, 30, lu); /* no format specifier "%zu" in C90 */
403 + check_length (9, (unsigned long) sz, 29 + DPLEN, lu); /* no format specifier "%zu" in C90 */
404 #endif
406 #ifndef NPRINTF_HH
407 diff -Naurd mpfr-4.2.0-a/tests/tprintf.c mpfr-4.2.0-b/tests/tprintf.c
408 --- mpfr-4.2.0-a/tests/tprintf.c 2023-01-05 17:09:48.000000000 +0000
409 +++ mpfr-4.2.0-b/tests/tprintf.c 2023-04-17 21:18:26.896579133 +0000
410 @@ -68,6 +68,12 @@
411 exit (1); \
414 +#if MPFR_LCONV_DPTS
415 +#define DPLEN ((int) strlen (localeconv()->decimal_point))
416 +#else
417 +#define DPLEN 1
418 +#endif
420 /* limit for random precision in random() */
421 const int prec_max_printf = 5000;
422 /* boolean: is stdout redirected to a file ? */
423 @@ -316,11 +322,11 @@
424 check_vprintf ("a. %c, b. %Rb, c. %u, d. %li%ln", i, mpfr, i, lo, &ulo);
425 check_length (2, ulo, 36, lu);
426 check_vprintf ("a. %hi, b. %*f, c. %Re%hn", ush, 3, f, mpfr, &ush);
427 - check_length (3, ush, 46, hu);
428 + check_length (3, ush, 45 + DPLEN, hu);
429 check_vprintf ("a. %hi, b. %f, c. %#.2Rf%n", sh, d, mpfr, &i);
430 - check_length (4, i, 29, d);
431 + check_length (4, i, 28 + DPLEN, d);
432 check_vprintf ("a. %R*A, b. %Fe, c. %i%zn", rnd, mpfr, mpf, sz, &sz);
433 - check_length (5, (unsigned long) sz, 34, lu); /* no format specifier '%zu' in C90 */
434 + check_length (5, (unsigned long) sz, 33 + DPLEN, lu); /* no format specifier '%zu' in C90 */
435 check_vprintf ("a. %Pu, b. %c, c. %RUG, d. %Zi%Zn", prec, ch, mpfr, mpz, &mpz);
436 check_length_with_cmp (6, mpz, 24, mpz_cmp_ui (mpz, 24), Zi);
437 check_vprintf ("%% a. %#.0RNg, b. %Qx%Rn c. %p",
438 @@ -344,7 +350,7 @@
440 #ifdef PRINTF_L
441 check_vprintf ("a. %RA, b. %Lf, c. %QX%zn", mpfr, ld, mpq, &sz);
442 - check_length (9, (unsigned long) sz, 30, lu); /* no format specifier '%zu' in C90 */
443 + check_length (9, (unsigned long) sz, 29 + DPLEN, lu); /* no format specifier '%zu' in C90 */
444 #endif
446 #ifndef NPRINTF_HH
447 diff -Naurd mpfr-4.2.0-a/PATCHES mpfr-4.2.0-b/PATCHES
448 --- mpfr-4.2.0-a/PATCHES 2023-04-17 21:19:01.988530337 +0000
449 +++ mpfr-4.2.0-b/PATCHES 2023-04-17 21:19:02.032530276 +0000
450 @@ -0,0 +1 @@
451 +rec_sqrt-zivloop
452 diff -Naurd mpfr-4.2.0-a/VERSION mpfr-4.2.0-b/VERSION
453 --- mpfr-4.2.0-a/VERSION 2023-04-17 21:18:26.904579122 +0000
454 +++ mpfr-4.2.0-b/VERSION 2023-04-17 21:19:02.032530276 +0000
455 @@ -1 +1 @@
456 -4.2.0-p3
457 +4.2.0-p4
458 diff -Naurd mpfr-4.2.0-a/src/mpfr.h mpfr-4.2.0-b/src/mpfr.h
459 --- mpfr-4.2.0-a/src/mpfr.h 2023-04-17 21:18:26.900579128 +0000
460 +++ mpfr-4.2.0-b/src/mpfr.h 2023-04-17 21:19:02.032530276 +0000
461 @@ -27,7 +27,7 @@
462 #define MPFR_VERSION_MAJOR 4
463 #define MPFR_VERSION_MINOR 2
464 #define MPFR_VERSION_PATCHLEVEL 0
465 -#define MPFR_VERSION_STRING "4.2.0-p3"
466 +#define MPFR_VERSION_STRING "4.2.0-p4"
468 /* User macros:
469 MPFR_USE_FILE: Define it to make MPFR define functions dealing
470 diff -Naurd mpfr-4.2.0-a/src/rec_sqrt.c mpfr-4.2.0-b/src/rec_sqrt.c
471 --- mpfr-4.2.0-a/src/rec_sqrt.c 2023-01-05 17:09:48.000000000 +0000
472 +++ mpfr-4.2.0-b/src/rec_sqrt.c 2023-04-17 21:19:02.024530287 +0000
473 @@ -463,6 +463,7 @@
474 int s, cy, inex;
475 mpfr_limb_ptr x;
476 MPFR_TMP_DECL(marker);
477 + MPFR_ZIV_DECL (loop);
479 MPFR_LOG_FUNC
480 (("x[%Pu]=%.*Rg rnd=%d", mpfr_get_prec (u), mpfr_log_prec, u, rnd_mode),
481 @@ -530,6 +531,7 @@
482 wp = rp + 11;
483 if (wp < rn * GMP_NUMB_BITS)
484 wp = rn * GMP_NUMB_BITS;
485 + MPFR_ZIV_INIT (loop, wp);
486 for (;;)
488 MPFR_TMP_MARK (marker);
489 @@ -561,8 +563,9 @@
491 MPFR_TMP_FREE(marker);
493 - wp += GMP_NUMB_BITS;
494 + MPFR_ZIV_NEXT (loop, wp);
496 + MPFR_ZIV_FREE (loop);
497 cy = mpfr_round_raw (MPFR_MANT(r), x, wp, 0, rp, rnd_mode, &inex);
498 MPFR_EXP(r) = - (MPFR_EXP(u) - 1 - s) / 2;
499 if (MPFR_UNLIKELY(cy != 0))
500 diff -Naurd mpfr-4.2.0-a/src/version.c mpfr-4.2.0-b/src/version.c
501 --- mpfr-4.2.0-a/src/version.c 2023-04-17 21:18:26.904579122 +0000
502 +++ mpfr-4.2.0-b/src/version.c 2023-04-17 21:19:02.032530276 +0000
503 @@ -25,5 +25,5 @@
504 const char *
505 mpfr_get_version (void)
507 - return "4.2.0-p3";
508 + return "4.2.0-p4";
510 diff -Naurd mpfr-4.2.0-a/tests/trec_sqrt.c mpfr-4.2.0-b/tests/trec_sqrt.c
511 --- mpfr-4.2.0-a/tests/trec_sqrt.c 2023-01-05 17:09:48.000000000 +0000
512 +++ mpfr-4.2.0-b/tests/trec_sqrt.c 2023-04-17 21:19:02.028530282 +0000
513 @@ -242,6 +242,8 @@
514 data_check ("data/rec_sqrt", mpfr_rec_sqrt, "mpfr_rec_sqrt");
515 bad_cases (mpfr_rec_sqrt, pm2, "mpfr_rec_sqrt", 0, -256, 255, 4, 128,
516 800, 50);
517 + bad_cases (mpfr_rec_sqrt, pm2, "mpfr_rec_sqrt", 0, -256, 255, 9999, 9999,
518 + 120000, 1);
520 end:
521 tests_end_mpfr ();
522 diff -Naurd mpfr-4.2.0-a/PATCHES mpfr-4.2.0-b/PATCHES
523 --- mpfr-4.2.0-a/PATCHES 2023-05-12 15:05:00.989811960 +0000
524 +++ mpfr-4.2.0-b/PATCHES 2023-05-12 15:05:01.085811835 +0000
525 @@ -0,0 +1 @@
526 +reldiff
527 diff -Naurd mpfr-4.2.0-a/VERSION mpfr-4.2.0-b/VERSION
528 --- mpfr-4.2.0-a/VERSION 2023-04-17 21:19:02.032530276 +0000
529 +++ mpfr-4.2.0-b/VERSION 2023-05-12 15:05:01.085811835 +0000
530 @@ -1 +1 @@
531 -4.2.0-p4
532 +4.2.0-p5
533 diff -Naurd mpfr-4.2.0-a/src/mpfr.h mpfr-4.2.0-b/src/mpfr.h
534 --- mpfr-4.2.0-a/src/mpfr.h 2023-04-17 21:19:02.032530276 +0000
535 +++ mpfr-4.2.0-b/src/mpfr.h 2023-05-12 15:05:01.077811846 +0000
536 @@ -27,7 +27,7 @@
537 #define MPFR_VERSION_MAJOR 4
538 #define MPFR_VERSION_MINOR 2
539 #define MPFR_VERSION_PATCHLEVEL 0
540 -#define MPFR_VERSION_STRING "4.2.0-p4"
541 +#define MPFR_VERSION_STRING "4.2.0-p5"
543 /* User macros:
544 MPFR_USE_FILE: Define it to make MPFR define functions dealing
545 diff -Naurd mpfr-4.2.0-a/src/reldiff.c mpfr-4.2.0-b/src/reldiff.c
546 --- mpfr-4.2.0-a/src/reldiff.c 2023-01-05 17:09:48.000000000 +0000
547 +++ mpfr-4.2.0-b/src/reldiff.c 2023-05-12 15:05:01.069811856 +0000
548 @@ -30,31 +30,25 @@
550 if (MPFR_ARE_SINGULAR (b, c))
552 - if (MPFR_IS_NAN(b) || MPFR_IS_NAN(c))
554 - MPFR_SET_NAN(a);
555 - return;
557 - else if (MPFR_IS_INF(b))
558 + if (MPFR_IS_NAN (b) || MPFR_IS_INF (b) || MPFR_IS_NAN (c) ||
559 + (MPFR_IS_ZERO (b) && MPFR_IS_ZERO (c)))
561 - if (MPFR_IS_INF (c) && (MPFR_SIGN (c) == MPFR_SIGN (b)))
562 - MPFR_SET_ZERO(a);
563 - else
564 - MPFR_SET_NAN(a);
565 + MPFR_SET_NAN (a);
566 return;
568 - else if (MPFR_IS_INF(c))
569 + if (MPFR_IS_ZERO (b) || MPFR_IS_INF (c))
571 MPFR_SET_SAME_SIGN (a, b);
572 MPFR_SET_INF (a);
573 return;
575 - else if (MPFR_IS_ZERO(b)) /* reldiff = abs(c)/c = sign(c) */
577 - mpfr_set_si (a, MPFR_INT_SIGN (c), rnd_mode);
578 - return;
580 - /* Fall through */
581 + /* The case c = 0 with b regular, which should give sign(b) exactly,
582 + cannot be optimized here as it is documented in the MPFR manual
583 + that this function just computes abs(b-c)/b using the precision
584 + of a and the rounding mode rnd_mode for all operations. So let's
585 + prefer the potentially "incorrect" result. Note that the correct
586 + result is not necessarily better because if could break properties
587 + (like monotonicity?) implied by the documentation. */
590 if (a == b)
591 @@ -64,8 +58,8 @@
594 mpfr_sub (a, b, c, rnd_mode);
595 - mpfr_abs (a, a, rnd_mode); /* for compatibility with MPF */
596 - mpfr_div (a, a, (a == b) ? b_copy : b, rnd_mode);
597 + MPFR_SET_SIGN (a, 1);
598 + mpfr_div (a, a, a == b ? b_copy : b, rnd_mode);
600 if (a == b)
601 mpfr_clear (b_copy);
602 diff -Naurd mpfr-4.2.0-a/src/version.c mpfr-4.2.0-b/src/version.c
603 --- mpfr-4.2.0-a/src/version.c 2023-04-17 21:19:02.032530276 +0000
604 +++ mpfr-4.2.0-b/src/version.c 2023-05-12 15:05:01.081811839 +0000
605 @@ -25,5 +25,5 @@
606 const char *
607 mpfr_get_version (void)
609 - return "4.2.0-p4";
610 + return "4.2.0-p5";
612 diff -Naurd mpfr-4.2.0-a/PATCHES mpfr-4.2.0-b/PATCHES
613 --- mpfr-4.2.0-a/PATCHES 2023-05-12 15:06:11.789722083 +0000
614 +++ mpfr-4.2.0-b/PATCHES 2023-05-12 15:06:11.885721962 +0000
615 @@ -0,0 +1 @@
616 +tests-reuse
617 diff -Naurd mpfr-4.2.0-a/VERSION mpfr-4.2.0-b/VERSION
618 --- mpfr-4.2.0-a/VERSION 2023-05-12 15:05:01.085811835 +0000
619 +++ mpfr-4.2.0-b/VERSION 2023-05-12 15:06:11.885721962 +0000
620 @@ -1 +1 @@
621 -4.2.0-p5
622 +4.2.0-p6
623 diff -Naurd mpfr-4.2.0-a/src/mpfr.h mpfr-4.2.0-b/src/mpfr.h
624 --- mpfr-4.2.0-a/src/mpfr.h 2023-05-12 15:05:01.077811846 +0000
625 +++ mpfr-4.2.0-b/src/mpfr.h 2023-05-12 15:06:11.877721972 +0000
626 @@ -27,7 +27,7 @@
627 #define MPFR_VERSION_MAJOR 4
628 #define MPFR_VERSION_MINOR 2
629 #define MPFR_VERSION_PATCHLEVEL 0
630 -#define MPFR_VERSION_STRING "4.2.0-p5"
631 +#define MPFR_VERSION_STRING "4.2.0-p6"
633 /* User macros:
634 MPFR_USE_FILE: Define it to make MPFR define functions dealing
635 diff -Naurd mpfr-4.2.0-a/src/version.c mpfr-4.2.0-b/src/version.c
636 --- mpfr-4.2.0-a/src/version.c 2023-05-12 15:05:01.081811839 +0000
637 +++ mpfr-4.2.0-b/src/version.c 2023-05-12 15:06:11.885721962 +0000
638 @@ -25,5 +25,5 @@
639 const char *
640 mpfr_get_version (void)
642 - return "4.2.0-p5";
643 + return "4.2.0-p6";
645 diff -Naurd mpfr-4.2.0-a/tests/reuse.c mpfr-4.2.0-b/tests/reuse.c
646 --- mpfr-4.2.0-a/tests/reuse.c 2023-01-05 17:09:48.000000000 +0000
647 +++ mpfr-4.2.0-b/tests/reuse.c 2023-05-12 15:06:11.869721983 +0000
648 @@ -78,22 +78,16 @@
649 mpfr_const_pi (x, MPFR_RNDN);
650 MPFR_SET_EXP (x, MPFR_GET_EXP (x)-1);
651 break;
652 - default:
653 + case 11:
654 mpfr_urandomb (x, RANDS);
655 if (RAND_BOOL ())
656 mpfr_neg (x, x, MPFR_RNDN);
657 break;
658 + default:
659 + MPFR_ASSERTN (0);
663 -/* same as mpfr_cmp, but returns 0 for both NaN's */
664 -static int
665 -mpfr_compare (mpfr_srcptr a, mpfr_srcptr b)
667 - return (MPFR_IS_NAN(a)) ? !MPFR_IS_NAN(b) :
668 - (MPFR_IS_NAN(b) || mpfr_cmp(a, b));
671 static void
672 test3 (int (*testfunc)(mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_rnd_t),
673 const char *foo, mpfr_prec_t prec, mpfr_rnd_t rnd)
674 @@ -112,10 +106,10 @@
676 /* for each variable, consider each of the following 6 possibilities:
677 NaN, +Infinity, -Infinity, +0, -0 or a random number */
678 - for (i=0; i < SPECIAL_MAX*SPECIAL_MAX ; i++)
679 + for (i = 0; i < SPECIAL_MAX * SPECIAL_MAX; i++)
681 - set_special (ref2, i%SPECIAL_MAX);
682 - set_special (ref3, i/SPECIAL_MAX);
683 + set_special (ref2, i % SPECIAL_MAX);
684 + set_special (ref3, i / SPECIAL_MAX);
686 /* reference call: foo(a, b, c) */
687 testfunc (ref1, ref2, ref3, rnd);
688 @@ -124,11 +118,11 @@
689 mpfr_set (res1, ref2, rnd); /* exact operation */
690 testfunc (res1, res1, ref3, rnd);
692 - if (mpfr_compare (res1, ref1))
693 + if (! SAME_VAL (res1, ref1))
695 printf ("Error for %s(a, a, c) with %s for ", foo,
696 mpfr_print_rnd_mode (rnd));
697 - DISP("a=",ref2); DISP2(", c=",ref3);
698 + DISP("a=", ref2); DISP2(", c=", ref3);
699 printf ("expected "); mpfr_dump (ref1);
700 printf ("got "); mpfr_dump (res1);
701 exit (1);
702 @@ -137,11 +131,12 @@
703 /* foo(a, b, a) */
704 mpfr_set (res1, ref3, rnd);
705 testfunc (res1, ref2, res1, rnd);
706 - if (mpfr_compare (res1, ref1))
707 + if (! SAME_VAL (res1, ref1))
709 printf ("Error for %s(a, b, a) for ", foo);
710 - DISP("b=",ref2); DISP2(", a=", ref3);
711 - DISP("expected ", ref1); DISP2(", got ",res1);
712 + DISP("b=", ref2); DISP2(", a=", ref3);
713 + printf ("expected "); mpfr_dump (ref1);
714 + printf ("got "); mpfr_dump (res1);
715 exit (1);
718 @@ -151,11 +146,12 @@
719 mpfr_set (res1, ref2, rnd);
720 testfunc (res1, res1, res1, rnd);
722 - if (mpfr_compare (res1, ref1))
723 + if (! SAME_VAL (res1, ref1))
725 printf ("Error for %s(a, a, a) for ", foo);
726 - DISP2("a=",ref2);
727 - DISP("expected ", ref1); DISP2(", got ", res1);
728 + DISP2("a=", ref2);
729 + printf ("expected "); mpfr_dump (ref1);
730 + printf ("got "); mpfr_dump (res1);
731 exit (1);
734 @@ -187,13 +183,13 @@
735 /* for each variable, consider each of the following 6 possibilities:
736 NaN, +Infinity, -Infinity, +0, -0 or a random number */
738 - for (i=0; i<SPECIAL_MAX; i++)
739 + for (i = 0; i < SPECIAL_MAX; i++)
741 set_special (op1, i);
742 - for (j=0; j<SPECIAL_MAX; j++)
743 + for (j = 0; j < SPECIAL_MAX; j++)
745 set_special (op2, j);
746 - for (k=0; k<SPECIAL_MAX; k++)
747 + for (k = 0; k < SPECIAL_MAX; k++)
749 set_special (op3, k);
751 @@ -204,11 +200,12 @@
752 mpfr_set (res, op1, rnd); /* exact operation */
753 testfunc (res, res, op2, op3, rnd);
755 - if (mpfr_compare (res, ref))
756 + if (! SAME_VAL (res, ref))
758 printf ("Error for %s(a, a, b, c) for ", foo);
759 DISP("a=", op1); DISP(", b=", op2); DISP2(", c=", op3);
760 - DISP("expected ", ref); DISP2(", got ", res);
761 + printf ("expected "); mpfr_dump (ref);
762 + printf ("got "); mpfr_dump (res);
763 exit (1);
766 @@ -216,11 +213,12 @@
767 mpfr_set (res, op2, rnd);
768 testfunc (res, op1, res, op3, rnd);
770 - if (mpfr_compare (res, ref))
771 + if (! SAME_VAL (res, ref))
773 printf ("Error for %s(a, a, b, c) for ", foo);
774 DISP("a=", op1); DISP(", b=", op2); DISP2(", c=", op3);
775 - DISP("expected ", ref); DISP2(", got ", res);
776 + printf ("expected "); mpfr_dump (ref);
777 + printf ("got "); mpfr_dump (res);
778 exit (1);
781 @@ -228,35 +226,38 @@
782 mpfr_set (res, op3, rnd);
783 testfunc (res, op1, op2, res, rnd);
785 - if (mpfr_compare (res, ref))
786 + if (! SAME_VAL (res, ref))
788 printf ("Error for %s(a, a, b, c) for ", foo);
789 DISP("a=", op1); DISP(", b=", op2); DISP2(", c=", op3);
790 - DISP("expected ", ref); DISP2(", got ", res);
791 + printf ("expected "); mpfr_dump (ref);
792 + printf ("got "); mpfr_dump (res);
793 exit (1);
796 - /* foo(a, a, a,c) */
797 + /* foo(a, a, a, c) */
798 testfunc (ref, op1, op1, op3, rnd);
799 mpfr_set (res, op1, rnd);
800 testfunc (res, res, res, op3, rnd);
801 - if (mpfr_compare (res, ref))
802 + if (! SAME_VAL (res, ref))
804 printf ("Error for %s(a, a, b, c) for ", foo);
805 DISP("a=", op1); DISP(", a=", op2); DISP2(", c=", op3);
806 - DISP("expected ", ref); DISP2(", got ", res);
807 + printf ("expected "); mpfr_dump (ref);
808 + printf ("got "); mpfr_dump (res);
809 exit (1);
812 - /* foo(a, a, b,a) */
813 + /* foo(a, a, b, a) */
814 testfunc (ref, op1, op2, op1, rnd);
815 mpfr_set (res, op1, rnd);
816 testfunc (res, res, op2, res, rnd);
817 - if (mpfr_compare (res, ref))
818 + if (! SAME_VAL (res, ref))
820 printf ("Error for %s(a, a, b, c) for ", foo);
821 DISP("a=", op1); DISP(", a=", op2); DISP2(", c=", op3);
822 - DISP("expected ", ref); DISP2(", got ", res);
823 + printf ("expected "); mpfr_dump (ref);
824 + printf ("got "); mpfr_dump (res);
825 exit (1);
828 @@ -264,11 +265,12 @@
829 testfunc (ref, op1, op2, op2, rnd);
830 mpfr_set (res, op2, rnd);
831 testfunc (res, op1, res, res, rnd);
832 - if (mpfr_compare (res, ref))
833 + if (! SAME_VAL (res, ref))
835 printf ("Error for %s(a, a, b, c) for ", foo);
836 DISP("a=", op1); DISP(", a=", op2); DISP2(", c=", op3);
837 - DISP("expected ", ref); DISP2(", got ", res);
838 + printf ("expected "); mpfr_dump (ref);
839 + printf ("got "); mpfr_dump (res);
840 exit (1);
843 @@ -276,11 +278,12 @@
844 testfunc (ref, op1, op1, op1, rnd);
845 mpfr_set (res, op1, rnd);
846 testfunc (res, res, res, res, rnd);
847 - if (mpfr_compare (res, ref))
848 + if (! SAME_VAL (res, ref))
850 printf ("Error for %s(a, a, a, a) for ", foo);
851 DISP2("a=", op1);
852 - DISP("expected ", ref); DISP2(", got ", res);
853 + printf ("expected "); mpfr_dump (ref);
854 + printf ("got "); mpfr_dump (res);
855 exit (1);
858 @@ -313,10 +316,10 @@
860 /* ref2 can be NaN, +Inf, -Inf, +0, -0 or any number
861 ref3 can be 0 or any number */
862 - for (i=0; i<SPECIAL_MAX*2; i++)
863 + for (i = 0; i < SPECIAL_MAX * 2; i++)
865 - set_special (ref2, i%SPECIAL_MAX);
866 - ref3 = i/SPECIAL_MAX == 0 ? 0 : randlimb ();
867 + set_special (ref2, i % SPECIAL_MAX);
868 + ref3 = i / SPECIAL_MAX == 0 ? 0 : randlimb ();
870 /* reference call: foo(a, b, c) */
871 testfunc (ref1, ref2, ref3, rnd);
872 @@ -325,10 +328,10 @@
873 mpfr_set (res1, ref2, rnd); /* exact operation */
874 testfunc (res1, res1, ref3, rnd);
876 - if (mpfr_compare (res1, ref1))
877 + if (! SAME_VAL (res1, ref1))
879 printf ("Error for %s(a, a, c) for c=%u\n", foo, ref3);
880 - DISP2("a=",ref2);
881 + DISP2("a=", ref2);
882 printf ("expected "); mpfr_dump (ref1);
883 printf ("got "); mpfr_dump (res1);
884 exit (1);
885 @@ -356,10 +359,10 @@
886 mpfr_init2 (ref3, prec);
887 mpfr_init2 (res1, prec);
889 - for (i=0; i<SPECIAL_MAX*2; i++)
890 + for (i = 0; i < SPECIAL_MAX * 2; i++)
892 - set_special (ref3, i%SPECIAL_MAX);
893 - ref2 = i/SPECIAL_MAX==0 ? 0 : randlimb ();
894 + set_special (ref3, i % SPECIAL_MAX);
895 + ref2 = i / SPECIAL_MAX == 0 ? 0 : randlimb ();
897 /* reference call: foo(a, b, c) */
898 testfunc (ref1, ref2, ref3, rnd);
899 @@ -367,7 +370,7 @@
900 /* foo(a, b, a) */
901 mpfr_set (res1, ref3, rnd); /* exact operation */
902 testfunc (res1, ref2, res1, rnd);
903 - if (mpfr_compare (res1, ref1))
904 + if (! SAME_VAL (res1, ref1))
906 printf ("Error for %s(a, b, a) for b=%u \n", foo, ref2);
907 DISP2("a=", ref3);
908 @@ -397,7 +400,7 @@
909 mpfr_init2 (ref2, prec);
910 mpfr_init2 (res1, prec);
912 - for (i=0; i<SPECIAL_MAX; i++)
913 + for (i = 0; i < SPECIAL_MAX; i++)
915 set_special (ref2, i);
917 @@ -407,7 +410,7 @@
918 /* foo(a, a) */
919 mpfr_set (res1, ref2, rnd); /* exact operation */
920 testfunc (res1, res1, rnd);
921 - if (mpfr_compare (res1, ref1))
922 + if (! SAME_VAL (res1, ref1))
924 printf ("Error for %s(a, a) for ", foo);
925 DISP2("a=", ref2);
926 @@ -437,7 +440,7 @@
927 mpfr_init2 (ref2, prec);
928 mpfr_init2 (res1, prec);
930 - for (i=0; i<SPECIAL_MAX; i++)
931 + for (i = 0; i < SPECIAL_MAX; i++)
933 set_special (ref2, i);
935 @@ -447,10 +450,10 @@
936 /* foo(a, a) */
937 mpfr_set (res1, ref2, MPFR_RNDN); /* exact operation */
938 testfunc (res1, res1);
939 - if (mpfr_compare (res1, ref1))
940 + if (! SAME_VAL (res1, ref1))
942 printf ("Error for %s(a, a) for ", foo);
943 - DISP2("a=",ref2);
944 + DISP2("a=", ref2);
945 DISP("expected", ref1); DISP2(", got ", res1);
946 exit (1);
948 @@ -479,7 +482,7 @@
949 mpfr_init2 (res1, prec);
950 mpfr_init2 (res2, prec);
952 - for (i=0; i<SPECIAL_MAX; i++)
953 + for (i = 0; i < SPECIAL_MAX; i++)
955 set_special (ref3, i);
957 @@ -489,12 +492,12 @@
958 /* foo(a, b, a) */
959 mpfr_set (res1, ref3, rnd); /* exact operation */
960 testfunc (res1, res2, res1, rnd);
961 - if (mpfr_compare (res1, ref1) || mpfr_compare (res2, ref2))
962 + if (! SAME_VAL (res1, ref1) || ! SAME_VAL (res2, ref2))
964 printf ("Error for %s(a, b, a) for rnd=%s, ", foo,
965 mpfr_print_rnd_mode (rnd));
966 - DISP2("a=",ref3);
967 - DISP("expected (", ref1); DISP(",",ref2);
968 + DISP2("a=", ref3);
969 + DISP("expected (", ref1); DISP(",", ref2);
970 DISP("), got (", res1); DISP(",", res2); printf(")\n");
971 exit (1);
973 @@ -502,11 +505,11 @@
974 /* foo(a, b, b) */
975 mpfr_set (res2, ref3, rnd); /* exact operation */
976 testfunc (res1, res2, res2, rnd);
977 - if (mpfr_compare (res1, ref1) || mpfr_compare (res2, ref2))
978 + if (! SAME_VAL (res1, ref1) || ! SAME_VAL (res2, ref2))
980 printf ("Error for %s(a, b, b) for ", foo);
981 - DISP2("b=",ref3);
982 - DISP("expected (", ref1); DISP(",",ref2);
983 + DISP2("b=", ref3);
984 + DISP("expected (", ref1); DISP(",", ref2);
985 DISP("), got (", res1); DISP(",", res2); printf(")\n");
986 exit (1);
988 @@ -561,10 +564,10 @@
989 mpfr_set (res1, ref2, rnd); /* exact operation */
990 mpfr_pow (res1, res1, ref3, rnd);
992 - if (mpfr_compare (res1, ref1))
993 + if (! SAME_VAL (res1, ref1))
995 printf ("Error for pow_int(a, a, c) for ");
996 - DISP("a=",ref2); DISP2(", c=",ref3);
997 + DISP("a=", ref2); DISP2(", c=", ref3);
998 printf ("expected "); mpfr_dump (ref1);
999 printf ("got "); mpfr_dump (res1);
1000 exit (1);
1001 diff -Naurd mpfr-4.2.0-a/PATCHES mpfr-4.2.0-b/PATCHES
1002 --- mpfr-4.2.0-a/PATCHES 2023-05-12 15:08:39.233546717 +0000
1003 +++ mpfr-4.2.0-b/PATCHES 2023-05-12 15:08:39.325546612 +0000
1004 @@ -0,0 +1 @@
1005 +pow_general
1006 diff -Naurd mpfr-4.2.0-a/VERSION mpfr-4.2.0-b/VERSION
1007 --- mpfr-4.2.0-a/VERSION 2023-05-12 15:06:11.885721962 +0000
1008 +++ mpfr-4.2.0-b/VERSION 2023-05-12 15:08:39.325546612 +0000
1009 @@ -1 +1 @@
1010 -4.2.0-p6
1011 +4.2.0-p7
1012 diff -Naurd mpfr-4.2.0-a/src/mpfr.h mpfr-4.2.0-b/src/mpfr.h
1013 --- mpfr-4.2.0-a/src/mpfr.h 2023-05-12 15:06:11.877721972 +0000
1014 +++ mpfr-4.2.0-b/src/mpfr.h 2023-05-12 15:08:39.321546616 +0000
1015 @@ -27,7 +27,7 @@
1016 #define MPFR_VERSION_MAJOR 4
1017 #define MPFR_VERSION_MINOR 2
1018 #define MPFR_VERSION_PATCHLEVEL 0
1019 -#define MPFR_VERSION_STRING "4.2.0-p6"
1020 +#define MPFR_VERSION_STRING "4.2.0-p7"
1022 /* User macros:
1023 MPFR_USE_FILE: Define it to make MPFR define functions dealing
1024 diff -Naurd mpfr-4.2.0-a/src/pow.c mpfr-4.2.0-b/src/pow.c
1025 --- mpfr-4.2.0-a/src/pow.c 2023-01-05 17:09:48.000000000 +0000
1026 +++ mpfr-4.2.0-b/src/pow.c 2023-05-12 15:08:39.309546630 +0000
1027 @@ -131,7 +131,6 @@
1028 /* Declaration of the size variable */
1029 mpfr_prec_t Nz = MPFR_PREC(z); /* target precision */
1030 mpfr_prec_t Nt; /* working precision */
1031 - mpfr_exp_t err; /* error */
1032 MPFR_ZIV_DECL (ziv_loop);
1034 MPFR_LOG_FUNC
1035 @@ -171,12 +170,14 @@
1036 MPFR_ZIV_INIT (ziv_loop, Nt);
1037 for (;;)
1039 + mpfr_exp_t err, exp_t;
1040 MPFR_BLOCK_DECL (flags1);
1042 /* compute exp(y*ln|x|), using MPFR_RNDU to get an upper bound, so
1043 that we can detect underflows. */
1044 mpfr_log (t, absx, MPFR_IS_NEG (y) ? MPFR_RNDD : MPFR_RNDU); /* ln|x| */
1045 mpfr_mul (t, y, t, MPFR_RNDU); /* y*ln|x| */
1046 + exp_t = MPFR_GET_EXP (t);
1047 if (k_non_zero)
1049 MPFR_LOG_MSG (("subtract k * ln(2)\n", 0));
1050 @@ -188,14 +189,16 @@
1051 MPFR_LOG_VAR (t);
1053 /* estimate of the error -- see pow function in algorithms.tex.
1054 - The error on t is at most 1/2 + 3*2^(EXP(t)+1) ulps, which is
1055 - <= 2^(EXP(t)+3) for EXP(t) >= -1, and <= 2 ulps for EXP(t) <= -2.
1056 + The error on t before the subtraction of k*log(2) is at most
1057 + 1/2 + 3*2^(EXP(t)+1) ulps, which is <= 2^(EXP(t)+3) for EXP(t) >= -1,
1058 + and <= 2 ulps for EXP(t) <= -2.
1059 Additional error if k_no_zero: treal = t * errk, with
1060 1 - |k| * 2^(-Nt) <= exp(-|k| * 2^(-Nt)) <= errk <= 1,
1061 i.e., additional absolute error <= 2^(EXP(k)+EXP(t)-Nt).
1062 - Total error <= 2^err1 + 2^err2 <= 2^(max(err1,err2)+1). */
1063 - err = MPFR_NOTZERO (t) && MPFR_GET_EXP (t) >= -1 ?
1064 - MPFR_GET_EXP (t) + 3 : 1;
1065 + Total ulp error <= 2^err1 + 2^err2 <= 2^(max(err1,err2)+1),
1066 + where err1 = EXP(t)+3 for EXP(t) >= -1, and 1 otherwise,
1067 + and err2 = EXP(k). */
1068 + err = MPFR_NOTZERO (t) && exp_t >= -1 ? exp_t + 3 : 1;
1069 if (k_non_zero)
1071 if (MPFR_GET_EXP (k) > err)
1072 @@ -328,11 +331,17 @@
1074 if (rnd_mode == MPFR_RNDN && inexact < 0 && lk < 0 &&
1075 MPFR_GET_EXP (z) == __gmpfr_emin - 1 - lk && mpfr_powerof2_raw (z))
1076 - /* Rounding to nearest, real result > z * 2^k = 2^(emin - 2),
1077 - * underflow case: we will obtain the correct result and exceptions
1078 - * by replacing z by nextabove(z).
1079 - */
1080 - mpfr_nextabove (z);
1081 + /* Rounding to nearest, exact result > z * 2^k = 2^(emin - 2),
1082 + * and underflow case because the rounded result assuming an
1083 + * unbounded exponent range is 2^(emin - 2). We need to round
1084 + * to 2^(emin - 1), i.e. to round toward +inf.
1085 + * Note: the old code was using "mpfr_nextabove (z);" instead of
1086 + * setting rnd_mode to MPFR_RNDU for the call to mpfr_mul_2si, but
1087 + * this was incorrect in precision 1 because in this precision,
1088 + * mpfr_nextabove gave 2^(emin - 1), which is representable,
1089 + * so that mpfr_mul_2si did not generate the wanted underflow
1090 + * (the value was correct, but the underflow flag was missing). */
1091 + rnd_mode = MPFR_RNDU;
1092 MPFR_CLEAR_FLAGS ();
1093 inex2 = mpfr_mul_2si (z, z, lk, rnd_mode);
1094 if (inex2) /* underflow or overflow */
1095 diff -Naurd mpfr-4.2.0-a/src/version.c mpfr-4.2.0-b/src/version.c
1096 --- mpfr-4.2.0-a/src/version.c 2023-05-12 15:06:11.885721962 +0000
1097 +++ mpfr-4.2.0-b/src/version.c 2023-05-12 15:08:39.325546612 +0000
1098 @@ -25,5 +25,5 @@
1099 const char *
1100 mpfr_get_version (void)
1102 - return "4.2.0-p6";
1103 + return "4.2.0-p7";
1105 diff -Naurd mpfr-4.2.0-a/tests/texp10.c mpfr-4.2.0-b/tests/texp10.c
1106 --- mpfr-4.2.0-a/tests/texp10.c 2023-01-05 17:09:48.000000000 +0000
1107 +++ mpfr-4.2.0-b/tests/texp10.c 2023-05-12 15:08:39.309546630 +0000
1108 @@ -190,6 +190,187 @@
1109 mpfr_clear (y);
1112 +/* Bug in mpfr_pow_general found by ofuf_thresholds (on 2023-02-13 for
1113 + a 32-bit exponent, changed on 2023-03-06 for a 64-bit exponent too),
1114 + fixed in commit b62966df913f73f08b3c5252e1d0c702bc20442f.
1115 + With a 32-bit exponent, failure for i=0.
1116 + expected 0.1111E1073741823
1117 + got @Inf@
1118 + expected flags = inexact (8)
1119 + got flags = overflow inexact (10)
1120 + With a 64-bit exponent, failure for i=1.
1121 + expected 0.11111111111111111111111E4611686018427387903
1122 + got @Inf@
1123 + expected flags = inexact (8)
1124 + got flags = overflow inexact (10)
1125 + Note: ofuf_thresholds was added to the master branch, but for the
1126 + time being, there are issues with these tests.
1128 +static void
1129 +bug20230213 (void)
1131 + const char *s[2] = {
1132 + "0x1.34413504b3ccdbd5dd8p+28",
1133 + "0x1.34413509f79fef2c4e0dd14a7ae0ecfbacdbp+60"
1134 + };
1135 + mpfr_t x1, x2, y1, y2;
1136 + mpfr_prec_t px[2] = { 74, 147 };
1137 + mpfr_prec_t py[2] = { 4, 23 };
1138 + mpfr_exp_t old_emax, emax;
1139 + mpfr_flags_t flags1, flags2;
1140 + int i;
1142 + old_emax = mpfr_get_emax ();
1144 + for (i = 0; i < 2; i++)
1146 + if (i != 0)
1147 + set_emax (MPFR_EMAX_MAX);
1149 + emax = mpfr_get_emax ();
1151 + mpfr_inits2 (px[i], x1, x2, (mpfr_ptr) 0);
1152 + mpfr_inits2 (py[i], y1, y2, (mpfr_ptr) 0);
1154 + mpfr_setmax (y1, emax);
1155 + mpfr_log10 (x1, y1, MPFR_RNDD);
1156 + mpfr_set_str (x2, s[i], 0, MPFR_RNDN);
1157 + /* For i == 0, emax == 2^30, so that the value can be checked.
1158 + For i != 0, check the value for the case emax == 2^62.
1159 + The "0UL" ensures that the shifts are valid. */
1160 + if (i == 0 || (((0UL + MPFR_EMAX_MAX) >> 31) >> 30) == 1)
1162 + /* printf ("Checking x1 for i=%d\n", i); */
1163 + MPFR_ASSERTN (mpfr_equal_p (x1, x2));
1166 + /* Let MAXF be the maximum finite value (y1 above).
1167 + Since x1 < log10(MAXF), one should have exp10(x1) < MAXF, and
1168 + therefore, y2 = RU(exp10(x1)) <= RU(MAXF) = MAXF (no overflow). */
1169 + flags1 = MPFR_FLAGS_INEXACT;
1170 + mpfr_clear_flags ();
1171 + mpfr_exp10 (y2, x1, MPFR_RNDU);
1172 + flags2 = __gmpfr_flags;
1174 + if (! (mpfr_lessequal_p (y2, y1) && flags2 == flags1))
1176 + printf ("Error in bug20230213 for i=%d\n", i);
1177 + printf ("emax = %" MPFR_EXP_FSPEC "d\n", (mpfr_eexp_t) emax);
1178 + printf ("expected "); mpfr_dump (y1);
1179 + printf ("got "); mpfr_dump (y2);
1180 + printf ("expected flags =");
1181 + flags_out (flags1);
1182 + printf ("got flags =");
1183 + flags_out (flags2);
1184 + exit (1);
1187 + mpfr_clears (x1, x2, y1, y2, (mpfr_ptr) 0);
1190 + set_emax (old_emax);
1193 +/* Bug in mpfr_pow_general in precision 1 in the particular case of
1194 + rounding to nearest, z * 2^k = 2^(emin - 2) and real result larger
1195 + than this value; fixed in ff5012b61d5e5fee5156c57b8aa8fc1739c2a771
1196 + (which is simplified in 4f5de980be290687ac1409aa02873e9e0dd1a030);
1197 + initially found by ofuf_thresholds (though the test was incorrect).
1198 + With a 32-bit exponent, failure for i=0.
1199 + With a 64-bit exponent, failure for i=1.
1200 + The result was correct, but the underflow flag was missing.
1201 + Note: ofuf_thresholds was added to the master branch, but for the
1202 + time being, there are issues with these tests.
1204 +static void
1205 +bug20230427 (void)
1207 + const char *s[2] = {
1208 + "-0.1001101000100000100110101000011E29",
1209 + "-0.100110100010000010011010100001001111101111001111111101111001101E61"
1210 + };
1211 + mpfr_t x, y, z, t1, t2;
1212 + mpfr_exp_t old_emin;
1213 + mpfr_flags_t flags, ex_flags;
1214 + int i, inex;
1216 + old_emin = mpfr_get_emin ();
1218 + mpfr_init2 (x, 63);
1219 + mpfr_inits2 (1, y, z, (mpfr_ptr) 0);
1220 + mpfr_inits2 (128, t1, t2, (mpfr_ptr) 0);
1222 + for (i = 0; i < 2; i++)
1224 + if (i == 0)
1226 + /* Basic check: the default emin should be -2^30 (exactly). */
1227 + if (mpfr_get_emin () != -1073741823)
1228 + abort ();
1230 + else
1232 + /* This test assumes that MPFR_EMIN_MIN = -2^62 (exactly).
1233 + The "0UL" ensures that the shifts are valid. */
1234 + if ((((0UL - MPFR_EMIN_MIN) >> 31) >> 30) != 1)
1235 + break;
1237 + set_emin (MPFR_EMIN_MIN);
1240 + mpfr_set_str_binary (x, s[i]);
1242 + /* We will test 10^x rounded to nearest in precision 1.
1243 + Check that 2^(emin - 2) < 10^x < (3/2) * 2^(emin - 2).
1244 + This is approximate, but by outputting the values, one can check
1245 + that one is not too close to the boundaries:
1246 + emin - 2 = -4611686018427387905
1247 + log2(10^x) ~= -4611686018427387904.598
1248 + emin - 2 + log2(3/2) ~= -4611686018427387904.415
1249 + Thus the result should be the smallest positive number 2^(emin - 1)
1250 + because 10^x is closer to this number than to 0, the midpoint being
1251 + 2^(emin - 2). And there should be an underflow in precision 1 because
1252 + the result rounded to nearest in an unbounded exponent range should
1253 + have been 2^(emin - 2), the midpoint being (3/2) * 2^(emin - 2).
1254 + */
1255 + mpfr_set_ui (t1, 10, MPFR_RNDN);
1256 + mpfr_log2 (t2, t1, MPFR_RNDN);
1257 + mpfr_mul (t1, t2, x, MPFR_RNDN);
1258 + inex = mpfr_set_exp_t (t2, mpfr_get_emin () - 2, MPFR_RNDN);
1259 + MPFR_ASSERTN (inex == 0);
1260 + MPFR_ASSERTN (mpfr_greater_p (t1, t2)); /* log2(10^x) > emin - 2 */
1261 + inex = mpfr_sub (t1, t1, t2, MPFR_RNDN);
1262 + MPFR_ASSERTN (inex == 0);
1263 + mpfr_set_ui (t2, 3, MPFR_RNDN);
1264 + mpfr_log2 (t2, t2, MPFR_RNDN);
1265 + mpfr_sub_ui (t2, t2, 1, MPFR_RNDN); /* log2(3/2) */
1266 + MPFR_ASSERTN (mpfr_less_p (t1, t2));
1268 + mpfr_clear_flags ();
1269 + mpfr_exp10 (y, x, MPFR_RNDN);
1270 + flags = __gmpfr_flags;
1271 + ex_flags = MPFR_FLAGS_UNDERFLOW | MPFR_FLAGS_INEXACT;
1273 + mpfr_setmin (z, mpfr_get_emin ()); /* z = 0.1@emin */
1274 + if (! (mpfr_equal_p (y, z) && flags == ex_flags))
1276 + printf ("Error in bug20230427 for i=%d\n", i);
1277 + printf ("expected "); mpfr_dump (z);
1278 + printf ("got "); mpfr_dump (y);
1279 + printf ("emin = %" MPFR_EXP_FSPEC "d\n",
1280 + (mpfr_eexp_t) mpfr_get_emin ());
1281 + printf ("expected flags =");
1282 + flags_out (ex_flags);
1283 + printf ("got flags =");
1284 + flags_out (flags);
1285 + exit (1);
1289 + mpfr_clears (x, y, z, t1, t2, (mpfr_ptr) 0);
1290 + set_emin (old_emin);
1294 main (int argc, char *argv[])
1296 @@ -199,6 +380,9 @@
1298 tests_start_mpfr ();
1300 + bug20230213 ();
1301 + bug20230427 ();
1303 special_overflow ();
1304 emax_m_eps ();
1305 exp_range ();