wok view mpfr/stuff/mpfr-3.1.0.patch @ rev 13984

midori: up to 0.4.8
author ernia <monghitri@aruba.it>
date Fri Feb 08 18:12:00 2013 +0000 (2013-02-08)
parents
children
line source
1 Submitted By: Matt Burgess <matthew_at_linuxfromscratch_dot_org>
2 Date: 2011-12-22
3 Initial Package Version: 3.1.0
4 Upstream Status: Already in upstream patch repo
5 Origin: Upstream
6 Description: This patch contains patches for several bugs in MPFR,
7 the main one being a rounding related error with the
8 mpfr_*printf functions.
10 diff -Naur mpfr-3.1.0.orig/PATCHES mpfr-3.1.0/PATCHES
11 --- mpfr-3.1.0.orig/PATCHES 2011-10-03 08:17:15.000000000 +0000
12 +++ mpfr-3.1.0/PATCHES 2011-12-22 11:08:42.188819413 +0000
13 @@ -0,0 +1,4 @@
14 +gmp41compat
15 +vasprintf
16 +lib-search-path
17 +mpfr_unlikely
18 diff -Naur mpfr-3.1.0.orig/VERSION mpfr-3.1.0/VERSION
19 --- mpfr-3.1.0.orig/VERSION 2011-10-03 08:17:15.000000000 +0000
20 +++ mpfr-3.1.0/VERSION 2011-11-28 12:22:52.000000000 +0000
21 @@ -1 +1 @@
22 -3.1.0
23 +3.1.0-p4
24 diff -Naur mpfr-3.1.0.orig/doc/mpfr.info mpfr-3.1.0/doc/mpfr.info
25 --- mpfr-3.1.0.orig/doc/mpfr.info 2011-10-03 09:43:04.000000000 +0000
26 +++ mpfr-3.1.0/doc/mpfr.info 2011-11-28 12:22:52.000000000 +0000
27 @@ -2994,11 +2994,12 @@
29 * `mpfr_urandom' and `mpfr_urandomb' changed in MPFR 3.1. Their
30 behavior no longer depends on the platform (assuming this is also
31 - true for GMP's random generator). As a consequence, the returned
32 - values can be different between MPFR 3.1 and previous MPFR
33 - versions. Note: as the reproducibility of these functions was not
34 - specified before MPFR 3.1, the MPFR 3.1 behavior is _not_ regarded
35 - as backward incompatible with previous versions.
36 + true for GMP's random generator, which is not the case between GMP
37 + 4.1 and 4.2 if `gmp_randinit_default' is used). As a consequence,
38 + the returned values can be different between MPFR 3.1 and previous
39 + MPFR versions. Note: as the reproducibility of these functions
40 + was not specified before MPFR 3.1, the MPFR 3.1 behavior is _not_
41 + regarded as backward incompatible with previous versions.
44 
45 @@ -4239,13 +4240,13 @@
46 Node: Type and Macro Changes129308
47 Node: Added Functions132029
48 Node: Changed Functions134972
49 -Node: Removed Functions139167
50 -Node: Other Changes139579
51 -Node: Contributors141108
52 -Node: References143574
53 -Node: GNU Free Documentation License145315
54 -Node: Concept Index167758
55 -Node: Function and Type Index173677
56 +Node: Removed Functions139253
57 +Node: Other Changes139665
58 +Node: Contributors141194
59 +Node: References143660
60 +Node: GNU Free Documentation License145401
61 +Node: Concept Index167844
62 +Node: Function and Type Index173763
63 
64 End Tag Table
66 diff -Naur mpfr-3.1.0.orig/doc/mpfr.texi mpfr-3.1.0/doc/mpfr.texi
67 --- mpfr-3.1.0.orig/doc/mpfr.texi 2011-10-03 08:17:14.000000000 +0000
68 +++ mpfr-3.1.0/doc/mpfr.texi 2011-11-28 12:22:52.000000000 +0000
69 @@ -3466,8 +3466,9 @@
70 a lack of specification.
72 @item @code{mpfr_urandom} and @code{mpfr_urandomb} changed in MPFR 3.1.
73 -Their behavior no longer depends on the platform (assuming this is also
74 -true for GMP's random generator). As a consequence, the returned values
75 +Their behavior no longer depends on the platform (assuming this is also true
76 +for GMP's random generator, which is not the case between GMP 4.1 and 4.2 if
77 +@code{gmp_randinit_default} is used). As a consequence, the returned values
78 can be different between MPFR 3.1 and previous MPFR versions.
79 Note: as the reproducibility of these functions was not specified
80 before MPFR 3.1, the MPFR 3.1 behavior is @emph{not} regarded as
81 diff -Naur mpfr-3.1.0.orig/src/mpfr-impl.h mpfr-3.1.0/src/mpfr-impl.h
82 --- mpfr-3.1.0.orig/src/mpfr-impl.h 2011-10-03 08:17:09.000000000 +0000
83 +++ mpfr-3.1.0/src/mpfr-impl.h 2011-10-05 21:39:57.000000000 +0000
84 @@ -988,10 +988,11 @@
85 ******************************************************/
87 /* Theses macros help the compiler to determine if a test is
88 - * likely or unlikely. */
89 + likely or unlikely. The !! is necessary in case x is larger
90 + than a long. */
91 #if __MPFR_GNUC(3,0) || __MPFR_ICC(8,1,0)
92 # define MPFR_LIKELY(x) (__builtin_expect(!!(x),1))
93 -# define MPFR_UNLIKELY(x) (__builtin_expect((x),0))
94 +# define MPFR_UNLIKELY(x) (__builtin_expect(!!(x),0))
95 #else
96 # define MPFR_LIKELY(x) (x)
97 # define MPFR_UNLIKELY(x) (x)
98 diff -Naur mpfr-3.1.0.orig/src/mpfr.h mpfr-3.1.0/src/mpfr.h
99 --- mpfr-3.1.0.orig/src/mpfr.h 2011-10-03 08:17:09.000000000 +0000
100 +++ mpfr-3.1.0/src/mpfr.h 2011-11-28 12:22:52.000000000 +0000
101 @@ -27,7 +27,7 @@
102 #define MPFR_VERSION_MAJOR 3
103 #define MPFR_VERSION_MINOR 1
104 #define MPFR_VERSION_PATCHLEVEL 0
105 -#define MPFR_VERSION_STRING "3.1.0"
106 +#define MPFR_VERSION_STRING "3.1.0-p4"
108 /* Macros dealing with MPFR VERSION */
109 #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
110 diff -Naur mpfr-3.1.0.orig/src/vasprintf.c mpfr-3.1.0/src/vasprintf.c
111 --- mpfr-3.1.0.orig/src/vasprintf.c 2011-10-03 08:17:09.000000000 +0000
112 +++ mpfr-3.1.0/src/vasprintf.c 2011-11-03 15:15:11.000000000 +0000
113 @@ -1178,7 +1178,7 @@
114 mpfr_exp_t exp;
115 char * str;
116 const int spec_g = (spec.spec == 'g' || spec.spec == 'G');
117 - const int keep_trailing_zeros = spec_g && spec.alt;
118 + const int keep_trailing_zeros = !spec_g || spec.alt;
120 /* WARNING: an empty precision field is forbidden (it means precision = 6
121 and it should have been changed to 6 before the function call) */
122 @@ -1356,7 +1356,7 @@
123 else
124 /* 1 <= |p| */
125 {
126 - size_t nsd; /* Number of significant digits */
127 + size_t str_len;
129 /* Determine the position of the most significant decimal digit. */
130 exp = floor_log10 (p);
131 @@ -1365,12 +1365,10 @@
132 /* P is too large to print all its integral part digits */
133 return -1;
135 - np->ip_size = exp + 1;
136 -
137 - nsd = spec.prec + np->ip_size;
138 if (dec_info == NULL)
139 - {
140 - str = mpfr_get_str (NULL, &exp, 10, nsd, p, spec.rnd_mode);
141 + { /* this case occurs with mpfr_printf ("%.0RUf", x) with x=9.5 */
142 + str =
143 + mpfr_get_str (NULL, &exp, 10, spec.prec+exp+1, p, spec.rnd_mode);
144 register_string (np->sl, str);
145 }
146 else
147 @@ -1379,81 +1377,60 @@
148 str = dec_info->str;
149 }
150 np->ip_ptr = MPFR_IS_NEG (p) ? ++str : str; /* skip sign */
151 + str_len = strlen (str);
152 +
153 + /* integral part */
154 + if (exp > str_len)
155 + /* mpfr_get_str gives no trailing zero when p is rounded up to the next
156 + power of 10 (p integer, so no fractional part) */
157 + {
158 + np->ip_trailing_zeros = exp - str_len;
159 + np->ip_size = str_len;
160 + }
161 + else
162 + np->ip_size = exp;
164 if (spec.group)
165 /* thousands separator in integral part */
166 np->thousands_sep = MPFR_THOUSANDS_SEPARATOR;
168 - if (nsd == 0 || (spec_g && !spec.alt))
169 - /* compute how much non-zero digits in integral and fractional
170 - parts */
171 + /* fractional part */
172 + str += np->ip_size;
173 + str_len -= np->ip_size;
174 + if (!keep_trailing_zeros)
175 + /* remove trailing zeros, if any */
176 {
177 - size_t str_len;
178 - str_len = strlen (str); /* note: the sign has been skipped */
179 -
180 - if (exp > str_len)
181 - /* mpfr_get_str doesn't give the trailing zeros when p is a
182 - multiple of 10 (p integer, so no fractional part) */
183 + char *ptr = str + str_len - 1; /* pointer to the last digit of
184 + str */
185 + while ((*ptr == '0') && (str_len != 0))
186 {
187 - np->ip_trailing_zeros = exp - str_len;
188 - np->ip_size = str_len;
189 - if (spec.alt)
190 - np->point = MPFR_DECIMAL_POINT;
191 - }
192 - else
193 - /* str may contain some digits which are in fractional part */
194 - {
195 - char *ptr;
196 -
197 - ptr = str + str_len - 1; /* points to the end of str */
198 - str_len -= np->ip_size; /* number of digits in fractional
199 - part */
200 -
201 - if (!keep_trailing_zeros)
202 - /* remove trailing zeros, if any */
203 - {
204 - while ((*ptr == '0') && (str_len != 0))
205 - {
206 - --ptr;
207 - --str_len;
208 - }
209 - }
210 -
211 - if (str_len > INT_MAX)
212 - /* too many digits in fractional part */
213 - return -1;
214 -
215 - if (str_len != 0)
216 - /* some digits in fractional part */
217 - {
218 - np->point = MPFR_DECIMAL_POINT;
219 - np->fp_ptr = str + np->ip_size;
220 - np->fp_size = str_len;
221 - }
222 + --ptr;
223 + --str_len;
224 }
225 }
226 - else
227 - /* spec.prec digits in fractional part */
228 - {
229 - if (np->ip_size == exp - 1)
230 - /* the absolute value of the number has been rounded up to a power
231 - of ten.
232 - Insert an additional zero in integral part and put the rest of
233 - them in fractional part. */
234 - np->ip_trailing_zeros = 1;
236 - if (spec.prec != 0)
237 - {
238 - MPFR_ASSERTD (np->ip_size + np->ip_trailing_zeros == exp);
239 - MPFR_ASSERTD (np->ip_size + spec.prec == nsd);
240 + if (str_len > 0)
241 + /* some nonzero digits in fractional part */
242 + {
243 + if (str_len > INT_MAX)
244 + /* too many digits in fractional part */
245 + return -1;
246 +
247 + np->point = MPFR_DECIMAL_POINT;
248 + np->fp_ptr = str;
249 + np->fp_size = str_len;
250 + }
252 - np->point = MPFR_DECIMAL_POINT;
253 - np->fp_ptr = str + np->ip_size;
254 - np->fp_size = spec.prec;
255 - }
256 - else if (spec.alt)
257 - np->point = MPFR_DECIMAL_POINT;
258 + if (keep_trailing_zeros && str_len < spec.prec)
259 + /* add missing trailing zeros */
260 + {
261 + np->point = MPFR_DECIMAL_POINT;
262 + np->fp_trailing_zeros = spec.prec - np->fp_size;
263 }
264 +
265 + if (spec.alt)
266 + /* add decimal point even if no digits follow it */
267 + np->point = MPFR_DECIMAL_POINT;
268 }
270 return 0;
271 diff -Naur mpfr-3.1.0.orig/src/version.c mpfr-3.1.0/src/version.c
272 --- mpfr-3.1.0.orig/src/version.c 2011-10-03 08:17:09.000000000 +0000
273 +++ mpfr-3.1.0/src/version.c 2011-11-28 12:22:52.000000000 +0000
274 @@ -25,5 +25,5 @@
275 const char *
276 mpfr_get_version (void)
277 {
278 - return "3.1.0";
279 + return "3.1.0-p4";
280 }
281 diff -Naur mpfr-3.1.0.orig/tests/Makefile.am mpfr-3.1.0/tests/Makefile.am
282 --- mpfr-3.1.0.orig/tests/Makefile.am 2011-10-03 08:17:14.000000000 +0000
283 +++ mpfr-3.1.0/tests/Makefile.am 2011-10-03 08:17:14.000000000 +0000
284 @@ -65,8 +65,24 @@
285 TESTS = $(check_PROGRAMS)
286 TESTS_ENVIRONMENT = MPFR_QUIET=1 $(VALGRIND)
288 -# Option to prevent libtool from generating wrapper scripts for the tests.
289 +# The -no-install option prevents libtool from generating wrapper scripts
290 +# for the tests.
291 # This is useful to easily run the test scripts under valgrind or gdb.
292 # See discussion http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/28033
293 # http://article.gmane.org/gmane.comp.lib.gnulib.bugs/28140 in particular.
294 -AM_LDFLAGS = -no-install
295 +#
296 +# The -L$(top_builddir)/src/.libs option is necessary for some platforms,
297 +# such as HP-UX, when --with-gmp or --with-gmp-lib is used and an old MPFR
298 +# library is already installed in the corresponding lib directory: its
299 +# purpose is to make sure that the local .libs comes first in the library
300 +# search path (otherwise the tests are linked against the old MPFR library
301 +# by the LINK command -- see the generated Makefile). See:
302 +# http://websympa.loria.fr/wwsympa/arc/mpfr/2011-10/msg00042.html
303 +# http://websympa.loria.fr/wwsympa/arc/mpfr/2011-10/msg00043.html
304 +# http://websympa.loria.fr/wwsympa/arc/mpfr/2011-10/msg00044.html
305 +# http://websympa.loria.fr/wwsympa/arc/mpfr/2011-10/msg00066.html
306 +# http://websympa.loria.fr/wwsympa/arc/mpfr/2011-10/msg00065.html
307 +# and
308 +# http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9728
309 +#
310 +AM_LDFLAGS = -no-install -L$(top_builddir)/src/.libs
311 diff -Naur mpfr-3.1.0.orig/tests/Makefile.in mpfr-3.1.0/tests/Makefile.in
312 --- mpfr-3.1.0.orig/tests/Makefile.in 2011-10-03 08:17:35.000000000 +0000
313 +++ mpfr-3.1.0/tests/Makefile.in 2011-10-03 08:17:35.000000000 +0000
314 @@ -1124,11 +1124,27 @@
315 TESTS = $(check_PROGRAMS)
316 TESTS_ENVIRONMENT = MPFR_QUIET=1 $(VALGRIND)
318 -# Option to prevent libtool from generating wrapper scripts for the tests.
319 +# The -no-install option prevents libtool from generating wrapper scripts
320 +# for the tests.
321 # This is useful to easily run the test scripts under valgrind or gdb.
322 # See discussion http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/28033
323 # http://article.gmane.org/gmane.comp.lib.gnulib.bugs/28140 in particular.
324 -AM_LDFLAGS = -no-install
325 +#
326 +# The -L$(top_builddir)/src/.libs option is necessary for some platforms,
327 +# such as HP-UX, when --with-gmp or --with-gmp-lib is used and an old MPFR
328 +# library is already installed in the corresponding lib directory: its
329 +# purpose is to make sure that the local .libs comes first in the library
330 +# search path (otherwise the tests are linked against the old MPFR library
331 +# by the LINK command -- see the generated Makefile). See:
332 +# http://websympa.loria.fr/wwsympa/arc/mpfr/2011-10/msg00042.html
333 +# http://websympa.loria.fr/wwsympa/arc/mpfr/2011-10/msg00043.html
334 +# http://websympa.loria.fr/wwsympa/arc/mpfr/2011-10/msg00044.html
335 +# http://websympa.loria.fr/wwsympa/arc/mpfr/2011-10/msg00066.html
336 +# http://websympa.loria.fr/wwsympa/arc/mpfr/2011-10/msg00065.html
337 +# and
338 +# http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9728
339 +#
340 +AM_LDFLAGS = -no-install -L$(top_builddir)/src/.libs
341 all: all-am
343 .SUFFIXES:
344 diff -Naur mpfr-3.1.0.orig/tests/trandom.c mpfr-3.1.0/tests/trandom.c
345 --- mpfr-3.1.0.orig/tests/trandom.c 2011-10-03 08:17:14.000000000 +0000
346 +++ mpfr-3.1.0/tests/trandom.c 2011-11-28 12:22:52.000000000 +0000
347 @@ -114,21 +114,29 @@
348 mpfr_t x;
349 gmp_randstate_t s;
351 +#if __MPFR_GMP(4,2,0)
352 +# define C1 "0.895943"
353 +# define C2 "0.848824"
354 +#else
355 +# define C1 "0.479652"
356 +# define C2 "0.648529"
357 +#endif
358 +
359 gmp_randinit_default (s);
360 gmp_randseed_ui (s, 42);
361 mpfr_init2 (x, 17);
362 mpfr_urandomb (x, s);
363 - if (mpfr_cmp_str1 (x, "0.895943") != 0)
364 + if (mpfr_cmp_str1 (x, C1) != 0)
365 {
366 - printf ("Error in bug20100914, expected 0.895943, got ");
367 + printf ("Error in bug20100914, expected " C1 ", got ");
368 mpfr_out_str (stdout, 10, 0, x, MPFR_RNDN);
369 printf ("\n");
370 exit (1);
371 }
372 mpfr_urandomb (x, s);
373 - if (mpfr_cmp_str1 (x, "0.848824") != 0)
374 + if (mpfr_cmp_str1 (x, C2) != 0)
375 {
376 - printf ("Error in bug20100914, expected 0.848824, got ");
377 + printf ("Error in bug20100914, expected " C2 ", got ");
378 mpfr_out_str (stdout, 10, 0, x, MPFR_RNDN);
379 printf ("\n");
380 exit (1);
381 diff -Naur mpfr-3.1.0.orig/tests/tsprintf.c mpfr-3.1.0/tests/tsprintf.c
382 --- mpfr-3.1.0.orig/tests/tsprintf.c 2011-10-03 08:17:14.000000000 +0000
383 +++ mpfr-3.1.0/tests/tsprintf.c 2011-11-03 15:15:11.000000000 +0000
384 @@ -475,6 +475,18 @@
385 check_sprintf ("-1.", "%- #0.1RG", x);
387 /* precision zero */
388 + mpfr_set_d (x, 9.5, MPFR_RNDN);
389 + check_sprintf ("9", "%.0RDf", x);
390 + check_sprintf ("10", "%.0RUf", x);
391 +
392 + mpfr_set_d (x, 19.5, MPFR_RNDN);
393 + check_sprintf ("19", "%.0RDf", x);
394 + check_sprintf ("20", "%.0RUf", x);
395 +
396 + mpfr_set_d (x, 99.5, MPFR_RNDN);
397 + check_sprintf ("99", "%.0RDf", x);
398 + check_sprintf ("100", "%.0RUf", x);
399 +
400 mpfr_set_d (x, -9.5, MPFR_RNDN);
401 check_sprintf ("-10", "%.0RDf", x);
402 check_sprintf ("-10", "%.0RYf", x);
403 @@ -1078,6 +1090,23 @@
404 mpfr_clear (x);
405 }
407 +static void
408 +bug20111102 (void)
409 +{
410 + mpfr_t t;
411 + char s[100];
412 +
413 + mpfr_init2 (t, 84);
414 + mpfr_set_str (t, "999.99999999999999999999", 10, MPFR_RNDN);
415 + mpfr_sprintf (s, "%.20RNg", t);
416 + if (strcmp (s, "1000") != 0)
417 + {
418 + printf ("Error in bug20111102, expected 1000, got %s\n", s);
419 + exit (1);
420 + }
421 + mpfr_clear (t);
422 +}
423 +
424 /* In particular, the following test makes sure that the rounding
425 * for %Ra and %Rb is not done on the MPFR number itself (as it
426 * would overflow). Note: it has been reported on comp.std.c that
427 @@ -1161,6 +1190,7 @@
428 locale = setlocale (LC_ALL, "C");
429 #endif
431 + bug20111102 ();
432 native_types ();
433 hexadecimal ();
434 binary ();
435 diff -Naur mpfr-3.1.0.orig/tests/turandom.c mpfr-3.1.0/tests/turandom.c
436 --- mpfr-3.1.0.orig/tests/turandom.c 2011-10-03 08:17:14.000000000 +0000
437 +++ mpfr-3.1.0/tests/turandom.c 2011-11-28 12:22:52.000000000 +0000
438 @@ -160,23 +160,29 @@
439 mpfr_t x;
440 gmp_randstate_t s;
442 +#if __MPFR_GMP(4,2,0)
443 +# define C1 "0.8488312"
444 +# define C2 "0.8156509"
445 +#else
446 +# define C1 "0.6485367"
447 +# define C2 "0.9362717"
448 +#endif
449 +
450 gmp_randinit_default (s);
451 gmp_randseed_ui (s, 42);
452 mpfr_init2 (x, 17);
453 mpfr_urandom (x, s, MPFR_RNDN);
454 - /* the following values are obtained on a 32-bit computer, we should get
455 - the same values on a 64-bit computer */
456 - if (mpfr_cmp_str1 (x, "0.8488312") != 0)
457 + if (mpfr_cmp_str1 (x, C1) != 0)
458 {
459 - printf ("Error in bug20100914, expected 0.8488312, got ");
460 + printf ("Error in bug20100914, expected " C1 ", got ");
461 mpfr_out_str (stdout, 10, 0, x, MPFR_RNDN);
462 printf ("\n");
463 exit (1);
464 }
465 mpfr_urandom (x, s, MPFR_RNDN);
466 - if (mpfr_cmp_str1 (x, "0.8156509") != 0)
467 + if (mpfr_cmp_str1 (x, C2) != 0)
468 {
469 - printf ("Error in bug20100914, expected 0.8156509, got ");
470 + printf ("Error in bug20100914, expected " C2 ", got ");
471 mpfr_out_str (stdout, 10, 0, x, MPFR_RNDN);
472 printf ("\n");
473 exit (1);