don't scan beyond end of CBFS
[coreboot.git] / util / crossgcc / patches / mpfr-3.0.0_allpatches_20101216.patch
1 diff -Naurd mpfr-3.0.0.orig/PATCHES mpfr-3.0.0/PATCHES
2 --- mpfr-3.0.0.orig/PATCHES     2010-06-23 11:02:49.000000000 +0000
3 +++ mpfr-3.0.0/PATCHES  2010-06-23 11:03:36.000000000 +0000
4 @@ -0,0 +1 @@
5 +mpfr_out_str
6 diff -Naurd mpfr-3.0.0.orig/VERSION mpfr-3.0.0/VERSION
7 --- mpfr-3.0.0.orig/VERSION     2010-06-10 11:00:14.000000000 +0000
8 +++ mpfr-3.0.0/VERSION  2010-06-23 11:03:20.000000000 +0000
9 @@ -1 +1 @@
10 -3.0.0
11 +3.0.0-p1
12 diff -Naurd mpfr-3.0.0.orig/mpfr.h mpfr-3.0.0/mpfr.h
13 --- mpfr-3.0.0.orig/mpfr.h      2010-06-10 11:00:14.000000000 +0000
14 +++ mpfr-3.0.0/mpfr.h   2010-06-23 11:03:20.000000000 +0000
15 @@ -27,7 +27,7 @@
16  #define MPFR_VERSION_MAJOR 3
17  #define MPFR_VERSION_MINOR 0
18  #define MPFR_VERSION_PATCHLEVEL 0
19 -#define MPFR_VERSION_STRING "3.0.0"
20 +#define MPFR_VERSION_STRING "3.0.0-p1"
21  
22  /* Macros dealing with MPFR VERSION */
23  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
24 diff -Naurd mpfr-3.0.0.orig/mpfr.texi mpfr-3.0.0/mpfr.texi
25 --- mpfr-3.0.0.orig/mpfr.texi   2010-06-10 11:00:14.000000000 +0000
26 +++ mpfr-3.0.0/mpfr.texi        2010-06-23 11:03:12.000000000 +0000
27 @@ -2050,7 +2050,7 @@
28  are printed. If @var{base} is greater than 10, @samp{@@} will be used
29  instead of @samp{e} as exponent delimiter.
30  
31 -Return the number of bytes written, or if an error occurred, return 0.
32 +Return the number of characters written, or if an error occurred, return 0.
33  @end deftypefun
34  
35  @deftypefun size_t mpfr_inp_str (mpfr_t @var{rop}, FILE *@var{stream}, int @var{base}, mpfr_rnd_t @var{rnd})
36 diff -Naurd mpfr-3.0.0.orig/out_str.c mpfr-3.0.0/out_str.c
37 --- mpfr-3.0.0.orig/out_str.c   2010-06-10 11:00:14.000000000 +0000
38 +++ mpfr-3.0.0/out_str.c        2010-06-23 11:03:12.000000000 +0000
39 @@ -22,6 +22,16 @@
40  
41  #include "mpfr-impl.h"
42  
43 +/* Warning! S should not contain "%". */
44 +#define OUT_STR_RET(S)                          \
45 +  do                                            \
46 +    {                                           \
47 +      int r;                                    \
48 +      r = fprintf (stream, (S));                \
49 +      return r < 0 ? 0 : r;                     \
50 +    }                                           \
51 +  while (0)
52 +
53  size_t
54  mpfr_out_str (FILE *stream, int base, size_t n_digits, mpfr_srcptr op,
55                mpfr_rnd_t rnd_mode)
56 @@ -29,6 +39,7 @@
57    char *s, *s0;
58    size_t l;
59    mpfr_exp_t e;
60 +  int err;
61  
62    MPFR_ASSERTN (base >= 2 && base <= 62);
63  
64 @@ -36,37 +47,16 @@
65    if (stream == NULL)
66      stream = stdout;
67  
68 -  if (MPFR_IS_NAN(op))
69 -    {
70 -      fprintf (stream, "@NaN@");
71 -      return 3;
72 -    }
73 -
74 -  if (MPFR_IS_INF(op))
75 -    {
76 -      if (MPFR_SIGN(op) > 0)
77 -        {
78 -          fprintf (stream, "@Inf@");
79 -          return 3;
80 -        }
81 -      else
82 -        {
83 -          fprintf (stream, "-@Inf@");
84 -          return 4;
85 -        }
86 -    }
87 -
88 -  if (MPFR_IS_ZERO(op))
89 +  if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (op)))
90      {
91 -      if (MPFR_SIGN(op) > 0)
92 -        {
93 -          fprintf(stream, "0");
94 -          return 1;
95 -        }
96 +      if (MPFR_IS_NAN (op))
97 +        OUT_STR_RET ("@NaN@");
98 +      else if (MPFR_IS_INF (op))
99 +        OUT_STR_RET (MPFR_IS_POS (op) ? "@Inf@" : "-@Inf@");
100        else
101          {
102 -          fprintf(stream, "-0");
103 -          return 2;
104 +          MPFR_ASSERTD (MPFR_IS_ZERO (op));
105 +          OUT_STR_RET (MPFR_IS_POS (op) ? "0" : "-0");
106          }
107      }
108  
109 @@ -77,21 +67,31 @@
110  
111    l = strlen (s) + 1; /* size of allocated block returned by mpfr_get_str
112                           - may be incorrect, as only an upper bound? */
113 -  if (*s == '-')
114 -    fputc (*s++, stream);
115  
116 -  /* outputs mantissa */
117 -  fputc (*s++, stream); e--; /* leading digit */
118 -  fputc ((unsigned char) MPFR_DECIMAL_POINT, stream);
119 -  fputs (s, stream);         /* rest of mantissa */
120 +  /* outputs possible sign and significand */
121 +  err = (*s == '-' && fputc (*s++, stream) == EOF)
122 +    || fputc (*s++, stream) == EOF  /* leading digit */
123 +    || fputc ((unsigned char) MPFR_DECIMAL_POINT, stream) == EOF
124 +    || fputs (s, stream) == EOF;     /* trailing significand */
125    (*__gmp_free_func) (s0, l);
126 +  if (MPFR_UNLIKELY (err))
127 +    return 0;
128 +
129 +  e--;  /* due to the leading digit */
130  
131    /* outputs exponent */
132    if (e)
133      {
134 +      int r;
135 +
136        MPFR_ASSERTN(e >= LONG_MIN);
137        MPFR_ASSERTN(e <= LONG_MAX);
138 -      l += fprintf (stream, (base <= 10 ? "e%ld" : "@%ld"), (long) e);
139 +
140 +      r = fprintf (stream, (base <= 10 ? "e%ld" : "@%ld"), (long) e);
141 +      if (MPFR_UNLIKELY (r < 0))
142 +        return 0;
143 +
144 +      l += r;
145      }
146  
147    return l;
148 diff -Naurd mpfr-3.0.0.orig/tests/tout_str.c mpfr-3.0.0/tests/tout_str.c
149 --- mpfr-3.0.0.orig/tests/tout_str.c    2010-06-10 11:00:13.000000000 +0000
150 +++ mpfr-3.0.0/tests/tout_str.c 2010-06-23 11:03:12.000000000 +0000
151 @@ -46,22 +46,54 @@
152  special (void)
153  {
154    mpfr_t x;
155 +  unsigned int n;
156  
157    mpfr_init (x);
158  
159    mpfr_set_nan (x);
160 -  mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
161 +  n = mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
162 +  if (n != 5)
163 +    {
164 +      printf ("Error: mpfr_out_str (file, 10, 0, NaN, MPFR_RNDN) wrote %u "
165 +              "characters instead of 5.\n", n);
166 +      exit (1);
167 +    }
168  
169    mpfr_set_inf (x, 1);
170 -  mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
171 +  n = mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
172 +  if (n != 5)
173 +    {
174 +      printf ("Error: mpfr_out_str (file, 10, 0, +Inf, MPFR_RNDN) wrote %u "
175 +               "characters instead of 5.\n", n);
176 +      exit (1);
177 +    }
178  
179    mpfr_set_inf (x, -1);
180 -  mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
181 +  n = mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
182 +  if (n != 6)
183 +    {
184 +      printf ("Error: mpfr_out_str (file, 10, 0, -Inf, MPFR_RNDN) wrote %u "
185 +               "characters instead of 6.\n", n);
186 +      exit (1);
187 +    }
188  
189    mpfr_set_ui (x, 0, MPFR_RNDN);
190 -  mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
191 +  n = mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
192 +  if (n != 1)
193 +    {
194 +      printf ("Error: mpfr_out_str (file, 10, 0, +0, MPFR_RNDN) wrote %u "
195 +               "characters instead of 1.\n", n);
196 +      exit (1);
197 +    }
198 +
199    mpfr_neg (x, x, MPFR_RNDN);
200 -  mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
201 +  n = mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
202 +  if (n != 2)
203 +    {
204 +      printf ("Error: mpfr_out_str (file, 10, 0, -0, MPFR_RNDN) wrote %u "
205 +               "characters instead of 2.\n", n);
206 +      exit (1);
207 +    }
208  
209    mpfr_clear (x);
210  }
211 diff -Naurd mpfr-3.0.0.orig/version.c mpfr-3.0.0/version.c
212 --- mpfr-3.0.0.orig/version.c   2010-06-10 11:00:14.000000000 +0000
213 +++ mpfr-3.0.0/version.c        2010-06-23 11:03:20.000000000 +0000
214 @@ -25,5 +25,5 @@
215  const char *
216  mpfr_get_version (void)
217  {
218 -  return "3.0.0";
219 +  return "3.0.0-p1";
220  }
221 diff -Naurd mpfr-3.0.0.orig/Makefile.in mpfr-3.0.0/Makefile.in
222 --- mpfr-3.0.0.orig/Makefile.in 2010-06-10 11:00:52.000000000 +0000
223 +++ mpfr-3.0.0/Makefile.in      2010-06-10 11:00:52.000000000 +0000
224 @@ -239,6 +239,7 @@
225  distuninstallcheck_listfiles = find . -type f -print
226  distcleancheck_listfiles = find . -type f -print
227  ACLOCAL = @ACLOCAL@
228 +ALLOCA = @ALLOCA@
229  AMTAR = @AMTAR@
230  AR = @AR@
231  AS = @AS@
232 diff -Naurd mpfr-3.0.0.orig/PATCHES mpfr-3.0.0/PATCHES
233 --- mpfr-3.0.0.orig/PATCHES     2010-06-23 11:03:36.000000000 +0000
234 +++ mpfr-3.0.0/PATCHES  2010-06-25 13:23:13.000000000 +0000
235 @@ -0,0 +1 @@
236 +alloca
237 diff -Naurd mpfr-3.0.0.orig/VERSION mpfr-3.0.0/VERSION
238 --- mpfr-3.0.0.orig/VERSION     2010-06-23 11:03:20.000000000 +0000
239 +++ mpfr-3.0.0/VERSION  2010-06-25 13:23:13.000000000 +0000
240 @@ -1 +1 @@
241 -3.0.0-p1
242 +3.0.0-p2
243 diff -Naurd mpfr-3.0.0.orig/acinclude.m4 mpfr-3.0.0/acinclude.m4
244 --- mpfr-3.0.0.orig/acinclude.m4        2010-06-10 11:00:14.000000000 +0000
245 +++ mpfr-3.0.0/acinclude.m4     2010-06-10 11:00:14.000000000 +0000
246 @@ -59,6 +59,9 @@
247  dnl sys/fpu.h - MIPS specific
248  AC_CHECK_HEADERS([sys/time.h sys/fpu.h])
249  
250 +dnl Check how to get `alloca'
251 +AC_FUNC_ALLOCA
252 +
253  dnl SIZE_MAX macro
254  gl_SIZE_MAX
255  
256 diff -Naurd mpfr-3.0.0.orig/configure mpfr-3.0.0/configure
257 --- mpfr-3.0.0.orig/configure   2010-06-10 11:00:51.000000000 +0000
258 +++ mpfr-3.0.0/configure        2010-06-25 13:23:05.000000000 +0000
259 @@ -783,6 +783,7 @@
260  OBJDUMP
261  DLLTOOL
262  AS
263 +ALLOCA
264  MPFR_LIBM
265  ANSI2KNR
266  U
267 @@ -5622,6 +5623,197 @@
268  done
269  
270  
271 +# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
272 +# for constant arguments.  Useless!
273 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for working alloca.h" >&5
274 +$as_echo_n "checking for working alloca.h... " >&6; }
275 +if test "${ac_cv_working_alloca_h+set}" = set; then :
276 +  $as_echo_n "(cached) " >&6
277 +else
278 +  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
279 +/* end confdefs.h.  */
280 +#include <alloca.h>
281 +int
282 +main ()
283 +{
284 +char *p = (char *) alloca (2 * sizeof (int));
285 +                         if (p) return 0;
286 +  ;
287 +  return 0;
288 +}
289 +_ACEOF
290 +if ac_fn_c_try_link "$LINENO"; then :
291 +  ac_cv_working_alloca_h=yes
292 +else
293 +  ac_cv_working_alloca_h=no
294 +fi
295 +rm -f core conftest.err conftest.$ac_objext \
296 +    conftest$ac_exeext conftest.$ac_ext
297 +fi
298 +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_working_alloca_h" >&5
299 +$as_echo "$ac_cv_working_alloca_h" >&6; }
300 +if test $ac_cv_working_alloca_h = yes; then
301 +
302 +$as_echo "#define HAVE_ALLOCA_H 1" >>confdefs.h
303 +
304 +fi
305 +
306 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for alloca" >&5
307 +$as_echo_n "checking for alloca... " >&6; }
308 +if test "${ac_cv_func_alloca_works+set}" = set; then :
309 +  $as_echo_n "(cached) " >&6
310 +else
311 +  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
312 +/* end confdefs.h.  */
313 +#ifdef __GNUC__
314 +# define alloca __builtin_alloca
315 +#else
316 +# ifdef _MSC_VER
317 +#  include <malloc.h>
318 +#  define alloca _alloca
319 +# else
320 +#  ifdef HAVE_ALLOCA_H
321 +#   include <alloca.h>
322 +#  else
323 +#   ifdef _AIX
324 + #pragma alloca
325 +#   else
326 +#    ifndef alloca /* predefined by HP cc +Olibcalls */
327 +char *alloca ();
328 +#    endif
329 +#   endif
330 +#  endif
331 +# endif
332 +#endif
333 +
334 +int
335 +main ()
336 +{
337 +char *p = (char *) alloca (1);
338 +                                   if (p) return 0;
339 +  ;
340 +  return 0;
341 +}
342 +_ACEOF
343 +if ac_fn_c_try_link "$LINENO"; then :
344 +  ac_cv_func_alloca_works=yes
345 +else
346 +  ac_cv_func_alloca_works=no
347 +fi
348 +rm -f core conftest.err conftest.$ac_objext \
349 +    conftest$ac_exeext conftest.$ac_ext
350 +fi
351 +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_alloca_works" >&5
352 +$as_echo "$ac_cv_func_alloca_works" >&6; }
353 +
354 +if test $ac_cv_func_alloca_works = yes; then
355 +
356 +$as_echo "#define HAVE_ALLOCA 1" >>confdefs.h
357 +
358 +else
359 +  # The SVR3 libPW and SVR4 libucb both contain incompatible functions
360 +# that cause trouble.  Some versions do not even contain alloca or
361 +# contain a buggy version.  If you still want to use their alloca,
362 +# use ar to extract alloca.o from them instead of compiling alloca.c.
363 +
364 +ALLOCA=\${LIBOBJDIR}alloca.$ac_objext
365 +
366 +$as_echo "#define C_ALLOCA 1" >>confdefs.h
367 +
368 +
369 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether \`alloca.c' needs Cray hooks" >&5
370 +$as_echo_n "checking whether \`alloca.c' needs Cray hooks... " >&6; }
371 +if test "${ac_cv_os_cray+set}" = set; then :
372 +  $as_echo_n "(cached) " >&6
373 +else
374 +  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
375 +/* end confdefs.h.  */
376 +#if defined CRAY && ! defined CRAY2
377 +webecray
378 +#else
379 +wenotbecray
380 +#endif
381 +
382 +_ACEOF
383 +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
384 +  $EGREP "webecray" >/dev/null 2>&1; then :
385 +  ac_cv_os_cray=yes
386 +else
387 +  ac_cv_os_cray=no
388 +fi
389 +rm -f conftest*
390 +
391 +fi
392 +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_os_cray" >&5
393 +$as_echo "$ac_cv_os_cray" >&6; }
394 +if test $ac_cv_os_cray = yes; then
395 +  for ac_func in _getb67 GETB67 getb67; do
396 +    as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
397 +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
398 +eval as_val=\$$as_ac_var
399 +   if test "x$as_val" = x""yes; then :
400 +
401 +cat >>confdefs.h <<_ACEOF
402 +#define CRAY_STACKSEG_END $ac_func
403 +_ACEOF
404 +
405 +    break
406 +fi
407 +
408 +  done
409 +fi
410 +
411 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking stack direction for C alloca" >&5
412 +$as_echo_n "checking stack direction for C alloca... " >&6; }
413 +if test "${ac_cv_c_stack_direction+set}" = set; then :
414 +  $as_echo_n "(cached) " >&6
415 +else
416 +  if test "$cross_compiling" = yes; then :
417 +  ac_cv_c_stack_direction=0
418 +else
419 +  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
420 +/* end confdefs.h.  */
421 +$ac_includes_default
422 +int
423 +find_stack_direction ()
424 +{
425 +  static char *addr = 0;
426 +  auto char dummy;
427 +  if (addr == 0)
428 +    {
429 +      addr = &dummy;
430 +      return find_stack_direction ();
431 +    }
432 +  else
433 +    return (&dummy > addr) ? 1 : -1;
434 +}
435 +
436 +int
437 +main ()
438 +{
439 +  return find_stack_direction () < 0;
440 +}
441 +_ACEOF
442 +if ac_fn_c_try_run "$LINENO"; then :
443 +  ac_cv_c_stack_direction=1
444 +else
445 +  ac_cv_c_stack_direction=-1
446 +fi
447 +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
448 +  conftest.$ac_objext conftest.beam conftest.$ac_ext
449 +fi
450 +
451 +fi
452 +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_stack_direction" >&5
453 +$as_echo "$ac_cv_c_stack_direction" >&6; }
454 +cat >>confdefs.h <<_ACEOF
455 +#define STACK_DIRECTION $ac_cv_c_stack_direction
456 +_ACEOF
457 +
458 +
459 +fi
460 +
461 +
462  
463    for ac_header in stdint.h
464  do :
465 @@ -7564,13 +7756,13 @@
466  else
467    lt_cv_nm_interface="BSD nm"
468    echo "int some_variable = 0;" > conftest.$ac_ext
469 -  (eval echo "\"\$as_me:7567: $ac_compile\"" >&5)
470 +  (eval echo "\"\$as_me:7759: $ac_compile\"" >&5)
471    (eval "$ac_compile" 2>conftest.err)
472    cat conftest.err >&5
473 -  (eval echo "\"\$as_me:7570: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
474 +  (eval echo "\"\$as_me:7762: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
475    (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
476    cat conftest.err >&5
477 -  (eval echo "\"\$as_me:7573: output\"" >&5)
478 +  (eval echo "\"\$as_me:7765: output\"" >&5)
479    cat conftest.out >&5
480    if $GREP 'External.*some_variable' conftest.out > /dev/null; then
481      lt_cv_nm_interface="MS dumpbin"
482 @@ -8772,7 +8964,7 @@
483    ;;
484  *-*-irix6*)
485    # Find out which ABI we are using.
486 -  echo '#line 8775 "configure"' > conftest.$ac_ext
487 +  echo '#line 8967 "configure"' > conftest.$ac_ext
488    if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
489    (eval $ac_compile) 2>&5
490    ac_status=$?
491 @@ -10032,11 +10224,11 @@
492     -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
493     -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
494     -e 's:$: $lt_compiler_flag:'`
495 -   (eval echo "\"\$as_me:10035: $lt_compile\"" >&5)
496 +   (eval echo "\"\$as_me:10227: $lt_compile\"" >&5)
497     (eval "$lt_compile" 2>conftest.err)
498     ac_status=$?
499     cat conftest.err >&5
500 -   echo "$as_me:10039: \$? = $ac_status" >&5
501 +   echo "$as_me:10231: \$? = $ac_status" >&5
502     if (exit $ac_status) && test -s "$ac_outfile"; then
503       # The compiler can only warn and ignore the option if not recognized
504       # So say no if there are warnings other than the usual output.
505 @@ -10371,11 +10563,11 @@
506     -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
507     -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
508     -e 's:$: $lt_compiler_flag:'`
509 -   (eval echo "\"\$as_me:10374: $lt_compile\"" >&5)
510 +   (eval echo "\"\$as_me:10566: $lt_compile\"" >&5)
511     (eval "$lt_compile" 2>conftest.err)
512     ac_status=$?
513     cat conftest.err >&5
514 -   echo "$as_me:10378: \$? = $ac_status" >&5
515 +   echo "$as_me:10570: \$? = $ac_status" >&5
516     if (exit $ac_status) && test -s "$ac_outfile"; then
517       # The compiler can only warn and ignore the option if not recognized
518       # So say no if there are warnings other than the usual output.
519 @@ -10476,11 +10668,11 @@
520     -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
521     -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
522     -e 's:$: $lt_compiler_flag:'`
523 -   (eval echo "\"\$as_me:10479: $lt_compile\"" >&5)
524 +   (eval echo "\"\$as_me:10671: $lt_compile\"" >&5)
525     (eval "$lt_compile" 2>out/conftest.err)
526     ac_status=$?
527     cat out/conftest.err >&5
528 -   echo "$as_me:10483: \$? = $ac_status" >&5
529 +   echo "$as_me:10675: \$? = $ac_status" >&5
530     if (exit $ac_status) && test -s out/conftest2.$ac_objext
531     then
532       # The compiler can only warn and ignore the option if not recognized
533 @@ -10531,11 +10723,11 @@
534     -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
535     -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
536     -e 's:$: $lt_compiler_flag:'`
537 -   (eval echo "\"\$as_me:10534: $lt_compile\"" >&5)
538 +   (eval echo "\"\$as_me:10726: $lt_compile\"" >&5)
539     (eval "$lt_compile" 2>out/conftest.err)
540     ac_status=$?
541     cat out/conftest.err >&5
542 -   echo "$as_me:10538: \$? = $ac_status" >&5
543 +   echo "$as_me:10730: \$? = $ac_status" >&5
544     if (exit $ac_status) && test -s out/conftest2.$ac_objext
545     then
546       # The compiler can only warn and ignore the option if not recognized
547 @@ -12915,7 +13107,7 @@
548    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
549    lt_status=$lt_dlunknown
550    cat > conftest.$ac_ext <<_LT_EOF
551 -#line 12918 "configure"
552 +#line 13110 "configure"
553  #include "confdefs.h"
554  
555  #if HAVE_DLFCN_H
556 @@ -13011,7 +13203,7 @@
557    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
558    lt_status=$lt_dlunknown
559    cat > conftest.$ac_ext <<_LT_EOF
560 -#line 13014 "configure"
561 +#line 13206 "configure"
562  #include "confdefs.h"
563  
564  #if HAVE_DLFCN_H
565 diff -Naurd mpfr-3.0.0.orig/mpfr.h mpfr-3.0.0/mpfr.h
566 --- mpfr-3.0.0.orig/mpfr.h      2010-06-23 11:03:20.000000000 +0000
567 +++ mpfr-3.0.0/mpfr.h   2010-06-25 13:23:13.000000000 +0000
568 @@ -27,7 +27,7 @@
569  #define MPFR_VERSION_MAJOR 3
570  #define MPFR_VERSION_MINOR 0
571  #define MPFR_VERSION_PATCHLEVEL 0
572 -#define MPFR_VERSION_STRING "3.0.0-p1"
573 +#define MPFR_VERSION_STRING "3.0.0-p2"
574  
575  /* Macros dealing with MPFR VERSION */
576  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
577 diff -Naurd mpfr-3.0.0.orig/tests/Makefile.in mpfr-3.0.0/tests/Makefile.in
578 --- mpfr-3.0.0.orig/tests/Makefile.in   2010-06-10 11:00:52.000000000 +0000
579 +++ mpfr-3.0.0/tests/Makefile.in        2010-06-10 11:00:52.000000000 +0000
580 @@ -960,6 +960,7 @@
581  red=; grn=; lgn=; blu=; std=
582  DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
583  ACLOCAL = @ACLOCAL@
584 +ALLOCA = @ALLOCA@
585  AMTAR = @AMTAR@
586  AR = @AR@
587  AS = @AS@
588 diff -Naurd mpfr-3.0.0.orig/version.c mpfr-3.0.0/version.c
589 --- mpfr-3.0.0.orig/version.c   2010-06-23 11:03:20.000000000 +0000
590 +++ mpfr-3.0.0/version.c        2010-06-25 13:23:13.000000000 +0000
591 @@ -25,5 +25,5 @@
592  const char *
593  mpfr_get_version (void)
594  {
595 -  return "3.0.0-p1";
596 +  return "3.0.0-p2";
597  }
598 diff -Naurd mpfr-3.0.0.orig/PATCHES mpfr-3.0.0/PATCHES
599 --- mpfr-3.0.0.orig/PATCHES     2010-07-10 00:11:19.000000000 +0000
600 +++ mpfr-3.0.0/PATCHES  2010-07-10 00:12:50.000000000 +0000
601 @@ -0,0 +1 @@
602 +gamma_underflow
603 diff -Naurd mpfr-3.0.0.orig/VERSION mpfr-3.0.0/VERSION
604 --- mpfr-3.0.0.orig/VERSION     2010-06-25 13:23:13.000000000 +0000
605 +++ mpfr-3.0.0/VERSION  2010-07-10 00:11:53.000000000 +0000
606 @@ -1 +1 @@
607 -3.0.0-p2
608 +3.0.0-p3
609 diff -Naurd mpfr-3.0.0.orig/gamma.c mpfr-3.0.0/gamma.c
610 --- mpfr-3.0.0.orig/gamma.c     2010-06-10 11:00:14.000000000 +0000
611 +++ mpfr-3.0.0/gamma.c  2010-07-10 00:11:46.000000000 +0000
612 @@ -274,7 +274,7 @@
613        /* we want an upper bound for x * [log(2-x)-1].
614           since x < 0, we need a lower bound on log(2-x) */
615        mpfr_ui_sub (xp, 2, x, MPFR_RNDD);
616 -      mpfr_log (xp, xp, MPFR_RNDD);
617 +      mpfr_log2 (xp, xp, MPFR_RNDD);
618        mpfr_sub_ui (xp, xp, 1, MPFR_RNDD);
619        mpfr_mul (xp, xp, x, MPFR_RNDU);
620  
621 @@ -303,8 +303,8 @@
622          {
623            mpfr_sub (tmp, tmp, tmp2, MPFR_RNDZ); /* low bnd on |sin(Pi*(2-x))| */
624            mpfr_ui_div (tmp, 12, tmp, MPFR_RNDU); /* upper bound */
625 -          mpfr_log (tmp, tmp, MPFR_RNDU);
626 -          mpfr_add (tmp, tmp, xp, MPFR_RNDU);
627 +          mpfr_log2 (tmp, tmp, MPFR_RNDU);
628 +          mpfr_add (xp, tmp, xp, MPFR_RNDU);
629            underflow = mpfr_cmp_si (xp, expo.saved_emin - 2) <= 0;
630          }
631  
632 diff -Naurd mpfr-3.0.0.orig/mpfr.h mpfr-3.0.0/mpfr.h
633 --- mpfr-3.0.0.orig/mpfr.h      2010-06-25 13:23:13.000000000 +0000
634 +++ mpfr-3.0.0/mpfr.h   2010-07-10 00:11:53.000000000 +0000
635 @@ -27,7 +27,7 @@
636  #define MPFR_VERSION_MAJOR 3
637  #define MPFR_VERSION_MINOR 0
638  #define MPFR_VERSION_PATCHLEVEL 0
639 -#define MPFR_VERSION_STRING "3.0.0-p2"
640 +#define MPFR_VERSION_STRING "3.0.0-p3"
641  
642  /* Macros dealing with MPFR VERSION */
643  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
644 diff -Naurd mpfr-3.0.0.orig/tests/tgamma.c mpfr-3.0.0/tests/tgamma.c
645 --- mpfr-3.0.0.orig/tests/tgamma.c      2010-06-10 11:00:13.000000000 +0000
646 +++ mpfr-3.0.0/tests/tgamma.c   2010-07-10 00:11:46.000000000 +0000
647 @@ -461,6 +461,20 @@
648    mpfr_clear (x);
649  }
650  
651 +/* bug found by Stathis, only occurs on 32-bit machines */
652 +static void
653 +test20100709 (void)
654 +{
655 +  mpfr_t x;
656 +  int inex;
657 +
658 +  mpfr_init2 (x, 100);
659 +  mpfr_set_str (x, "-4.6308260837372266e+07", 10, MPFR_RNDN);
660 +  inex = mpfr_gamma (x, x, MPFR_RNDN);
661 +  MPFR_ASSERTN(MPFR_IS_ZERO(x) && MPFR_IS_NEG(x) && inex > 0);
662 +  mpfr_clear (x);
663 +}
664 +
665  int
666  main (int argc, char *argv[])
667  {
668 @@ -471,6 +485,7 @@
669    test_generic (2, 100, 2);
670    gamma_integer ();
671    test20071231 ();
672 +  test20100709 ();
673  
674    data_check ("data/gamma", mpfr_gamma, "mpfr_gamma");
675  
676 diff -Naurd mpfr-3.0.0.orig/version.c mpfr-3.0.0/version.c
677 --- mpfr-3.0.0.orig/version.c   2010-06-25 13:23:13.000000000 +0000
678 +++ mpfr-3.0.0/version.c        2010-07-10 00:11:53.000000000 +0000
679 @@ -25,5 +25,5 @@
680  const char *
681  mpfr_get_version (void)
682  {
683 -  return "3.0.0-p2";
684 +  return "3.0.0-p3";
685  }
686 diff -Naurd mpfr-3.0.0.orig/PATCHES mpfr-3.0.0/PATCHES
687 --- mpfr-3.0.0.orig/PATCHES     2010-09-07 08:44:01.000000000 +0000
688 +++ mpfr-3.0.0/PATCHES  2010-09-07 08:48:46.000000000 +0000
689 @@ -0,0 +1 @@
690 +mpfr_cmp/set_ui/si
691 diff -Naurd mpfr-3.0.0.orig/VERSION mpfr-3.0.0/VERSION
692 --- mpfr-3.0.0.orig/VERSION     2010-07-10 00:11:53.000000000 +0000
693 +++ mpfr-3.0.0/VERSION  2010-09-07 08:46:06.000000000 +0000
694 @@ -1 +1 @@
695 -3.0.0-p3
696 +3.0.0-p4
697 diff -Naurd mpfr-3.0.0.orig/mpfr.h mpfr-3.0.0/mpfr.h
698 --- mpfr-3.0.0.orig/mpfr.h      2010-07-10 00:11:53.000000000 +0000
699 +++ mpfr-3.0.0/mpfr.h   2010-09-07 08:46:06.000000000 +0000
700 @@ -27,7 +27,7 @@
701  #define MPFR_VERSION_MAJOR 3
702  #define MPFR_VERSION_MINOR 0
703  #define MPFR_VERSION_PATCHLEVEL 0
704 -#define MPFR_VERSION_STRING "3.0.0-p3"
705 +#define MPFR_VERSION_STRING "3.0.0-p4"
706  
707  /* Macros dealing with MPFR VERSION */
708  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
709 @@ -798,35 +798,45 @@
710       anyway. Checking with other ICC versions is needed. Possibly detect
711       whether warnings are produced or not with a configure test.
712     + Remove C++ too, since it complains too much. */
713 +/* Added casts to improve robustness in case of undefined behavior and
714 +   compiler extensions based on UB (in particular -fwrapv). MPFR doesn't
715 +   use such extensions, but these macros will be used by 3rd-party code,
716 +   where such extensions may be required.
717 +   Moreover casts to unsigned long have been added to avoid warnings in
718 +   programs that use MPFR and are compiled with -Wconversion; such casts
719 +   are OK since if X is a constant expression, then (unsigned long) X is
720 +   also a constant expression, so that the optimizations still work. */
721  #if defined (__GNUC__) && !defined(__ICC) && !defined(__cplusplus)
722  #if (__GNUC__ >= 2)
723  #undef mpfr_cmp_ui
724 -/* We use the fact that mpfr_sgn on NaN sets the erange flag and returns 0. */
725 -#define mpfr_cmp_ui(_f,_u)                 \
726 - (__builtin_constant_p (_u) && (_u) == 0 ? \
727 -   mpfr_sgn (_f) :                         \
728 -   mpfr_cmp_ui_2exp ((_f),(_u),0))
729 +/* We use the fact that mpfr_sgn on NaN sets the erange flag and returns 0.
730 +   But warning! mpfr_sgn is specified as a macro in the API, thus the macro
731 +   mustn't be used if side effects are possible, like here. */
732 +#define mpfr_cmp_ui(_f,_u)                                      \
733 +  (__builtin_constant_p (_u) && (unsigned long) (_u) == 0 ?     \
734 +   (mpfr_sgn) (_f) :                                            \
735 +   mpfr_cmp_ui_2exp ((_f), (unsigned long) (_u), 0))
736  #undef mpfr_cmp_si
737 -#define mpfr_cmp_si(_f,_s)                 \
738 - (__builtin_constant_p (_s) && (_s) >= 0 ? \
739 -   mpfr_cmp_ui ((_f), (_s)) :              \
740 -   mpfr_cmp_si_2exp ((_f), (_s), 0))
741 +#define mpfr_cmp_si(_f,_s)                              \
742 +  (__builtin_constant_p (_s) && (long) (_s) >= 0 ?      \
743 +   mpfr_cmp_ui ((_f), (unsigned long) (long) (_s)) :    \
744 +   mpfr_cmp_si_2exp ((_f), (long) (_s), 0))
745  #if __GNUC__ > 2 || __GNUC_MINOR__ >= 95
746  #undef mpfr_set_ui
747 -#define mpfr_set_ui(_f,_u,_r)              \
748 - (__builtin_constant_p (_u) && (_u) == 0 ? \
749 -   __extension__ ({                        \
750 -     mpfr_ptr _p = (_f);                   \
751 -     _p->_mpfr_sign = 1;                   \
752 -     _p->_mpfr_exp = __MPFR_EXP_ZERO;      \
753 -     (void) (_r); 0; }) :                  \
754 -   mpfr_set_ui_2exp ((_f), (_u), 0, (_r)))
755 +#define mpfr_set_ui(_f,_u,_r)                                   \
756 +  (__builtin_constant_p (_u) && (unsigned long) (_u) == 0 ?     \
757 +   __extension__ ({                                             \
758 +       mpfr_ptr _p = (_f);                                      \
759 +       _p->_mpfr_sign = 1;                                      \
760 +       _p->_mpfr_exp = __MPFR_EXP_ZERO;                         \
761 +       (void) (_r); 0; }) :                                     \
762 +   mpfr_set_ui_2exp ((_f), (unsigned long) (_u), 0, (_r)))
763  #endif
764  #undef mpfr_set_si
765 -#define mpfr_set_si(_f,_s,_r)              \
766 - (__builtin_constant_p (_s) && (_s) >= 0 ? \
767 -   mpfr_set_ui ((_f), (_s), (_r)) :        \
768 -   mpfr_set_si_2exp ((_f), (_s), 0, (_r)))
769 +#define mpfr_set_si(_f,_s,_r)                                   \
770 +  (__builtin_constant_p (_s) && (long) (_s) >= 0 ?              \
771 +   mpfr_set_ui ((_f), (unsigned long) (long) (_s), (_r)) :      \
772 +   mpfr_set_si_2exp ((_f), (long) (_s), 0, (_r)))
773  #endif
774  #endif
775  
776 diff -Naurd mpfr-3.0.0.orig/tests/tcmp_ui.c mpfr-3.0.0/tests/tcmp_ui.c
777 --- mpfr-3.0.0.orig/tests/tcmp_ui.c     2010-06-10 11:00:13.000000000 +0000
778 +++ mpfr-3.0.0/tests/tcmp_ui.c  2010-09-07 08:45:12.000000000 +0000
779 @@ -88,6 +88,126 @@
780    mpfr_clear (x);
781  }
782  
783 +/* Since mpfr_cmp_ui and mpfr_cmp_si are also implemented by a macro
784 +   with __builtin_constant_p for GCC, check that side effects are
785 +   handled correctly. */
786 +static void
787 +check_macros (void)
788 +{
789 +  mpfr_t x;
790 +  int c;
791 +
792 +  mpfr_init2 (x, 32);
793 +
794 +  c = 0;
795 +  mpfr_set_ui (x, 17, MPFR_RNDN);
796 +  if (mpfr_cmp_ui (x, 17) != 0)
797 +    {
798 +      printf ("Error 1 on mpfr_cmp_ui(x,17) in check_macros\n");
799 +      exit (1);
800 +    }
801 +  if (mpfr_cmp_ui (x, (c++, 17)) != 0)
802 +    {
803 +      printf ("Error 2 on mpfr_cmp_ui(x,17) in check_macros\n");
804 +      exit (1);
805 +    }
806 +  if (c != 1)
807 +    {
808 +      printf ("Error 3 on mpfr_cmp_ui(x,17) in check_macros\n"
809 +              "(c = %d instead of 1)\n", c);
810 +      exit (1);
811 +    }
812 +  if (mpfr_cmp_si (x, 17) != 0)
813 +    {
814 +      printf ("Error 1 on mpfr_cmp_si(x,17) in check_macros\n");
815 +      exit (1);
816 +    }
817 +  if (mpfr_cmp_si (x, (c++, 17)) != 0)
818 +    {
819 +      printf ("Error 2 on mpfr_cmp_si(x,17) in check_macros\n");
820 +      exit (1);
821 +    }
822 +  if (c != 2)
823 +    {
824 +      printf ("Error 3 on mpfr_cmp_si(x,17) in check_macros\n"
825 +              "(c = %d instead of 2)\n", c);
826 +      exit (1);
827 +    }
828 +
829 +  c = 0;
830 +  mpfr_set_ui (x, 0, MPFR_RNDN);
831 +  if (mpfr_cmp_ui (x, 0) != 0)
832 +    {
833 +      printf ("Error 1 on mpfr_cmp_ui(x,0) in check_macros\n");
834 +      exit (1);
835 +    }
836 +  if (mpfr_cmp_ui (x, (c++, 0)) != 0)
837 +    {
838 +      printf ("Error 2 on mpfr_cmp_ui(x,0) in check_macros\n");
839 +      exit (1);
840 +    }
841 +  if (c != 1)
842 +    {
843 +      printf ("Error 3 on mpfr_cmp_ui(x,0) in check_macros\n"
844 +              "(c = %d instead of 1)\n", c);
845 +      exit (1);
846 +    }
847 +  if (mpfr_cmp_si (x, 0) != 0)
848 +    {
849 +      printf ("Error 1 on mpfr_cmp_si(x,0) in check_macros\n");
850 +      exit (1);
851 +    }
852 +  if (mpfr_cmp_si (x, (c++, 0)) != 0)
853 +    {
854 +      printf ("Error 2 on mpfr_cmp_si(x,0) in check_macros\n");
855 +      exit (1);
856 +    }
857 +  if (c != 2)
858 +    {
859 +      printf ("Error 3 on mpfr_cmp_si(x,0) in check_macros\n"
860 +              "(c = %d instead of 2)\n", c);
861 +      exit (1);
862 +    }
863 +
864 +  mpfr_clear (x);
865 +}
866 +
867 +/* Bug in r7114 */
868 +static void
869 +test_macros (void)
870 +{
871 +  mpfr_t x[3];
872 +  mpfr_ptr p;
873 +
874 +  mpfr_inits (x[0], x[1], x[2], (mpfr_ptr) 0);
875 +  mpfr_set_ui (x[0], 0, MPFR_RNDN);
876 +  p = x[0];
877 +  if (mpfr_cmp_ui (p++, 0) != 0)
878 +    {
879 +      printf ("Error in mpfr_cmp_ui macro: result should be 0.\n");
880 +      exit (1);
881 +    }
882 +  if (p != x[1])
883 +    {
884 +      printf ("Error in mpfr_cmp_ui macro: p - x[0] = %d (expecting 1)\n",
885 +              (int) (p - x[0]));
886 +      exit (1);
887 +    }
888 +  p = x[0];
889 +  if (mpfr_cmp_si (p++, 0) != 0)
890 +    {
891 +      printf ("Error in mpfr_cmp_si macro: result should be 0.\n");
892 +      exit (1);
893 +    }
894 +  if (p != x[1])
895 +    {
896 +      printf ("Error in mpfr_cmp_si macro: p - x[0] = %d (expecting 1)\n",
897 +              (int) (p - x[0]));
898 +      exit (1);
899 +    }
900 +  mpfr_clears (x[0], x[1], x[2], (mpfr_ptr) 0);
901 +}
902 +
903  int
904  main (void)
905  {
906 @@ -216,6 +336,8 @@
907    mpfr_clear (x);
908  
909    check_nan ();
910 +  check_macros ();
911 +  test_macros ();
912  
913    tests_end_mpfr ();
914    return 0;
915 diff -Naurd mpfr-3.0.0.orig/version.c mpfr-3.0.0/version.c
916 --- mpfr-3.0.0.orig/version.c   2010-07-10 00:11:53.000000000 +0000
917 +++ mpfr-3.0.0/version.c        2010-09-07 08:46:06.000000000 +0000
918 @@ -25,5 +25,5 @@
919  const char *
920  mpfr_get_version (void)
921  {
922 -  return "3.0.0-p3";
923 +  return "3.0.0-p4";
924  }
925 diff -Naurd mpfr-3.0.0.orig/PATCHES mpfr-3.0.0/PATCHES
926 --- mpfr-3.0.0.orig/PATCHES     2010-10-21 20:28:38.000000000 +0000
927 +++ mpfr-3.0.0/PATCHES  2010-10-21 20:28:38.000000000 +0000
928 @@ -0,0 +1 @@
929 +tcan_round
930 diff -Naurd mpfr-3.0.0.orig/VERSION mpfr-3.0.0/VERSION
931 --- mpfr-3.0.0.orig/VERSION     2010-09-07 08:46:06.000000000 +0000
932 +++ mpfr-3.0.0/VERSION  2010-10-21 20:28:38.000000000 +0000
933 @@ -1 +1 @@
934 -3.0.0-p4
935 +3.0.0-p5
936 diff -Naurd mpfr-3.0.0.orig/mpfr.h mpfr-3.0.0/mpfr.h
937 --- mpfr-3.0.0.orig/mpfr.h      2010-09-07 08:46:06.000000000 +0000
938 +++ mpfr-3.0.0/mpfr.h   2010-10-21 20:28:38.000000000 +0000
939 @@ -27,7 +27,7 @@
940  #define MPFR_VERSION_MAJOR 3
941  #define MPFR_VERSION_MINOR 0
942  #define MPFR_VERSION_PATCHLEVEL 0
943 -#define MPFR_VERSION_STRING "3.0.0-p4"
944 +#define MPFR_VERSION_STRING "3.0.0-p5"
945  
946  /* Macros dealing with MPFR VERSION */
947  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
948 diff -Naurd mpfr-3.0.0.orig/tests/tcan_round.c mpfr-3.0.0/tests/tcan_round.c
949 --- mpfr-3.0.0.orig/tests/tcan_round.c  2010-06-10 11:00:13.000000000 +0000
950 +++ mpfr-3.0.0/tests/tcan_round.c       2010-10-21 20:28:38.000000000 +0000
951 @@ -41,7 +41,7 @@
952        /* avoid mpn_random which leaks memory */
953        for (i = 0; i < n; i++)
954          buf[i] = randlimb ();
955 -      p = (mpfr_prec_t) randlimb() % ((n-1) * GMP_NUMB_BITS) + MPFR_PREC_MIN;
956 +      p = randlimb() % ((n-1) * GMP_NUMB_BITS) + MPFR_PREC_MIN;
957        err = p + randlimb () % GMP_NUMB_BITS;
958        r1 = mpfr_round_p (buf, n, err, p);
959        r2 = mpfr_can_round_raw (buf, n, MPFR_SIGN_POS, err,
960 diff -Naurd mpfr-3.0.0.orig/version.c mpfr-3.0.0/version.c
961 --- mpfr-3.0.0.orig/version.c   2010-09-07 08:46:06.000000000 +0000
962 +++ mpfr-3.0.0/version.c        2010-10-21 20:28:38.000000000 +0000
963 @@ -25,5 +25,5 @@
964  const char *
965  mpfr_get_version (void)
966  {
967 -  return "3.0.0-p4";
968 +  return "3.0.0-p5";
969  }
970 diff -Naurd mpfr-3.0.0.orig/PATCHES mpfr-3.0.0/PATCHES
971 --- mpfr-3.0.0.orig/PATCHES     2010-10-21 20:59:32.000000000 +0000
972 +++ mpfr-3.0.0/PATCHES  2010-10-21 20:59:32.000000000 +0000
973 @@ -0,0 +1 @@
974 +mpfr_sub1
975 diff -Naurd mpfr-3.0.0.orig/VERSION mpfr-3.0.0/VERSION
976 --- mpfr-3.0.0.orig/VERSION     2010-10-21 20:28:38.000000000 +0000
977 +++ mpfr-3.0.0/VERSION  2010-10-21 20:59:32.000000000 +0000
978 @@ -1 +1 @@
979 -3.0.0-p5
980 +3.0.0-p6
981 diff -Naurd mpfr-3.0.0.orig/mpfr.h mpfr-3.0.0/mpfr.h
982 --- mpfr-3.0.0.orig/mpfr.h      2010-10-21 20:28:38.000000000 +0000
983 +++ mpfr-3.0.0/mpfr.h   2010-10-21 20:59:32.000000000 +0000
984 @@ -27,7 +27,7 @@
985  #define MPFR_VERSION_MAJOR 3
986  #define MPFR_VERSION_MINOR 0
987  #define MPFR_VERSION_PATCHLEVEL 0
988 -#define MPFR_VERSION_STRING "3.0.0-p5"
989 +#define MPFR_VERSION_STRING "3.0.0-p6"
990  
991  /* Macros dealing with MPFR VERSION */
992  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
993 diff -Naurd mpfr-3.0.0.orig/sub1.c mpfr-3.0.0/sub1.c
994 --- mpfr-3.0.0.orig/sub1.c      2010-06-10 11:00:14.000000000 +0000
995 +++ mpfr-3.0.0/sub1.c   2010-10-21 20:59:32.000000000 +0000
996 @@ -37,7 +37,9 @@
997    mp_size_t cancel2, an, bn, cn, cn0;
998    mp_limb_t *ap, *bp, *cp;
999    mp_limb_t carry, bb, cc, borrow = 0;
1000 -  int inexact, shift_b, shift_c, is_exact = 1, down = 0, add_exp = 0;
1001 +  int inexact, shift_b, shift_c, add_exp = 0;
1002 +  int cmp_low = 0; /* used for rounding to nearest: 0 if low(b) = low(c),
1003 +                      negative if low(b) < low(c), positive if low(b)>low(c) */
1004    int sh, k;
1005    MPFR_TMP_DECL(marker);
1006  
1007 @@ -196,7 +198,8 @@
1008      }
1009  
1010  #ifdef DEBUG
1011 -  printf ("shift_b=%d shift_c=%d diffexp=%lu\n", shift_b, shift_c,
1012 +  printf ("rnd=%s shift_b=%d shift_c=%d diffexp=%lu\n",
1013 +          mpfr_print_rnd_mode (rnd_mode), shift_b, shift_c,
1014            (unsigned long) diff_exp);
1015  #endif
1016  
1017 @@ -307,17 +310,18 @@
1018      {
1019        if (MPFR_LIKELY(sh))
1020          {
1021 -          is_exact = (carry == 0);
1022            /* can decide except when carry = 2^(sh-1) [middle]
1023               or carry = 0 [truncate, but cannot decide inexact flag] */
1024 -          down = (carry < (MPFR_LIMB_ONE << (sh - 1)));
1025            if (carry > (MPFR_LIMB_ONE << (sh - 1)))
1026              goto add_one_ulp;
1027 -          else if ((0 < carry) && down)
1028 +          else if ((0 < carry) && (carry < (MPFR_LIMB_ONE << (sh - 1))))
1029              {
1030                inexact = -1; /* result if smaller than exact value */
1031                goto truncate;
1032              }
1033 +          /* now carry = 2^(sh-1), in which case cmp_low=2,
1034 +             or carry = 0, in which case cmp_low=0 */
1035 +          cmp_low = (carry == 0) ? 0 : 2;
1036          }
1037      }
1038    else /* directed rounding: set rnd_mode to RNDZ iff toward zero */
1039 @@ -344,12 +348,32 @@
1040    cn -= (long int) an + cancel2;
1041  
1042  #ifdef DEBUG
1043 -  printf ("last %d bits from a are %lu, bn=%ld, cn=%ld\n",
1044 +  printf ("last sh=%d bits from a are %lu, bn=%ld, cn=%ld\n",
1045            sh, (unsigned long) carry, (long) bn, (long) cn);
1046  #endif
1047  
1048 +  /* for rounding to nearest, we couldn't conclude up to here in the following
1049 +     cases:
1050 +     1. sh = 0, then cmp_low=0: we can either truncate, subtract one ulp
1051 +        or add one ulp: -1 ulp < low(b)-low(c) < 1 ulp
1052 +     2. sh > 0 but the low sh bits from high(b)-high(c) equal 2^(sh-1):
1053 +        -0.5 ulp <= -1/2^sh < low(b)-low(c)-0.5 < 1/2^sh <= 0.5 ulp
1054 +        we can't decide the rounding, in that case cmp_low=2:
1055 +        either we truncate and flag=-1, or we add one ulp and flag=1
1056 +     3. the low sh>0 bits from high(b)-high(c) equal 0: we know we have to
1057 +        truncate but we can't decide the ternary value, here cmp_low=0:
1058 +        -0.5 ulp <= -1/2^sh < low(b)-low(c) < 1/2^sh <= 0.5 ulp
1059 +        we always truncate and inexact can be any of -1,0,1
1060 +  */
1061 +
1062 +  /* note: here cn might exceed cn0, in which case we consider a zero limb */
1063    for (k = 0; (bn > 0) || (cn > 0); k = 1)
1064      {
1065 +      /* if cmp_low < 0, we know low(b) - low(c) < 0
1066 +         if cmp_low > 0, we know low(b) - low(c) > 0
1067 +            (more precisely if cmp_low = 2, low(b) - low(c) = 0.5 ulp so far)
1068 +         if cmp_low = 0, so far low(b) - low(c) = 0 */
1069 +
1070        /* get next limbs */
1071        bb = (bn > 0) ? bp[--bn] : 0;
1072        if ((cn > 0) && (cn-- <= cn0))
1073 @@ -357,76 +381,115 @@
1074        else
1075          cc = 0;
1076  
1077 -      /* down is set when low(b) < low(c) */
1078 -      if (down == 0)
1079 -        down = (bb < cc);
1080 +      /* cmp_low compares low(b) and low(c) */
1081 +      if (cmp_low == 0) /* case 1 or 3 */
1082 +        cmp_low = (bb < cc) ? -2+k : (bb > cc) ? 1 : 0;
1083 +
1084 +      /* Case 1 for k=0 splits into 7 subcases:
1085 +         1a: bb > cc + half
1086 +         1b: bb = cc + half
1087 +         1c: 0 < bb - cc < half
1088 +         1d: bb = cc
1089 +         1e: -half < bb - cc < 0
1090 +         1f: bb - cc = -half
1091 +         1g: bb - cc < -half
1092 +
1093 +         Case 2 splits into 3 subcases:
1094 +         2a: bb > cc
1095 +         2b: bb = cc
1096 +         2c: bb < cc
1097 +
1098 +         Case 3 splits into 3 subcases:
1099 +         3a: bb > cc
1100 +         3b: bb = cc
1101 +         3c: bb < cc
1102 +      */
1103  
1104        /* the case rounding to nearest with sh=0 is special since one couldn't
1105           subtract above 1/2 ulp in the trailing limb of the result */
1106 -      if ((rnd_mode == MPFR_RNDN) && sh == 0 && k == 0)
1107 +      if (rnd_mode == MPFR_RNDN && sh == 0 && k == 0) /* case 1 for k=0 */
1108          {
1109            mp_limb_t half = MPFR_LIMB_HIGHBIT;
1110  
1111 -          is_exact = (bb == cc);
1112 -
1113            /* add one ulp if bb > cc + half
1114               truncate if cc - half < bb < cc + half
1115               sub one ulp if bb < cc - half
1116            */
1117  
1118 -          if (down)
1119 +          if (cmp_low < 0) /* bb < cc: -1 ulp < low(b) - low(c) < 0,
1120 +                              cases 1e, 1f and 1g */
1121              {
1122                if (cc >= half)
1123                  cc -= half;
1124 -              else
1125 +              else /* since bb < cc < half, bb+half < 2*half */
1126                  bb += half;
1127 +              /* now we have bb < cc + half:
1128 +                 we have to subtract one ulp if bb < cc,
1129 +                 and truncate if bb > cc */
1130              }
1131 -          else /* bb >= cc */
1132 +          else if (cmp_low >= 0) /* bb >= cc, cases 1a to 1d */
1133              {
1134                if (cc < half)
1135                  cc += half;
1136 -              else
1137 +              else /* since bb >= cc >= half, bb - half >= 0 */
1138                  bb -= half;
1139 +              /* now we have bb > cc - half: we have to add one ulp if bb > cc,
1140 +                 and truncate if bb < cc */
1141 +              if (cmp_low > 0)
1142 +                cmp_low = 2;
1143              }
1144          }
1145  
1146  #ifdef DEBUG
1147 -      printf ("    bb=%lu cc=%lu down=%d is_exact=%d\n",
1148 -              (unsigned long) bb, (unsigned long) cc, down, is_exact);
1149 +      printf ("k=%u bb=%lu cc=%lu cmp_low=%d\n", k,
1150 +              (unsigned long) bb, (unsigned long) cc, cmp_low);
1151  #endif
1152 -      if (bb < cc)
1153 +      if (cmp_low < 0) /* low(b) - low(c) < 0: either truncate or subtract
1154 +                          one ulp */
1155          {
1156            if (rnd_mode == MPFR_RNDZ)
1157 -            goto sub_one_ulp;
1158 +            goto sub_one_ulp; /* set inexact=-1 */
1159            else if (rnd_mode != MPFR_RNDN) /* round away */
1160              {
1161                inexact = 1;
1162                goto truncate;
1163              }
1164 -          else /* round to nearest: special case here since for sh=k=0
1165 -                  bb = bb0 - MPFR_LIMB_HIGHBIT */
1166 +          else /* round to nearest */
1167              {
1168 -              if (is_exact && sh == 0)
1169 -                {
1170 -                  /* For k=0 we can't decide exactness since it may depend
1171 -                     from low order bits.
1172 -                     For k=1, the first low limbs matched: low(b)-low(c)<0. */
1173 -                  if (k)
1174 -                    {
1175 -                      inexact = 1;
1176 -                      goto truncate;
1177 -                    }
1178 -                }
1179 -              else if (down && sh == 0)
1180 -                goto sub_one_ulp;
1181 -              else
1182 -                {
1183 -                  inexact = (is_exact) ? 1 : -1;
1184 +              /* If cmp_low < 0 and bb > cc, then -0.5 ulp < low(b)-low(c) < 0,
1185 +                 whatever the value of sh.
1186 +                 If sh>0, then cmp_low < 0 implies that the initial neglected
1187 +                 sh bits were 0 (otherwise cmp_low=2 initially), thus the
1188 +                 weight of the new bits is less than 0.5 ulp too.
1189 +                 If k > 0 (and sh=0) this means that either the first neglected
1190 +                 limbs bb and cc were equal (thus cmp_low was 0 for k=0),
1191 +                 or we had bb - cc = -0.5 ulp or 0.5 ulp.
1192 +                 The last case is not possible here since we would have
1193 +                 cmp_low > 0 which is sticky.
1194 +                 In the first case (where we have cmp_low = -1), we truncate,
1195 +                 whereas in the 2nd case we have cmp_low = -2 and we subtract
1196 +                 one ulp.
1197 +              */
1198 +              if (bb > cc || sh > 0 || cmp_low == -1)
1199 +                {  /* -0.5 ulp < low(b)-low(c) < 0,
1200 +                      bb > cc corresponds to cases 1e and 1f1
1201 +                      sh > 0 corresponds to cases 3c and 3b3
1202 +                      cmp_low = -1 corresponds to case 1d3 (also 3b3) */
1203 +                  inexact = 1;
1204                    goto truncate;
1205                  }
1206 +              else if (bb < cc) /* here sh = 0 and low(b)-low(c) < -0.5 ulp,
1207 +                                   this corresponds to cases 1g and 1f3 */
1208 +                goto sub_one_ulp;
1209 +              /* the only case where we can't conclude is sh=0 and bb=cc,
1210 +                 i.e., we have low(b) - low(c) = -0.5 ulp (up to now), thus
1211 +                 we don't know if we must truncate or subtract one ulp.
1212 +                 Note: for sh=0 we can't have low(b) - low(c) = -0.5 ulp up to
1213 +                 now, since low(b) - low(c) > 1/2^sh */
1214              }
1215          }
1216 -      else if (bb > cc)
1217 +      else if (cmp_low > 0) /* 0 < low(b) - low(c): either truncate or
1218 +                               add one ulp */
1219          {
1220            if (rnd_mode == MPFR_RNDZ)
1221              {
1222 @@ -437,34 +500,70 @@
1223              goto add_one_ulp;
1224            else /* round to nearest */
1225              {
1226 -              if (is_exact)
1227 +              if (bb > cc)
1228                  {
1229 -                  inexact = -1;
1230 -                  goto truncate;
1231 +                  /* if sh=0, then bb>cc means that low(b)-low(c) > 0.5 ulp,
1232 +                     and similarly when cmp_low=2 */
1233 +                  if (cmp_low == 2) /* cases 1a, 1b1, 2a and 2b1 */
1234 +                    goto add_one_ulp;
1235 +                  /* sh > 0 and cmp_low > 0: this implies that the sh initial
1236 +                     neglected bits were 0, and the remaining low(b)-low(c)>0,
1237 +                     but its weight is less than 0.5 ulp */
1238 +                  else /* 0 < low(b) - low(c) < 0.5 ulp, this corresponds to
1239 +                          cases 3a, 1d1 and 3b1 */
1240 +                    {
1241 +                      inexact = -1;
1242 +                      goto truncate;
1243 +                    }
1244                  }
1245 -              else if (down)
1246 +              else if (bb < cc) /* 0 < low(b) - low(c) < 0.5 ulp, cases 1c,
1247 +                                   1b3, 2b3 and 2c */
1248                  {
1249 -                  inexact = 1;
1250 +                  inexact = -1;
1251                    goto truncate;
1252                  }
1253 -              else
1254 -                goto add_one_ulp;
1255 +              /* the only case where we can't conclude is bb=cc, i.e.,
1256 +                 low(b) - low(c) = 0.5 ulp (up to now), thus we don't know
1257 +                 if we must truncate or add one ulp. */
1258              }
1259          }
1260 +      /* after k=0, we cannot conclude in the following cases, we split them
1261 +         according to the values of bb and cc for k=1:
1262 +         1b. sh=0 and cmp_low = 1 and bb-cc = half [around 0.5 ulp]
1263 +             1b1. bb > cc: add one ulp, inex = 1
1264 +             1b2: bb = cc: cannot conclude
1265 +             1b3: bb < cc: truncate, inex = -1
1266 +         1d. sh=0 and cmp_low = 0 and bb-cc = 0 [around 0]
1267 +             1d1: bb > cc: truncate, inex = -1
1268 +             1d2: bb = cc: cannot conclude
1269 +             1d3: bb < cc: truncate, inex = +1
1270 +         1f. sh=0 and cmp_low = -1 and bb-cc = -half [around -0.5 ulp]
1271 +             1f1: bb > cc: truncate, inex = +1
1272 +             1f2: bb = cc: cannot conclude
1273 +             1f3: bb < cc: sub one ulp, inex = -1
1274 +         2b. sh > 0 and cmp_low = 2 and bb=cc [around 0.5 ulp]
1275 +             2b1. bb > cc: add one ulp, inex = 1
1276 +             2b2: bb = cc: cannot conclude
1277 +             2b3: bb < cc: truncate, inex = -1
1278 +         3b. sh > 0 and cmp_low = 0 [around 0]
1279 +             3b1. bb > cc: truncate, inex = -1
1280 +             3b2: bb = cc: cannot conclude
1281 +             3b3: bb < cc: truncate, inex = +1
1282 +      */
1283      }
1284  
1285 -  if ((rnd_mode == MPFR_RNDN) && !is_exact)
1286 +  if ((rnd_mode == MPFR_RNDN) && cmp_low != 0)
1287      {
1288        /* even rounding rule */
1289        if ((ap[0] >> sh) & 1)
1290          {
1291 -          if (down)
1292 +          if (cmp_low < 0)
1293              goto sub_one_ulp;
1294            else
1295              goto add_one_ulp;
1296          }
1297        else
1298 -        inexact = (down) ? 1 : -1;
1299 +        inexact = (cmp_low > 0) ? -1 : 1;
1300      }
1301    else
1302      inexact = 0;
1303 diff -Naurd mpfr-3.0.0.orig/tests/tfma.c mpfr-3.0.0/tests/tfma.c
1304 --- mpfr-3.0.0.orig/tests/tfma.c        2010-06-10 11:00:13.000000000 +0000
1305 +++ mpfr-3.0.0/tests/tfma.c     2010-10-21 20:59:32.000000000 +0000
1306 @@ -337,6 +337,94 @@
1307    mpfr_clears (x, y, z, r, (mpfr_ptr) 0);
1308  }
1309  
1310 +static void
1311 +bug20101018 (void)
1312 +{
1313 +  mpfr_t x, y, z, t, u;
1314 +  int i;
1315 +
1316 +  mpfr_init2 (x, 64);
1317 +  mpfr_init2 (y, 64);
1318 +  mpfr_init2 (z, 64);
1319 +  mpfr_init2 (t, 64);
1320 +  mpfr_init2 (u, 64);
1321 +
1322 +  mpfr_set_str (x, "0xf.fffffffffffffffp-14766", 16, MPFR_RNDN);
1323 +  mpfr_set_str (y, "-0xf.fffffffffffffffp+317", 16, MPFR_RNDN);
1324 +  mpfr_set_str (z, "0x8.3ffffffffffe3ffp-14443", 16, MPFR_RNDN);
1325 +  mpfr_set_str (t, "0x8.7ffffffffffc7ffp-14444", 16, MPFR_RNDN);
1326 +  i = mpfr_fma (u, x, y, z, MPFR_RNDN);
1327 +  if (mpfr_cmp (u, t) != 0)
1328 +    {
1329 +      printf ("Wrong result in bug20101018 (a)\n");
1330 +      printf ("Expected ");
1331 +      mpfr_out_str (stdout, 16, 0, t, MPFR_RNDN);
1332 +      printf ("\nGot      ");
1333 +      mpfr_out_str (stdout, 16, 0, u, MPFR_RNDN);
1334 +      printf ("\n");
1335 +      exit (1);
1336 +    }
1337 +  if (i <= 0)
1338 +    {
1339 +      printf ("Wrong ternary value in bug20101018 (a)\n");
1340 +      printf ("Expected > 0\n");
1341 +      printf ("Got      %d\n", i);
1342 +      exit (1);
1343 +    }
1344 +
1345 +  mpfr_set_str (x, "-0xf.fffffffffffffffp-11420", 16, MPFR_RNDN);
1346 +  mpfr_set_str (y, "0xf.fffffffffffffffp+9863", 16, MPFR_RNDN);
1347 +  mpfr_set_str (z, "0x8.fffff80ffffffffp-1551", 16, MPFR_RNDN);
1348 +  mpfr_set_str (t, "0x9.fffff01ffffffffp-1552", 16, MPFR_RNDN);
1349 +  i = mpfr_fma (u, x, y, z, MPFR_RNDN);
1350 +  if (mpfr_cmp (u, t) != 0)
1351 +    {
1352 +      printf ("Wrong result in bug20101018 (b)\n");
1353 +      printf ("Expected ");
1354 +      mpfr_out_str (stdout, 16, 0, t, MPFR_RNDN);
1355 +      printf ("\nGot      ");
1356 +      mpfr_out_str (stdout, 16, 0, u, MPFR_RNDN);
1357 +      printf ("\n");
1358 +      exit (1);
1359 +    }
1360 +  if (i <= 0)
1361 +    {
1362 +      printf ("Wrong ternary value in bug20101018 (b)\n");
1363 +      printf ("Expected > 0\n");
1364 +      printf ("Got      %d\n", i);
1365 +      exit (1);
1366 +    }
1367 +
1368 +  mpfr_set_str (x, "0xf.fffffffffffffffp-2125", 16, MPFR_RNDN);
1369 +  mpfr_set_str (y, "-0xf.fffffffffffffffp-6000", 16, MPFR_RNDN);
1370 +  mpfr_set_str (z, "0x8p-8119", 16, MPFR_RNDN);
1371 +  mpfr_set_str (t, "0x8.000000000000001p-8120", 16, MPFR_RNDN);
1372 +  i = mpfr_fma (u, x, y, z, MPFR_RNDN);
1373 +  if (mpfr_cmp (u, t) != 0)
1374 +    {
1375 +      printf ("Wrong result in bug20101018 (c)\n");
1376 +      printf ("Expected ");
1377 +      mpfr_out_str (stdout, 16, 0, t, MPFR_RNDN);
1378 +      printf ("\nGot      ");
1379 +      mpfr_out_str (stdout, 16, 0, u, MPFR_RNDN);
1380 +      printf ("\n");
1381 +      exit (1);
1382 +    }
1383 +  if (i <= 0)
1384 +    {
1385 +      printf ("Wrong ternary value in bug20101018 (c)\n");
1386 +      printf ("Expected > 0\n");
1387 +      printf ("Got      %d\n", i);
1388 +      exit (1);
1389 +    }
1390 +
1391 +  mpfr_clear (x);
1392 +  mpfr_clear (y);
1393 +  mpfr_clear (z);
1394 +  mpfr_clear (t);
1395 +  mpfr_clear (u);
1396 +}
1397 +
1398  int
1399  main (int argc, char *argv[])
1400  {
1401 @@ -345,6 +433,8 @@
1402  
1403    tests_start_mpfr ();
1404  
1405 +  bug20101018 ();
1406 +
1407    mpfr_init (x);
1408    mpfr_init (s);
1409    mpfr_init (y);
1410 diff -Naurd mpfr-3.0.0.orig/tests/tsub.c mpfr-3.0.0/tests/tsub.c
1411 --- mpfr-3.0.0.orig/tests/tsub.c        2010-06-10 11:00:13.000000000 +0000
1412 +++ mpfr-3.0.0/tests/tsub.c     2010-10-21 20:59:32.000000000 +0000
1413 @@ -201,6 +201,8 @@
1414    if (mpfr_cmp (z, x))
1415      {
1416        printf ("Error in mpfr_sub (2)\n");
1417 +      printf ("Expected "); mpfr_print_binary (x); puts ("");
1418 +      printf ("Got      "); mpfr_print_binary (z); puts ("");
1419        exit (1);
1420      }
1421    mpfr_set_str_binary (x, "1.1110111011110001110111011111111111101000011001011100101100101101");
1422 @@ -478,6 +480,156 @@
1423    mpfr_clear (u);
1424  }
1425  
1426 +/* Bug found by Jakub Jelinek
1427 + * http://bugzilla.redhat.com/643657
1428 + * https://gforge.inria.fr/tracker/index.php?func=detail&aid=11301
1429 + * The consequence can be either an assertion failure (i = 2 in the
1430 + * testcase below, in debug mode) or an incorrectly rounded value.
1431 + */
1432 +static void
1433 +bug20101017 (void)
1434 +{
1435 +  mpfr_t a, b, c;
1436 +  int inex;
1437 +  int i;
1438 +
1439 +  mpfr_init2 (a, GMP_NUMB_BITS * 2);
1440 +  mpfr_init2 (b, GMP_NUMB_BITS);
1441 +  mpfr_init2 (c, GMP_NUMB_BITS);
1442 +
1443 +  /* a = 2^(2N) + k.2^(2N-1) + 2^N and b = 1
1444 +     with N = GMP_NUMB_BITS and k = 0 or 1.
1445 +     c = a - b should round to the same value as a. */
1446 +
1447 +  for (i = 2; i <= 3; i++)
1448 +    {
1449 +      mpfr_set_ui_2exp (a, i, GMP_NUMB_BITS - 1, MPFR_RNDN);
1450 +      mpfr_add_ui (a, a, 1, MPFR_RNDN);
1451 +      mpfr_mul_2ui (a, a, GMP_NUMB_BITS, MPFR_RNDN);
1452 +      mpfr_set_ui (b, 1, MPFR_RNDN);
1453 +      inex = mpfr_sub (c, a, b, MPFR_RNDN);
1454 +      mpfr_set (b, a, MPFR_RNDN);
1455 +      if (! mpfr_equal_p (c, b))
1456 +        {
1457 +          printf ("Error in bug20101017 for i = %d.\n", i);
1458 +          printf ("Expected ");
1459 +          mpfr_out_str (stdout, 16, 0, b, MPFR_RNDN);
1460 +          putchar ('\n');
1461 +          printf ("Got      ");
1462 +          mpfr_out_str (stdout, 16, 0, c, MPFR_RNDN);
1463 +          putchar ('\n');
1464 +          exit (1);
1465 +        }
1466 +      if (inex >= 0)
1467 +        {
1468 +          printf ("Error in bug20101017 for i = %d: bad inex value.\n", i);
1469 +          printf ("Expected negative, got %d.\n", inex);
1470 +          exit (1);
1471 +        }
1472 +    }
1473 +
1474 +  mpfr_set_prec (a, 64);
1475 +  mpfr_set_prec (b, 129);
1476 +  mpfr_set_prec (c, 2);
1477 +  mpfr_set_str_binary (b, "0.100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001E65");
1478 +  mpfr_set_str_binary (c, "0.10E1");
1479 +  inex = mpfr_sub (a, b, c, MPFR_RNDN);
1480 +  if (mpfr_cmp_ui_2exp (a, 1, 64) != 0 || inex >= 0)
1481 +    {
1482 +      printf ("Error in mpfr_sub for b-c for b=2^64+1+2^(-64), c=1\n");
1483 +      printf ("Expected result 2^64 with inex < 0\n");
1484 +      printf ("Got "); mpfr_print_binary (a);
1485 +      printf (" with inex=%d\n", inex);
1486 +      exit (1);
1487 +    }
1488 +
1489 +  mpfr_clears (a, b, c, (mpfr_ptr) 0);
1490 +}
1491 +
1492 +/* hard test of rounding */
1493 +static void
1494 +check_rounding (void)
1495 +{
1496 +  mpfr_t a, b, c, res;
1497 +  mpfr_prec_t p;
1498 +  long k, l;
1499 +  int i;
1500 +
1501 +#define MAXKL (2 * GMP_NUMB_BITS)
1502 +  for (p = MPFR_PREC_MIN; p <= GMP_NUMB_BITS; p++)
1503 +    {
1504 +      mpfr_init2 (a, p);
1505 +      mpfr_init2 (res, p);
1506 +      mpfr_init2 (b, p + 1 + MAXKL);
1507 +      mpfr_init2 (c, MPFR_PREC_MIN);
1508 +
1509 +      /* b = 2^p + 1 + 2^(-k), c = 2^(-l) */
1510 +      for (k = 0; k <= MAXKL; k++)
1511 +        for (l = 0; l <= MAXKL; l++)
1512 +          {
1513 +            mpfr_set_ui_2exp (b, 1, p, MPFR_RNDN);
1514 +            mpfr_add_ui (b, b, 1, MPFR_RNDN);
1515 +            mpfr_mul_2ui (b, b, k, MPFR_RNDN);
1516 +            mpfr_add_ui (b, b, 1, MPFR_RNDN);
1517 +            mpfr_div_2ui (b, b, k, MPFR_RNDN);
1518 +            mpfr_set_ui_2exp (c, 1, -l, MPFR_RNDN);
1519 +            i = mpfr_sub (a, b, c, MPFR_RNDN);
1520 +            /* b - c = 2^p + 1 + 2^(-k) - 2^(-l), should be rounded to
1521 +               2^p for l <= k, and 2^p+2 for l < k */
1522 +            if (l <= k)
1523 +              {
1524 +                if (mpfr_cmp_ui_2exp (a, 1, p) != 0)
1525 +                  {
1526 +                    printf ("Wrong result in check_rounding\n");
1527 +                    printf ("p=%lu k=%ld l=%ld\n", p, k, l);
1528 +                    printf ("b="); mpfr_print_binary (b); puts ("");
1529 +                    printf ("c="); mpfr_print_binary (c); puts ("");
1530 +                    printf ("Expected 2^%lu\n", p);
1531 +                    printf ("Got      "); mpfr_print_binary (a); puts ("");
1532 +                    exit (1);
1533 +                  }
1534 +                if (i >= 0)
1535 +                  {
1536 +                    printf ("Wrong ternary value in check_rounding\n");
1537 +                    printf ("p=%lu k=%ld l=%ld\n", p, k, l);
1538 +                    printf ("b="); mpfr_print_binary (b); puts ("");
1539 +                    printf ("c="); mpfr_print_binary (c); puts ("");
1540 +                    printf ("a="); mpfr_print_binary (a); puts ("");
1541 +                    printf ("Expected < 0, got %d\n", i);
1542 +                    exit (1);
1543 +                  }
1544 +              }
1545 +            else /* l < k */
1546 +              {
1547 +                mpfr_set_ui_2exp (res, 1, p, MPFR_RNDN);
1548 +                mpfr_add_ui (res, res, 2, MPFR_RNDN);
1549 +                if (mpfr_cmp (a, res) != 0)
1550 +                  {
1551 +                    printf ("Wrong result in check_rounding\n");
1552 +                    printf ("b="); mpfr_print_binary (b); puts ("");
1553 +                    printf ("c="); mpfr_print_binary (c); puts ("");
1554 +                    printf ("Expected "); mpfr_print_binary (res); puts ("");
1555 +                    printf ("Got      "); mpfr_print_binary (a); puts ("");
1556 +                    exit (1);
1557 +                  }
1558 +                if (i <= 0)
1559 +                  {
1560 +                    printf ("Wrong ternary value in check_rounding\n");
1561 +                    printf ("b="); mpfr_print_binary (b); puts ("");
1562 +                    printf ("c="); mpfr_print_binary (c); puts ("");
1563 +                    printf ("Expected > 0, got %d\n", i);
1564 +                    exit (1);
1565 +                  }
1566 +              }
1567 +          }
1568 +
1569 +      mpfr_clear (a);
1570 +      mpfr_clear (res);
1571 +      mpfr_clear (b);
1572 +      mpfr_clear (c);
1573 +    }
1574 +}
1575 +
1576  #define TEST_FUNCTION test_sub
1577  #define TWO_ARGS
1578  #define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), randlimb () % 100, RANDS)
1579 @@ -491,6 +643,8 @@
1580  
1581    tests_start_mpfr ();
1582  
1583 +  bug20101017 ();
1584 +  check_rounding ();
1585    check_diverse ();
1586    check_inexact ();
1587    bug_ddefour ();
1588 diff -Naurd mpfr-3.0.0.orig/version.c mpfr-3.0.0/version.c
1589 --- mpfr-3.0.0.orig/version.c   2010-10-21 20:28:38.000000000 +0000
1590 +++ mpfr-3.0.0/version.c        2010-10-21 20:59:32.000000000 +0000
1591 @@ -25,5 +25,5 @@
1592  const char *
1593  mpfr_get_version (void)
1594  {
1595 -  return "3.0.0-p5";
1596 +  return "3.0.0-p6";
1597  }
1598 diff -Naurd mpfr-3.0.0.orig/PATCHES mpfr-3.0.0/PATCHES
1599 --- mpfr-3.0.0.orig/PATCHES     2010-10-21 21:18:26.000000000 +0000
1600 +++ mpfr-3.0.0/PATCHES  2010-10-21 21:18:26.000000000 +0000
1601 @@ -0,0 +1 @@
1602 +mpfr_set_ld
1603 diff -Naurd mpfr-3.0.0.orig/VERSION mpfr-3.0.0/VERSION
1604 --- mpfr-3.0.0.orig/VERSION     2010-10-21 20:59:32.000000000 +0000
1605 +++ mpfr-3.0.0/VERSION  2010-10-21 21:18:26.000000000 +0000
1606 @@ -1 +1 @@
1607 -3.0.0-p6
1608 +3.0.0-p7
1609 diff -Naurd mpfr-3.0.0.orig/mpfr.h mpfr-3.0.0/mpfr.h
1610 --- mpfr-3.0.0.orig/mpfr.h      2010-10-21 20:59:32.000000000 +0000
1611 +++ mpfr-3.0.0/mpfr.h   2010-10-21 21:18:26.000000000 +0000
1612 @@ -27,7 +27,7 @@
1613  #define MPFR_VERSION_MAJOR 3
1614  #define MPFR_VERSION_MINOR 0
1615  #define MPFR_VERSION_PATCHLEVEL 0
1616 -#define MPFR_VERSION_STRING "3.0.0-p6"
1617 +#define MPFR_VERSION_STRING "3.0.0-p7"
1618  
1619  /* Macros dealing with MPFR VERSION */
1620  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
1621 diff -Naurd mpfr-3.0.0.orig/set_ld.c mpfr-3.0.0/set_ld.c
1622 --- mpfr-3.0.0.orig/set_ld.c    2010-06-10 11:00:14.000000000 +0000
1623 +++ mpfr-3.0.0/set_ld.c 2010-10-21 21:18:26.000000000 +0000
1624 @@ -102,21 +102,25 @@
1625              {
1626                x /= div13; /* exact */
1627                shift_exp += 8192;
1628 +              mpfr_div_2si (t, t, 8192, MPFR_RNDZ);
1629              }
1630            if (ABS (x) >= div12)
1631              {
1632                x /= div12; /* exact */
1633                shift_exp += 4096;
1634 +              mpfr_div_2si (t, t, 4096, MPFR_RNDZ);
1635              }
1636            if (ABS (x) >= div11)
1637              {
1638                x /= div11; /* exact */
1639                shift_exp += 2048;
1640 +              mpfr_div_2si (t, t, 2048, MPFR_RNDZ);
1641              }
1642            if (ABS (x) >= div10)
1643              {
1644                x /= div10; /* exact */
1645                shift_exp += 1024;
1646 +              mpfr_div_2si (t, t, 1024, MPFR_RNDZ);
1647              }
1648            /* warning: we may have DBL_MAX=2^1024*(1-2^(-53)) < x < 2^1024,
1649               therefore we have one extra exponent reduction step */
1650 @@ -124,9 +128,10 @@
1651              {
1652                x /= div9; /* exact */
1653                shift_exp += 512;
1654 +              mpfr_div_2si (t, t, 512, MPFR_RNDZ);
1655              }
1656          } /* Check overflow of double */
1657 -      else
1658 +      else /* no overflow on double */
1659          {
1660            long double div9, div10, div11;
1661  
1662 @@ -149,29 +154,34 @@
1663                  {
1664                    x /= div13; /* exact */
1665                    shift_exp -= 8192;
1666 +                  mpfr_mul_2si (t, t, 8192, MPFR_RNDZ);
1667                  }
1668                if (ABS (x) <= div12)
1669                  {
1670                    x /= div12; /* exact */
1671                    shift_exp -= 4096;
1672 +                  mpfr_mul_2si (t, t, 4096, MPFR_RNDZ);
1673                  }
1674                if (ABS (x) <= div11)
1675                  {
1676                    x /= div11; /* exact */
1677                    shift_exp -= 2048;
1678 +                  mpfr_mul_2si (t, t, 2048, MPFR_RNDZ);
1679                  }
1680                if (ABS (x) <= div10)
1681                  {
1682                    x /= div10; /* exact */
1683                    shift_exp -= 1024;
1684 +                  mpfr_mul_2si (t, t, 1024, MPFR_RNDZ);
1685                  }
1686                if (ABS(x) <= div9)
1687                  {
1688                    x /= div9;  /* exact */
1689                    shift_exp -= 512;
1690 +                  mpfr_mul_2si (t, t, 512, MPFR_RNDZ);
1691                  }
1692              }
1693 -          else
1694 +          else /* no underflow */
1695              {
1696                inexact = mpfr_set_d (u, (double) x, MPFR_RNDZ);
1697                MPFR_ASSERTD (inexact == 0);
1698 diff -Naurd mpfr-3.0.0.orig/tests/tset_ld.c mpfr-3.0.0/tests/tset_ld.c
1699 --- mpfr-3.0.0.orig/tests/tset_ld.c     2010-06-10 11:00:13.000000000 +0000
1700 +++ mpfr-3.0.0/tests/tset_ld.c  2010-10-21 21:18:26.000000000 +0000
1701 @@ -147,12 +147,39 @@
1702  test_fixed_bugs (void)
1703  {
1704    mpfr_t x;
1705 -  long double d;
1706 +  long double l, m;
1707  
1708    /* bug found by Steve Kargl (2009-03-14) */
1709    mpfr_init2 (x, 64);
1710    mpfr_set_ui_2exp (x, 1, -16447, MPFR_RNDN);
1711 -  d = mpfr_get_ld (x, MPFR_RNDN);  /* an assertion failed in init2.c:50 */
1712 +  mpfr_get_ld (x, MPFR_RNDN);  /* an assertion failed in init2.c:50 */
1713 +
1714 +  /* bug reported by Jakub Jelinek (2010-10-17)
1715 +     https://gforge.inria.fr/tracker/?func=detail&aid=11300 */
1716 +  mpfr_set_prec (x, MPFR_LDBL_MANT_DIG);
1717 +  /* l = 0x1.23456789abcdef0123456789abcdp-914L; */
1718 +  l = 8.215640181713713164092636634579e-276;
1719 +  mpfr_set_ld (x, l, MPFR_RNDN);
1720 +  m = mpfr_get_ld (x, MPFR_RNDN);
1721 +  if (m != l)
1722 +    {
1723 +      printf ("Error in get_ld o set_ld for l=%Le\n", l);
1724 +      printf ("Got m=%Le instead of l\n", m);
1725 +      exit (1);
1726 +    }
1727 +
1728 +  /* another similar test which failed with extended double precision and the
1729 +     generic code for mpfr_set_ld */
1730 +  /* l = 0x1.23456789abcdef0123456789abcdp-968L; */
1731 +  l = 4.560596445887084662336528403703e-292;
1732 +  mpfr_set_ld (x, l, MPFR_RNDN);
1733 +  m = mpfr_get_ld (x, MPFR_RNDN);
1734 +  if (m != l)
1735 +    {
1736 +      printf ("Error in get_ld o set_ld for l=%Le\n", l);
1737 +      printf ("Got m=%Le instead of l\n", m);
1738 +      exit (1);
1739 +    }
1740  
1741    mpfr_clear (x);
1742  }
1743 diff -Naurd mpfr-3.0.0.orig/version.c mpfr-3.0.0/version.c
1744 --- mpfr-3.0.0.orig/version.c   2010-10-21 20:59:32.000000000 +0000
1745 +++ mpfr-3.0.0/version.c        2010-10-21 21:18:26.000000000 +0000
1746 @@ -25,5 +25,5 @@
1747  const char *
1748  mpfr_get_version (void)
1749  {
1750 -  return "3.0.0-p6";
1751 +  return "3.0.0-p7";
1752  }
1753 diff -Naurd mpfr-3.0.0.orig/PATCHES mpfr-3.0.0/PATCHES
1754 --- mpfr-3.0.0.orig/PATCHES     2010-11-09 15:15:07.000000000 +0000
1755 +++ mpfr-3.0.0/PATCHES  2010-11-09 15:15:07.000000000 +0000
1756 @@ -0,0 +1 @@
1757 +macros
1758 diff -Naurd mpfr-3.0.0.orig/VERSION mpfr-3.0.0/VERSION
1759 --- mpfr-3.0.0.orig/VERSION     2010-10-21 21:18:26.000000000 +0000
1760 +++ mpfr-3.0.0/VERSION  2010-11-09 15:15:07.000000000 +0000
1761 @@ -1 +1 @@
1762 -3.0.0-p7
1763 +3.0.0-p8
1764 diff -Naurd mpfr-3.0.0.orig/mpfr.h mpfr-3.0.0/mpfr.h
1765 --- mpfr-3.0.0.orig/mpfr.h      2010-10-21 21:18:26.000000000 +0000
1766 +++ mpfr-3.0.0/mpfr.h   2010-11-09 15:15:07.000000000 +0000
1767 @@ -27,7 +27,7 @@
1768  #define MPFR_VERSION_MAJOR 3
1769  #define MPFR_VERSION_MINOR 0
1770  #define MPFR_VERSION_PATCHLEVEL 0
1771 -#define MPFR_VERSION_STRING "3.0.0-p7"
1772 +#define MPFR_VERSION_STRING "3.0.0-p8"
1773  
1774  /* Macros dealing with MPFR VERSION */
1775  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
1776 @@ -67,6 +67,16 @@
1777  # define _MPFR_H_HAVE_INTMAX_T 1
1778  #endif
1779  
1780 +/* Avoid some problems with macro expansion if the user defines macros
1781 +   with the same name as keywords. By convention, identifiers and macro
1782 +   names starting with mpfr_ are reserved by MPFR. */
1783 +typedef void            mpfr_void;
1784 +typedef int             mpfr_int;
1785 +typedef unsigned int    mpfr_uint;
1786 +typedef long            mpfr_long;
1787 +typedef unsigned long   mpfr_ulong;
1788 +typedef size_t          mpfr_size_t;
1789 +
1790  /* Definition of rounding modes (DON'T USE MPFR_RNDNA!).
1791     Warning! Changing the contents of this enum should be seen as an
1792     interface change since the old and the new types are not compatible
1793 @@ -136,7 +146,7 @@
1794  typedef mp_exp_t     mpfr_exp_t;
1795  
1796  /* Definition of the standard exponent limits */
1797 -#define MPFR_EMAX_DEFAULT ((mpfr_exp_t) (((unsigned long) 1 << 30) - 1))
1798 +#define MPFR_EMAX_DEFAULT ((mpfr_exp_t) (((mpfr_ulong) 1 << 30) - 1))
1799  #define MPFR_EMIN_DEFAULT (-(MPFR_EMAX_DEFAULT))
1800  
1801  /* Definition of the main structure */
1802 @@ -725,13 +735,13 @@
1803     unexpected results with future compilers and aggressive optimisations.
1804     Why not working only with signed types, using INT_MIN and LONG_MIN? */
1805  #if __GMP_MP_SIZE_T_INT
1806 -#define __MPFR_EXP_NAN  ((mpfr_exp_t)((~((~(unsigned int)0)>>1))+2))
1807 -#define __MPFR_EXP_ZERO ((mpfr_exp_t)((~((~(unsigned int)0)>>1))+1))
1808 -#define __MPFR_EXP_INF  ((mpfr_exp_t)((~((~(unsigned int)0)>>1))+3))
1809 +#define __MPFR_EXP_NAN  ((mpfr_exp_t)((~((~(mpfr_uint)0)>>1))+2))
1810 +#define __MPFR_EXP_ZERO ((mpfr_exp_t)((~((~(mpfr_uint)0)>>1))+1))
1811 +#define __MPFR_EXP_INF  ((mpfr_exp_t)((~((~(mpfr_uint)0)>>1))+3))
1812  #else
1813 -#define __MPFR_EXP_NAN  ((mpfr_exp_t)((~((~(unsigned long)0)>>1))+2))
1814 -#define __MPFR_EXP_ZERO ((mpfr_exp_t)((~((~(unsigned long)0)>>1))+1))
1815 -#define __MPFR_EXP_INF  ((mpfr_exp_t)((~((~(unsigned long)0)>>1))+3))
1816 +#define __MPFR_EXP_NAN  ((mpfr_exp_t)((~((~(mpfr_ulong)0)>>1))+2))
1817 +#define __MPFR_EXP_ZERO ((mpfr_exp_t)((~((~(mpfr_ulong)0)>>1))+1))
1818 +#define __MPFR_EXP_INF  ((mpfr_exp_t)((~((~(mpfr_ulong)0)>>1))+3))
1819  #endif
1820  
1821  /* Define MPFR_USE_EXTENSION to avoid "gcc -pedantic" warnings. */
1822 @@ -760,9 +770,9 @@
1823  #define mpfr_inf_p(_x)      ((_x)->_mpfr_exp == __MPFR_EXP_INF)
1824  #define mpfr_zero_p(_x)     ((_x)->_mpfr_exp == __MPFR_EXP_ZERO)
1825  #define mpfr_regular_p(_x)  ((_x)->_mpfr_exp >  __MPFR_EXP_INF)
1826 -#define mpfr_sgn(_x)                                          \
1827 -  ((_x)->_mpfr_exp < __MPFR_EXP_INF ?                         \
1828 -   (mpfr_nan_p (_x) ? mpfr_set_erangeflag () : (void) 0), 0 : \
1829 +#define mpfr_sgn(_x)                                               \
1830 +  ((_x)->_mpfr_exp < __MPFR_EXP_INF ?                              \
1831 +   (mpfr_nan_p (_x) ? mpfr_set_erangeflag () : (mpfr_void) 0), 0 : \
1832     MPFR_SIGN (_x))
1833  
1834  /* Prevent them from using as lvalues */
1835 @@ -805,7 +815,19 @@
1836     Moreover casts to unsigned long have been added to avoid warnings in
1837     programs that use MPFR and are compiled with -Wconversion; such casts
1838     are OK since if X is a constant expression, then (unsigned long) X is
1839 -   also a constant expression, so that the optimizations still work. */
1840 +   also a constant expression, so that the optimizations still work. The
1841 +   warnings are probably related to the following two bugs:
1842 +     http://gcc.gnu.org/bugzilla/show_bug.cgi?id=4210
1843 +     http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38470 (possibly a variant)
1844 +   and the casts could be removed once these bugs are fixed.
1845 +   Casts shouldn't be used on the generic calls (to the ..._2exp functions),
1846 +   where implicit conversions are performed. Indeed, having at least one
1847 +   implicit conversion in the macro allows the compiler to emit diagnostics
1848 +   when normally expected, for instance in the following call:
1849 +     mpfr_set_ui (x, "foo", MPFR_RNDN);
1850 +   If this is not possible (for future macros), one of the tricks described
1851 +   on http://groups.google.com/group/comp.std.c/msg/e92abd24bf9eaf7b could
1852 +   be used. */
1853  #if defined (__GNUC__) && !defined(__ICC) && !defined(__cplusplus)
1854  #if (__GNUC__ >= 2)
1855  #undef mpfr_cmp_ui
1856 @@ -813,45 +835,45 @@
1857     But warning! mpfr_sgn is specified as a macro in the API, thus the macro
1858     mustn't be used if side effects are possible, like here. */
1859  #define mpfr_cmp_ui(_f,_u)                                      \
1860 -  (__builtin_constant_p (_u) && (unsigned long) (_u) == 0 ?     \
1861 +  (__builtin_constant_p (_u) && (mpfr_ulong) (_u) == 0 ?        \
1862     (mpfr_sgn) (_f) :                                            \
1863 -   mpfr_cmp_ui_2exp ((_f), (unsigned long) (_u), 0))
1864 +   mpfr_cmp_ui_2exp ((_f), (_u), 0))
1865  #undef mpfr_cmp_si
1866 -#define mpfr_cmp_si(_f,_s)                              \
1867 -  (__builtin_constant_p (_s) && (long) (_s) >= 0 ?      \
1868 -   mpfr_cmp_ui ((_f), (unsigned long) (long) (_s)) :    \
1869 -   mpfr_cmp_si_2exp ((_f), (long) (_s), 0))
1870 +#define mpfr_cmp_si(_f,_s)                                      \
1871 +  (__builtin_constant_p (_s) && (mpfr_long) (_s) >= 0 ?         \
1872 +   mpfr_cmp_ui ((_f), (mpfr_ulong) (mpfr_long) (_s)) :          \
1873 +   mpfr_cmp_si_2exp ((_f), (_s), 0))
1874  #if __GNUC__ > 2 || __GNUC_MINOR__ >= 95
1875  #undef mpfr_set_ui
1876  #define mpfr_set_ui(_f,_u,_r)                                   \
1877 -  (__builtin_constant_p (_u) && (unsigned long) (_u) == 0 ?     \
1878 +  (__builtin_constant_p (_u) && (mpfr_ulong) (_u) == 0 ?        \
1879     __extension__ ({                                             \
1880         mpfr_ptr _p = (_f);                                      \
1881         _p->_mpfr_sign = 1;                                      \
1882         _p->_mpfr_exp = __MPFR_EXP_ZERO;                         \
1883 -       (void) (_r); 0; }) :                                     \
1884 -   mpfr_set_ui_2exp ((_f), (unsigned long) (_u), 0, (_r)))
1885 +       (mpfr_void) (_r); 0; }) :                                \
1886 +   mpfr_set_ui_2exp ((_f), (_u), 0, (_r)))
1887  #endif
1888  #undef mpfr_set_si
1889  #define mpfr_set_si(_f,_s,_r)                                   \
1890 -  (__builtin_constant_p (_s) && (long) (_s) >= 0 ?              \
1891 -   mpfr_set_ui ((_f), (unsigned long) (long) (_s), (_r)) :      \
1892 -   mpfr_set_si_2exp ((_f), (long) (_s), 0, (_r)))
1893 +  (__builtin_constant_p (_s) && (mpfr_long) (_s) >= 0 ?         \
1894 +   mpfr_set_ui ((_f), (mpfr_ulong) (mpfr_long) (_s), (_r)) :    \
1895 +   mpfr_set_si_2exp ((_f), (_s), 0, (_r)))
1896  #endif
1897  #endif
1898  
1899  /* Macro version of mpfr_stack interface for fast access */
1900 -#define mpfr_custom_get_size(p) ((size_t)                            \
1901 +#define mpfr_custom_get_size(p) ((mpfr_size_t)                          \
1902         (((p)+GMP_NUMB_BITS-1)/GMP_NUMB_BITS*sizeof (mp_limb_t)))
1903  #define mpfr_custom_init(m,p) do {} while (0)
1904 -#define mpfr_custom_get_significand(x) ((void*)((x)->_mpfr_d))
1905 +#define mpfr_custom_get_significand(x) ((mpfr_void*)((x)->_mpfr_d))
1906  #define mpfr_custom_get_exp(x) ((x)->_mpfr_exp)
1907  #define mpfr_custom_move(x,m) do { ((x)->_mpfr_d = (mp_limb_t*)(m)); } while (0)
1908  #define mpfr_custom_init_set(x,k,e,p,m) do {                   \
1909    mpfr_ptr _x = (x);                                           \
1910    mpfr_exp_t _e;                                               \
1911    mpfr_kind_t _t;                                              \
1912 -  int _s, _k;                                                  \
1913 +  mpfr_int _s, _k;                                             \
1914    _k = (k);                                                    \
1915    if (_k >= 0)  {                                              \
1916      _t = (mpfr_kind_t) _k;                                     \
1917 @@ -868,11 +890,13 @@
1918    _x->_mpfr_exp  = _e;                                         \
1919    _x->_mpfr_d    = (mp_limb_t*) (m);                           \
1920   } while (0)
1921 -#define mpfr_custom_get_kind(x)                                              \
1922 -  ( (x)->_mpfr_exp >  __MPFR_EXP_INF ? (int)MPFR_REGULAR_KIND*MPFR_SIGN (x) \
1923 -  : (x)->_mpfr_exp == __MPFR_EXP_INF ? (int)MPFR_INF_KIND*MPFR_SIGN (x)     \
1924 -  : (x)->_mpfr_exp == __MPFR_EXP_NAN ? (int)MPFR_NAN_KIND                   \
1925 -  : (int) MPFR_ZERO_KIND * MPFR_SIGN (x) )
1926 +#define mpfr_custom_get_kind(x)                                         \
1927 +  ( (x)->_mpfr_exp >  __MPFR_EXP_INF ?                                  \
1928 +    (mpfr_int) MPFR_REGULAR_KIND * MPFR_SIGN (x)                        \
1929 +  : (x)->_mpfr_exp == __MPFR_EXP_INF ?                                  \
1930 +    (mpfr_int) MPFR_INF_KIND * MPFR_SIGN (x)                            \
1931 +  : (x)->_mpfr_exp == __MPFR_EXP_NAN ? (mpfr_int) MPFR_NAN_KIND         \
1932 +  : (mpfr_int) MPFR_ZERO_KIND * MPFR_SIGN (x) )
1933  
1934  
1935  #endif /* MPFR_USE_NO_MACRO */
1936 diff -Naurd mpfr-3.0.0.orig/version.c mpfr-3.0.0/version.c
1937 --- mpfr-3.0.0.orig/version.c   2010-10-21 21:18:26.000000000 +0000
1938 +++ mpfr-3.0.0/version.c        2010-11-09 15:15:07.000000000 +0000
1939 @@ -25,5 +25,5 @@
1940  const char *
1941  mpfr_get_version (void)
1942  {
1943 -  return "3.0.0-p7";
1944 +  return "3.0.0-p8";
1945  }