1 diff -rupN mpfr-3.0.0.orig/Makefile.in mpfr-3.0.0/Makefile.in
2 --- mpfr-3.0.0.orig/Makefile.in 2010-11-17 14:50:50.054040400 -0700
3 +++ mpfr-3.0.0/Makefile.in 2010-06-10 05:00:52.000000000 -0600
4 @@ -239,6 +239,7 @@ GZIP_ENV = --best
5 distuninstallcheck_listfiles = find . -type f -print
6 distcleancheck_listfiles = find . -type f -print
12 diff -rupN mpfr-3.0.0.orig/PATCHES mpfr-3.0.0/PATCHES
13 --- mpfr-3.0.0.orig/PATCHES 2010-11-17 14:50:50.081041900 -0700
14 +++ mpfr-3.0.0/PATCHES 2010-11-17 14:51:05.016295800 -0700
24 diff -rupN mpfr-3.0.0.orig/VERSION mpfr-3.0.0/VERSION
25 --- mpfr-3.0.0.orig/VERSION 2010-11-17 14:50:50.821082000 -0700
26 +++ mpfr-3.0.0/VERSION 2010-11-09 08:15:07.000000000 -0700
30 diff -rupN mpfr-3.0.0.orig/acinclude.m4 mpfr-3.0.0/acinclude.m4
31 --- mpfr-3.0.0.orig/acinclude.m4 2010-11-17 14:50:49.896031300 -0700
32 +++ mpfr-3.0.0/acinclude.m4 2010-06-10 05:00:14.000000000 -0600
33 @@ -59,6 +59,9 @@ AC_CHECK_HEADER([stdarg.h],[AC_DEFINE([H
34 dnl sys/fpu.h - MIPS specific
35 AC_CHECK_HEADERS([sys/time.h sys/fpu.h])
37 +dnl Check how to get `alloca'
43 diff -rupN mpfr-3.0.0.orig/configure mpfr-3.0.0/configure
44 --- mpfr-3.0.0.orig/configure 2010-11-17 14:50:49.945034100 -0700
45 +++ mpfr-3.0.0/configure 2010-06-25 07:23:05.000000000 -0600
46 @@ -783,6 +783,7 @@ LIBTOOL
54 @@ -5622,6 +5623,197 @@ fi
58 +# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
59 +# for constant arguments. Useless!
60 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for working alloca.h" >&5
61 +$as_echo_n "checking for working alloca.h... " >&6; }
62 +if test "${ac_cv_working_alloca_h+set}" = set; then :
63 + $as_echo_n "(cached) " >&6
65 + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
66 +/* end confdefs.h. */
71 +char *p = (char *) alloca (2 * sizeof (int));
77 +if ac_fn_c_try_link "$LINENO"; then :
78 + ac_cv_working_alloca_h=yes
80 + ac_cv_working_alloca_h=no
82 +rm -f core conftest.err conftest.$ac_objext \
83 + conftest$ac_exeext conftest.$ac_ext
85 +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_working_alloca_h" >&5
86 +$as_echo "$ac_cv_working_alloca_h" >&6; }
87 +if test $ac_cv_working_alloca_h = yes; then
89 +$as_echo "#define HAVE_ALLOCA_H 1" >>confdefs.h
93 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for alloca" >&5
94 +$as_echo_n "checking for alloca... " >&6; }
95 +if test "${ac_cv_func_alloca_works+set}" = set; then :
96 + $as_echo_n "(cached) " >&6
98 + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
99 +/* end confdefs.h. */
101 +# define alloca __builtin_alloca
104 +# include <malloc.h>
105 +# define alloca _alloca
107 +# ifdef HAVE_ALLOCA_H
108 +# include <alloca.h>
113 +# ifndef alloca /* predefined by HP cc +Olibcalls */
124 +char *p = (char *) alloca (1);
130 +if ac_fn_c_try_link "$LINENO"; then :
131 + ac_cv_func_alloca_works=yes
133 + ac_cv_func_alloca_works=no
135 +rm -f core conftest.err conftest.$ac_objext \
136 + conftest$ac_exeext conftest.$ac_ext
138 +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_alloca_works" >&5
139 +$as_echo "$ac_cv_func_alloca_works" >&6; }
141 +if test $ac_cv_func_alloca_works = yes; then
143 +$as_echo "#define HAVE_ALLOCA 1" >>confdefs.h
146 + # The SVR3 libPW and SVR4 libucb both contain incompatible functions
147 +# that cause trouble. Some versions do not even contain alloca or
148 +# contain a buggy version. If you still want to use their alloca,
149 +# use ar to extract alloca.o from them instead of compiling alloca.c.
151 +ALLOCA=\${LIBOBJDIR}alloca.$ac_objext
153 +$as_echo "#define C_ALLOCA 1" >>confdefs.h
156 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether \`alloca.c' needs Cray hooks" >&5
157 +$as_echo_n "checking whether \`alloca.c' needs Cray hooks... " >&6; }
158 +if test "${ac_cv_os_cray+set}" = set; then :
159 + $as_echo_n "(cached) " >&6
161 + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
162 +/* end confdefs.h. */
163 +#if defined CRAY && ! defined CRAY2
170 +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
171 + $EGREP "webecray" >/dev/null 2>&1; then :
179 +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_os_cray" >&5
180 +$as_echo "$ac_cv_os_cray" >&6; }
181 +if test $ac_cv_os_cray = yes; then
182 + for ac_func in _getb67 GETB67 getb67; do
183 + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
184 +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
185 +eval as_val=\$$as_ac_var
186 + if test "x$as_val" = x""yes; then :
188 +cat >>confdefs.h <<_ACEOF
189 +#define CRAY_STACKSEG_END $ac_func
198 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking stack direction for C alloca" >&5
199 +$as_echo_n "checking stack direction for C alloca... " >&6; }
200 +if test "${ac_cv_c_stack_direction+set}" = set; then :
201 + $as_echo_n "(cached) " >&6
203 + if test "$cross_compiling" = yes; then :
204 + ac_cv_c_stack_direction=0
206 + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
207 +/* end confdefs.h. */
208 +$ac_includes_default
210 +find_stack_direction ()
212 + static char *addr = 0;
217 + return find_stack_direction ();
220 + return (&dummy > addr) ? 1 : -1;
226 + return find_stack_direction () < 0;
229 +if ac_fn_c_try_run "$LINENO"; then :
230 + ac_cv_c_stack_direction=1
232 + ac_cv_c_stack_direction=-1
234 +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
235 + conftest.$ac_objext conftest.beam conftest.$ac_ext
239 +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_stack_direction" >&5
240 +$as_echo "$ac_cv_c_stack_direction" >&6; }
241 +cat >>confdefs.h <<_ACEOF
242 +#define STACK_DIRECTION $ac_cv_c_stack_direction
250 for ac_header in stdint.h
252 @@ -7564,13 +7756,13 @@ if test "${lt_cv_nm_interface+set}" = se
254 lt_cv_nm_interface="BSD nm"
255 echo "int some_variable = 0;" > conftest.$ac_ext
256 - (eval echo "\"\$as_me:7567: $ac_compile\"" >&5)
257 + (eval echo "\"\$as_me:7759: $ac_compile\"" >&5)
258 (eval "$ac_compile" 2>conftest.err)
260 - (eval echo "\"\$as_me:7570: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
261 + (eval echo "\"\$as_me:7762: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
262 (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
264 - (eval echo "\"\$as_me:7573: output\"" >&5)
265 + (eval echo "\"\$as_me:7765: output\"" >&5)
267 if $GREP 'External.*some_variable' conftest.out > /dev/null; then
268 lt_cv_nm_interface="MS dumpbin"
269 @@ -8772,7 +8964,7 @@ ia64-*-hpux*)
272 # Find out which ABI we are using.
273 - echo '#line 8775 "configure"' > conftest.$ac_ext
274 + echo '#line 8967 "configure"' > conftest.$ac_ext
275 if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
276 (eval $ac_compile) 2>&5
278 @@ -10032,11 +10224,11 @@ else
279 -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
280 -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
281 -e 's:$: $lt_compiler_flag:'`
282 - (eval echo "\"\$as_me:10035: $lt_compile\"" >&5)
283 + (eval echo "\"\$as_me:10227: $lt_compile\"" >&5)
284 (eval "$lt_compile" 2>conftest.err)
287 - echo "$as_me:10039: \$? = $ac_status" >&5
288 + echo "$as_me:10231: \$? = $ac_status" >&5
289 if (exit $ac_status) && test -s "$ac_outfile"; then
290 # The compiler can only warn and ignore the option if not recognized
291 # So say no if there are warnings other than the usual output.
292 @@ -10371,11 +10563,11 @@ else
293 -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
294 -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
295 -e 's:$: $lt_compiler_flag:'`
296 - (eval echo "\"\$as_me:10374: $lt_compile\"" >&5)
297 + (eval echo "\"\$as_me:10566: $lt_compile\"" >&5)
298 (eval "$lt_compile" 2>conftest.err)
301 - echo "$as_me:10378: \$? = $ac_status" >&5
302 + echo "$as_me:10570: \$? = $ac_status" >&5
303 if (exit $ac_status) && test -s "$ac_outfile"; then
304 # The compiler can only warn and ignore the option if not recognized
305 # So say no if there are warnings other than the usual output.
306 @@ -10476,11 +10668,11 @@ else
307 -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
308 -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
309 -e 's:$: $lt_compiler_flag:'`
310 - (eval echo "\"\$as_me:10479: $lt_compile\"" >&5)
311 + (eval echo "\"\$as_me:10671: $lt_compile\"" >&5)
312 (eval "$lt_compile" 2>out/conftest.err)
314 cat out/conftest.err >&5
315 - echo "$as_me:10483: \$? = $ac_status" >&5
316 + echo "$as_me:10675: \$? = $ac_status" >&5
317 if (exit $ac_status) && test -s out/conftest2.$ac_objext
319 # The compiler can only warn and ignore the option if not recognized
320 @@ -10531,11 +10723,11 @@ else
321 -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
322 -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
323 -e 's:$: $lt_compiler_flag:'`
324 - (eval echo "\"\$as_me:10534: $lt_compile\"" >&5)
325 + (eval echo "\"\$as_me:10726: $lt_compile\"" >&5)
326 (eval "$lt_compile" 2>out/conftest.err)
328 cat out/conftest.err >&5
329 - echo "$as_me:10538: \$? = $ac_status" >&5
330 + echo "$as_me:10730: \$? = $ac_status" >&5
331 if (exit $ac_status) && test -s out/conftest2.$ac_objext
333 # The compiler can only warn and ignore the option if not recognized
334 @@ -12915,7 +13107,7 @@ else
335 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
336 lt_status=$lt_dlunknown
337 cat > conftest.$ac_ext <<_LT_EOF
338 -#line 12918 "configure"
339 +#line 13110 "configure"
340 #include "confdefs.h"
343 @@ -13011,7 +13203,7 @@ else
344 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
345 lt_status=$lt_dlunknown
346 cat > conftest.$ac_ext <<_LT_EOF
347 -#line 13014 "configure"
348 +#line 13206 "configure"
349 #include "confdefs.h"
352 diff -rupN mpfr-3.0.0.orig/gamma.c mpfr-3.0.0/gamma.c
353 --- mpfr-3.0.0.orig/gamma.c 2010-11-17 14:50:50.003037400 -0700
354 +++ mpfr-3.0.0/gamma.c 2010-07-09 18:11:46.000000000 -0600
355 @@ -274,7 +274,7 @@ mpfr_gamma (mpfr_ptr gamma, mpfr_srcptr
356 /* we want an upper bound for x * [log(2-x)-1].
357 since x < 0, we need a lower bound on log(2-x) */
358 mpfr_ui_sub (xp, 2, x, MPFR_RNDD);
359 - mpfr_log (xp, xp, MPFR_RNDD);
360 + mpfr_log2 (xp, xp, MPFR_RNDD);
361 mpfr_sub_ui (xp, xp, 1, MPFR_RNDD);
362 mpfr_mul (xp, xp, x, MPFR_RNDU);
364 @@ -303,8 +303,8 @@ mpfr_gamma (mpfr_ptr gamma, mpfr_srcptr
366 mpfr_sub (tmp, tmp, tmp2, MPFR_RNDZ); /* low bnd on |sin(Pi*(2-x))| */
367 mpfr_ui_div (tmp, 12, tmp, MPFR_RNDU); /* upper bound */
368 - mpfr_log (tmp, tmp, MPFR_RNDU);
369 - mpfr_add (tmp, tmp, xp, MPFR_RNDU);
370 + mpfr_log2 (tmp, tmp, MPFR_RNDU);
371 + mpfr_add (xp, tmp, xp, MPFR_RNDU);
372 underflow = mpfr_cmp_si (xp, expo.saved_emin - 2) <= 0;
375 diff -rupN mpfr-3.0.0.orig/mpfr.h mpfr-3.0.0/mpfr.h
376 --- mpfr-3.0.0.orig/mpfr.h 2010-11-17 14:50:50.066041000 -0700
377 +++ mpfr-3.0.0/mpfr.h 2010-11-09 08:15:07.000000000 -0700
378 @@ -27,7 +27,7 @@ http://www.gnu.org/licenses/ or write to
379 #define MPFR_VERSION_MAJOR 3
380 #define MPFR_VERSION_MINOR 0
381 #define MPFR_VERSION_PATCHLEVEL 0
382 -#define MPFR_VERSION_STRING "3.0.0"
383 +#define MPFR_VERSION_STRING "3.0.0-p8"
385 /* Macros dealing with MPFR VERSION */
386 #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
387 @@ -67,6 +67,16 @@ MPFR_VERSION_NUM(MPFR_VERSION_MAJOR,MPFR
388 # define _MPFR_H_HAVE_INTMAX_T 1
391 +/* Avoid some problems with macro expansion if the user defines macros
392 + with the same name as keywords. By convention, identifiers and macro
393 + names starting with mpfr_ are reserved by MPFR. */
394 +typedef void mpfr_void;
395 +typedef int mpfr_int;
396 +typedef unsigned int mpfr_uint;
397 +typedef long mpfr_long;
398 +typedef unsigned long mpfr_ulong;
399 +typedef size_t mpfr_size_t;
401 /* Definition of rounding modes (DON'T USE MPFR_RNDNA!).
402 Warning! Changing the contents of this enum should be seen as an
403 interface change since the old and the new types are not compatible
404 @@ -136,7 +146,7 @@ typedef int mpfr_sign_t;
405 typedef mp_exp_t mpfr_exp_t;
407 /* Definition of the standard exponent limits */
408 -#define MPFR_EMAX_DEFAULT ((mpfr_exp_t) (((unsigned long) 1 << 30) - 1))
409 +#define MPFR_EMAX_DEFAULT ((mpfr_exp_t) (((mpfr_ulong) 1 << 30) - 1))
410 #define MPFR_EMIN_DEFAULT (-(MPFR_EMAX_DEFAULT))
412 /* Definition of the main structure */
413 @@ -725,13 +735,13 @@ __MPFR_DECLSPEC int mpfr_custom_get_k
414 unexpected results with future compilers and aggressive optimisations.
415 Why not working only with signed types, using INT_MIN and LONG_MIN? */
416 #if __GMP_MP_SIZE_T_INT
417 -#define __MPFR_EXP_NAN ((mpfr_exp_t)((~((~(unsigned int)0)>>1))+2))
418 -#define __MPFR_EXP_ZERO ((mpfr_exp_t)((~((~(unsigned int)0)>>1))+1))
419 -#define __MPFR_EXP_INF ((mpfr_exp_t)((~((~(unsigned int)0)>>1))+3))
420 +#define __MPFR_EXP_NAN ((mpfr_exp_t)((~((~(mpfr_uint)0)>>1))+2))
421 +#define __MPFR_EXP_ZERO ((mpfr_exp_t)((~((~(mpfr_uint)0)>>1))+1))
422 +#define __MPFR_EXP_INF ((mpfr_exp_t)((~((~(mpfr_uint)0)>>1))+3))
424 -#define __MPFR_EXP_NAN ((mpfr_exp_t)((~((~(unsigned long)0)>>1))+2))
425 -#define __MPFR_EXP_ZERO ((mpfr_exp_t)((~((~(unsigned long)0)>>1))+1))
426 -#define __MPFR_EXP_INF ((mpfr_exp_t)((~((~(unsigned long)0)>>1))+3))
427 +#define __MPFR_EXP_NAN ((mpfr_exp_t)((~((~(mpfr_ulong)0)>>1))+2))
428 +#define __MPFR_EXP_ZERO ((mpfr_exp_t)((~((~(mpfr_ulong)0)>>1))+1))
429 +#define __MPFR_EXP_INF ((mpfr_exp_t)((~((~(mpfr_ulong)0)>>1))+3))
432 /* Define MPFR_USE_EXTENSION to avoid "gcc -pedantic" warnings. */
433 @@ -760,9 +770,9 @@ __MPFR_DECLSPEC int mpfr_custom_get_k
434 #define mpfr_inf_p(_x) ((_x)->_mpfr_exp == __MPFR_EXP_INF)
435 #define mpfr_zero_p(_x) ((_x)->_mpfr_exp == __MPFR_EXP_ZERO)
436 #define mpfr_regular_p(_x) ((_x)->_mpfr_exp > __MPFR_EXP_INF)
437 -#define mpfr_sgn(_x) \
438 - ((_x)->_mpfr_exp < __MPFR_EXP_INF ? \
439 - (mpfr_nan_p (_x) ? mpfr_set_erangeflag () : (void) 0), 0 : \
440 +#define mpfr_sgn(_x) \
441 + ((_x)->_mpfr_exp < __MPFR_EXP_INF ? \
442 + (mpfr_nan_p (_x) ? mpfr_set_erangeflag () : (mpfr_void) 0), 0 : \
445 /* Prevent them from using as lvalues */
446 @@ -798,50 +808,72 @@ __MPFR_DECLSPEC int mpfr_custom_get_k
447 anyway. Checking with other ICC versions is needed. Possibly detect
448 whether warnings are produced or not with a configure test.
449 + Remove C++ too, since it complains too much. */
450 +/* Added casts to improve robustness in case of undefined behavior and
451 + compiler extensions based on UB (in particular -fwrapv). MPFR doesn't
452 + use such extensions, but these macros will be used by 3rd-party code,
453 + where such extensions may be required.
454 + Moreover casts to unsigned long have been added to avoid warnings in
455 + programs that use MPFR and are compiled with -Wconversion; such casts
456 + are OK since if X is a constant expression, then (unsigned long) X is
457 + also a constant expression, so that the optimizations still work. The
458 + warnings are probably related to the following two bugs:
459 + http://gcc.gnu.org/bugzilla/show_bug.cgi?id=4210
460 + http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38470 (possibly a variant)
461 + and the casts could be removed once these bugs are fixed.
462 + Casts shouldn't be used on the generic calls (to the ..._2exp functions),
463 + where implicit conversions are performed. Indeed, having at least one
464 + implicit conversion in the macro allows the compiler to emit diagnostics
465 + when normally expected, for instance in the following call:
466 + mpfr_set_ui (x, "foo", MPFR_RNDN);
467 + If this is not possible (for future macros), one of the tricks described
468 + on http://groups.google.com/group/comp.std.c/msg/e92abd24bf9eaf7b could
470 #if defined (__GNUC__) && !defined(__ICC) && !defined(__cplusplus)
473 -/* We use the fact that mpfr_sgn on NaN sets the erange flag and returns 0. */
474 -#define mpfr_cmp_ui(_f,_u) \
475 - (__builtin_constant_p (_u) && (_u) == 0 ? \
477 - mpfr_cmp_ui_2exp ((_f),(_u),0))
478 +/* We use the fact that mpfr_sgn on NaN sets the erange flag and returns 0.
479 + But warning! mpfr_sgn is specified as a macro in the API, thus the macro
480 + mustn't be used if side effects are possible, like here. */
481 +#define mpfr_cmp_ui(_f,_u) \
482 + (__builtin_constant_p (_u) && (mpfr_ulong) (_u) == 0 ? \
483 + (mpfr_sgn) (_f) : \
484 + mpfr_cmp_ui_2exp ((_f), (_u), 0))
486 -#define mpfr_cmp_si(_f,_s) \
487 - (__builtin_constant_p (_s) && (_s) >= 0 ? \
488 - mpfr_cmp_ui ((_f), (_s)) : \
489 +#define mpfr_cmp_si(_f,_s) \
490 + (__builtin_constant_p (_s) && (mpfr_long) (_s) >= 0 ? \
491 + mpfr_cmp_ui ((_f), (mpfr_ulong) (mpfr_long) (_s)) : \
492 mpfr_cmp_si_2exp ((_f), (_s), 0))
493 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 95
495 -#define mpfr_set_ui(_f,_u,_r) \
496 - (__builtin_constant_p (_u) && (_u) == 0 ? \
498 - mpfr_ptr _p = (_f); \
499 - _p->_mpfr_sign = 1; \
500 - _p->_mpfr_exp = __MPFR_EXP_ZERO; \
501 - (void) (_r); 0; }) : \
502 +#define mpfr_set_ui(_f,_u,_r) \
503 + (__builtin_constant_p (_u) && (mpfr_ulong) (_u) == 0 ? \
505 + mpfr_ptr _p = (_f); \
506 + _p->_mpfr_sign = 1; \
507 + _p->_mpfr_exp = __MPFR_EXP_ZERO; \
508 + (mpfr_void) (_r); 0; }) : \
509 mpfr_set_ui_2exp ((_f), (_u), 0, (_r)))
512 -#define mpfr_set_si(_f,_s,_r) \
513 - (__builtin_constant_p (_s) && (_s) >= 0 ? \
514 - mpfr_set_ui ((_f), (_s), (_r)) : \
515 +#define mpfr_set_si(_f,_s,_r) \
516 + (__builtin_constant_p (_s) && (mpfr_long) (_s) >= 0 ? \
517 + mpfr_set_ui ((_f), (mpfr_ulong) (mpfr_long) (_s), (_r)) : \
518 mpfr_set_si_2exp ((_f), (_s), 0, (_r)))
522 /* Macro version of mpfr_stack interface for fast access */
523 -#define mpfr_custom_get_size(p) ((size_t) \
524 +#define mpfr_custom_get_size(p) ((mpfr_size_t) \
525 (((p)+GMP_NUMB_BITS-1)/GMP_NUMB_BITS*sizeof (mp_limb_t)))
526 #define mpfr_custom_init(m,p) do {} while (0)
527 -#define mpfr_custom_get_significand(x) ((void*)((x)->_mpfr_d))
528 +#define mpfr_custom_get_significand(x) ((mpfr_void*)((x)->_mpfr_d))
529 #define mpfr_custom_get_exp(x) ((x)->_mpfr_exp)
530 #define mpfr_custom_move(x,m) do { ((x)->_mpfr_d = (mp_limb_t*)(m)); } while (0)
531 #define mpfr_custom_init_set(x,k,e,p,m) do { \
539 _t = (mpfr_kind_t) _k; \
540 @@ -858,11 +890,13 @@ __MPFR_DECLSPEC int mpfr_custom_get_k
541 _x->_mpfr_exp = _e; \
542 _x->_mpfr_d = (mp_limb_t*) (m); \
544 -#define mpfr_custom_get_kind(x) \
545 - ( (x)->_mpfr_exp > __MPFR_EXP_INF ? (int)MPFR_REGULAR_KIND*MPFR_SIGN (x) \
546 - : (x)->_mpfr_exp == __MPFR_EXP_INF ? (int)MPFR_INF_KIND*MPFR_SIGN (x) \
547 - : (x)->_mpfr_exp == __MPFR_EXP_NAN ? (int)MPFR_NAN_KIND \
548 - : (int) MPFR_ZERO_KIND * MPFR_SIGN (x) )
549 +#define mpfr_custom_get_kind(x) \
550 + ( (x)->_mpfr_exp > __MPFR_EXP_INF ? \
551 + (mpfr_int) MPFR_REGULAR_KIND * MPFR_SIGN (x) \
552 + : (x)->_mpfr_exp == __MPFR_EXP_INF ? \
553 + (mpfr_int) MPFR_INF_KIND * MPFR_SIGN (x) \
554 + : (x)->_mpfr_exp == __MPFR_EXP_NAN ? (mpfr_int) MPFR_NAN_KIND \
555 + : (mpfr_int) MPFR_ZERO_KIND * MPFR_SIGN (x) )
558 #endif /* MPFR_USE_NO_MACRO */
559 diff -rupN mpfr-3.0.0.orig/mpfr.texi mpfr-3.0.0/mpfr.texi
560 --- mpfr-3.0.0.orig/mpfr.texi 2010-11-17 14:50:50.069041200 -0700
561 +++ mpfr-3.0.0/mpfr.texi 2010-06-23 05:03:12.000000000 -0600
562 @@ -2050,7 +2050,7 @@ first digit and a trailing exponent in b
563 are printed. If @var{base} is greater than 10, @samp{@@} will be used
564 instead of @samp{e} as exponent delimiter.
566 -Return the number of bytes written, or if an error occurred, return 0.
567 +Return the number of characters written, or if an error occurred, return 0.
570 @deftypefun size_t mpfr_inp_str (mpfr_t @var{rop}, FILE *@var{stream}, int @var{base}, mpfr_rnd_t @var{rnd})
571 diff -rupN mpfr-3.0.0.orig/out_str.c mpfr-3.0.0/out_str.c
572 --- mpfr-3.0.0.orig/out_str.c 2010-11-17 14:50:50.080041800 -0700
573 +++ mpfr-3.0.0/out_str.c 2010-06-23 05:03:12.000000000 -0600
574 @@ -22,6 +22,16 @@ http://www.gnu.org/licenses/ or write to
576 #include "mpfr-impl.h"
578 +/* Warning! S should not contain "%". */
579 +#define OUT_STR_RET(S) \
583 + r = fprintf (stream, (S)); \
584 + return r < 0 ? 0 : r; \
589 mpfr_out_str (FILE *stream, int base, size_t n_digits, mpfr_srcptr op,
591 @@ -29,6 +39,7 @@ mpfr_out_str (FILE *stream, int base, si
597 MPFR_ASSERTN (base >= 2 && base <= 62);
599 @@ -36,37 +47,16 @@ mpfr_out_str (FILE *stream, int base, si
603 - if (MPFR_IS_NAN(op))
605 - fprintf (stream, "@NaN@");
609 - if (MPFR_IS_INF(op))
611 - if (MPFR_SIGN(op) > 0)
613 - fprintf (stream, "@Inf@");
618 - fprintf (stream, "-@Inf@");
623 - if (MPFR_IS_ZERO(op))
624 + if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (op)))
626 - if (MPFR_SIGN(op) > 0)
628 - fprintf(stream, "0");
631 + if (MPFR_IS_NAN (op))
632 + OUT_STR_RET ("@NaN@");
633 + else if (MPFR_IS_INF (op))
634 + OUT_STR_RET (MPFR_IS_POS (op) ? "@Inf@" : "-@Inf@");
637 - fprintf(stream, "-0");
639 + MPFR_ASSERTD (MPFR_IS_ZERO (op));
640 + OUT_STR_RET (MPFR_IS_POS (op) ? "0" : "-0");
644 @@ -77,21 +67,31 @@ mpfr_out_str (FILE *stream, int base, si
646 l = strlen (s) + 1; /* size of allocated block returned by mpfr_get_str
647 - may be incorrect, as only an upper bound? */
649 - fputc (*s++, stream);
651 - /* outputs mantissa */
652 - fputc (*s++, stream); e--; /* leading digit */
653 - fputc ((unsigned char) MPFR_DECIMAL_POINT, stream);
654 - fputs (s, stream); /* rest of mantissa */
655 + /* outputs possible sign and significand */
656 + err = (*s == '-' && fputc (*s++, stream) == EOF)
657 + || fputc (*s++, stream) == EOF /* leading digit */
658 + || fputc ((unsigned char) MPFR_DECIMAL_POINT, stream) == EOF
659 + || fputs (s, stream) == EOF; /* trailing significand */
660 (*__gmp_free_func) (s0, l);
661 + if (MPFR_UNLIKELY (err))
664 + e--; /* due to the leading digit */
666 /* outputs exponent */
671 MPFR_ASSERTN(e >= LONG_MIN);
672 MPFR_ASSERTN(e <= LONG_MAX);
673 - l += fprintf (stream, (base <= 10 ? "e%ld" : "@%ld"), (long) e);
675 + r = fprintf (stream, (base <= 10 ? "e%ld" : "@%ld"), (long) e);
676 + if (MPFR_UNLIKELY (r < 0))
683 diff -rupN mpfr-3.0.0.orig/set_ld.c mpfr-3.0.0/set_ld.c
684 --- mpfr-3.0.0.orig/set_ld.c 2010-11-17 14:50:50.224050100 -0700
685 +++ mpfr-3.0.0/set_ld.c 2010-10-21 15:18:26.000000000 -0600
686 @@ -102,21 +102,25 @@ mpfr_set_ld (mpfr_ptr r, long double d,
688 x /= div13; /* exact */
690 + mpfr_div_2si (t, t, 8192, MPFR_RNDZ);
692 if (ABS (x) >= div12)
694 x /= div12; /* exact */
696 + mpfr_div_2si (t, t, 4096, MPFR_RNDZ);
698 if (ABS (x) >= div11)
700 x /= div11; /* exact */
702 + mpfr_div_2si (t, t, 2048, MPFR_RNDZ);
704 if (ABS (x) >= div10)
706 x /= div10; /* exact */
708 + mpfr_div_2si (t, t, 1024, MPFR_RNDZ);
710 /* warning: we may have DBL_MAX=2^1024*(1-2^(-53)) < x < 2^1024,
711 therefore we have one extra exponent reduction step */
712 @@ -124,9 +128,10 @@ mpfr_set_ld (mpfr_ptr r, long double d,
714 x /= div9; /* exact */
716 + mpfr_div_2si (t, t, 512, MPFR_RNDZ);
718 } /* Check overflow of double */
720 + else /* no overflow on double */
722 long double div9, div10, div11;
724 @@ -149,29 +154,34 @@ mpfr_set_ld (mpfr_ptr r, long double d,
726 x /= div13; /* exact */
728 + mpfr_mul_2si (t, t, 8192, MPFR_RNDZ);
730 if (ABS (x) <= div12)
732 x /= div12; /* exact */
734 + mpfr_mul_2si (t, t, 4096, MPFR_RNDZ);
736 if (ABS (x) <= div11)
738 x /= div11; /* exact */
740 + mpfr_mul_2si (t, t, 2048, MPFR_RNDZ);
742 if (ABS (x) <= div10)
744 x /= div10; /* exact */
746 + mpfr_mul_2si (t, t, 1024, MPFR_RNDZ);
750 x /= div9; /* exact */
752 + mpfr_mul_2si (t, t, 512, MPFR_RNDZ);
756 + else /* no underflow */
758 inexact = mpfr_set_d (u, (double) x, MPFR_RNDZ);
759 MPFR_ASSERTD (inexact == 0);
760 diff -rupN mpfr-3.0.0.orig/sub1.c mpfr-3.0.0/sub1.c
761 --- mpfr-3.0.0.orig/sub1.c 2010-11-17 14:50:50.254051800 -0700
762 +++ mpfr-3.0.0/sub1.c 2010-10-21 14:59:32.000000000 -0600
763 @@ -37,7 +37,9 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mp
764 mp_size_t cancel2, an, bn, cn, cn0;
765 mp_limb_t *ap, *bp, *cp;
766 mp_limb_t carry, bb, cc, borrow = 0;
767 - int inexact, shift_b, shift_c, is_exact = 1, down = 0, add_exp = 0;
768 + int inexact, shift_b, shift_c, add_exp = 0;
769 + int cmp_low = 0; /* used for rounding to nearest: 0 if low(b) = low(c),
770 + negative if low(b) < low(c), positive if low(b)>low(c) */
772 MPFR_TMP_DECL(marker);
774 @@ -196,7 +198,8 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mp
778 - printf ("shift_b=%d shift_c=%d diffexp=%lu\n", shift_b, shift_c,
779 + printf ("rnd=%s shift_b=%d shift_c=%d diffexp=%lu\n",
780 + mpfr_print_rnd_mode (rnd_mode), shift_b, shift_c,
781 (unsigned long) diff_exp);
784 @@ -307,17 +310,18 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mp
788 - is_exact = (carry == 0);
789 /* can decide except when carry = 2^(sh-1) [middle]
790 or carry = 0 [truncate, but cannot decide inexact flag] */
791 - down = (carry < (MPFR_LIMB_ONE << (sh - 1)));
792 if (carry > (MPFR_LIMB_ONE << (sh - 1)))
794 - else if ((0 < carry) && down)
795 + else if ((0 < carry) && (carry < (MPFR_LIMB_ONE << (sh - 1))))
797 inexact = -1; /* result if smaller than exact value */
800 + /* now carry = 2^(sh-1), in which case cmp_low=2,
801 + or carry = 0, in which case cmp_low=0 */
802 + cmp_low = (carry == 0) ? 0 : 2;
805 else /* directed rounding: set rnd_mode to RNDZ iff toward zero */
806 @@ -344,12 +348,32 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mp
807 cn -= (long int) an + cancel2;
810 - printf ("last %d bits from a are %lu, bn=%ld, cn=%ld\n",
811 + printf ("last sh=%d bits from a are %lu, bn=%ld, cn=%ld\n",
812 sh, (unsigned long) carry, (long) bn, (long) cn);
815 + /* for rounding to nearest, we couldn't conclude up to here in the following
817 + 1. sh = 0, then cmp_low=0: we can either truncate, subtract one ulp
818 + or add one ulp: -1 ulp < low(b)-low(c) < 1 ulp
819 + 2. sh > 0 but the low sh bits from high(b)-high(c) equal 2^(sh-1):
820 + -0.5 ulp <= -1/2^sh < low(b)-low(c)-0.5 < 1/2^sh <= 0.5 ulp
821 + we can't decide the rounding, in that case cmp_low=2:
822 + either we truncate and flag=-1, or we add one ulp and flag=1
823 + 3. the low sh>0 bits from high(b)-high(c) equal 0: we know we have to
824 + truncate but we can't decide the ternary value, here cmp_low=0:
825 + -0.5 ulp <= -1/2^sh < low(b)-low(c) < 1/2^sh <= 0.5 ulp
826 + we always truncate and inexact can be any of -1,0,1
829 + /* note: here cn might exceed cn0, in which case we consider a zero limb */
830 for (k = 0; (bn > 0) || (cn > 0); k = 1)
832 + /* if cmp_low < 0, we know low(b) - low(c) < 0
833 + if cmp_low > 0, we know low(b) - low(c) > 0
834 + (more precisely if cmp_low = 2, low(b) - low(c) = 0.5 ulp so far)
835 + if cmp_low = 0, so far low(b) - low(c) = 0 */
838 bb = (bn > 0) ? bp[--bn] : 0;
839 if ((cn > 0) && (cn-- <= cn0))
840 @@ -357,76 +381,115 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mp
844 - /* down is set when low(b) < low(c) */
847 + /* cmp_low compares low(b) and low(c) */
848 + if (cmp_low == 0) /* case 1 or 3 */
849 + cmp_low = (bb < cc) ? -2+k : (bb > cc) ? 1 : 0;
851 + /* Case 1 for k=0 splits into 7 subcases:
854 + 1c: 0 < bb - cc < half
856 + 1e: -half < bb - cc < 0
857 + 1f: bb - cc = -half
858 + 1g: bb - cc < -half
860 + Case 2 splits into 3 subcases:
865 + Case 3 splits into 3 subcases:
871 /* the case rounding to nearest with sh=0 is special since one couldn't
872 subtract above 1/2 ulp in the trailing limb of the result */
873 - if ((rnd_mode == MPFR_RNDN) && sh == 0 && k == 0)
874 + if (rnd_mode == MPFR_RNDN && sh == 0 && k == 0) /* case 1 for k=0 */
876 mp_limb_t half = MPFR_LIMB_HIGHBIT;
878 - is_exact = (bb == cc);
880 /* add one ulp if bb > cc + half
881 truncate if cc - half < bb < cc + half
882 sub one ulp if bb < cc - half
886 + if (cmp_low < 0) /* bb < cc: -1 ulp < low(b) - low(c) < 0,
887 + cases 1e, 1f and 1g */
892 + else /* since bb < cc < half, bb+half < 2*half */
894 + /* now we have bb < cc + half:
895 + we have to subtract one ulp if bb < cc,
896 + and truncate if bb > cc */
898 - else /* bb >= cc */
899 + else if (cmp_low >= 0) /* bb >= cc, cases 1a to 1d */
904 + else /* since bb >= cc >= half, bb - half >= 0 */
906 + /* now we have bb > cc - half: we have to add one ulp if bb > cc,
907 + and truncate if bb < cc */
914 - printf (" bb=%lu cc=%lu down=%d is_exact=%d\n",
915 - (unsigned long) bb, (unsigned long) cc, down, is_exact);
916 + printf ("k=%u bb=%lu cc=%lu cmp_low=%d\n", k,
917 + (unsigned long) bb, (unsigned long) cc, cmp_low);
920 + if (cmp_low < 0) /* low(b) - low(c) < 0: either truncate or subtract
923 if (rnd_mode == MPFR_RNDZ)
925 + goto sub_one_ulp; /* set inexact=-1 */
926 else if (rnd_mode != MPFR_RNDN) /* round away */
931 - else /* round to nearest: special case here since for sh=k=0
932 - bb = bb0 - MPFR_LIMB_HIGHBIT */
933 + else /* round to nearest */
935 - if (is_exact && sh == 0)
937 - /* For k=0 we can't decide exactness since it may depend
938 - from low order bits.
939 - For k=1, the first low limbs matched: low(b)-low(c)<0. */
946 - else if (down && sh == 0)
950 - inexact = (is_exact) ? 1 : -1;
951 + /* If cmp_low < 0 and bb > cc, then -0.5 ulp < low(b)-low(c) < 0,
952 + whatever the value of sh.
953 + If sh>0, then cmp_low < 0 implies that the initial neglected
954 + sh bits were 0 (otherwise cmp_low=2 initially), thus the
955 + weight of the new bits is less than 0.5 ulp too.
956 + If k > 0 (and sh=0) this means that either the first neglected
957 + limbs bb and cc were equal (thus cmp_low was 0 for k=0),
958 + or we had bb - cc = -0.5 ulp or 0.5 ulp.
959 + The last case is not possible here since we would have
960 + cmp_low > 0 which is sticky.
961 + In the first case (where we have cmp_low = -1), we truncate,
962 + whereas in the 2nd case we have cmp_low = -2 and we subtract
965 + if (bb > cc || sh > 0 || cmp_low == -1)
966 + { /* -0.5 ulp < low(b)-low(c) < 0,
967 + bb > cc corresponds to cases 1e and 1f1
968 + sh > 0 corresponds to cases 3c and 3b3
969 + cmp_low = -1 corresponds to case 1d3 (also 3b3) */
973 + else if (bb < cc) /* here sh = 0 and low(b)-low(c) < -0.5 ulp,
974 + this corresponds to cases 1g and 1f3 */
976 + /* the only case where we can't conclude is sh=0 and bb=cc,
977 + i.e., we have low(b) - low(c) = -0.5 ulp (up to now), thus
978 + we don't know if we must truncate or subtract one ulp.
979 + Note: for sh=0 we can't have low(b) - low(c) = -0.5 ulp up to
980 + now, since low(b) - low(c) > 1/2^sh */
984 + else if (cmp_low > 0) /* 0 < low(b) - low(c): either truncate or
987 if (rnd_mode == MPFR_RNDZ)
989 @@ -437,34 +500,70 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mp
991 else /* round to nearest */
998 + /* if sh=0, then bb>cc means that low(b)-low(c) > 0.5 ulp,
999 + and similarly when cmp_low=2 */
1000 + if (cmp_low == 2) /* cases 1a, 1b1, 2a and 2b1 */
1002 + /* sh > 0 and cmp_low > 0: this implies that the sh initial
1003 + neglected bits were 0, and the remaining low(b)-low(c)>0,
1004 + but its weight is less than 0.5 ulp */
1005 + else /* 0 < low(b) - low(c) < 0.5 ulp, this corresponds to
1006 + cases 3a, 1d1 and 3b1 */
1013 + else if (bb < cc) /* 0 < low(b) - low(c) < 0.5 ulp, cases 1c,
1014 + 1b3, 2b3 and 2c */
1024 + /* the only case where we can't conclude is bb=cc, i.e.,
1025 + low(b) - low(c) = 0.5 ulp (up to now), thus we don't know
1026 + if we must truncate or add one ulp. */
1029 + /* after k=0, we cannot conclude in the following cases, we split them
1030 + according to the values of bb and cc for k=1:
1031 + 1b. sh=0 and cmp_low = 1 and bb-cc = half [around 0.5 ulp]
1032 + 1b1. bb > cc: add one ulp, inex = 1
1033 + 1b2: bb = cc: cannot conclude
1034 + 1b3: bb < cc: truncate, inex = -1
1035 + 1d. sh=0 and cmp_low = 0 and bb-cc = 0 [around 0]
1036 + 1d1: bb > cc: truncate, inex = -1
1037 + 1d2: bb = cc: cannot conclude
1038 + 1d3: bb < cc: truncate, inex = +1
1039 + 1f. sh=0 and cmp_low = -1 and bb-cc = -half [around -0.5 ulp]
1040 + 1f1: bb > cc: truncate, inex = +1
1041 + 1f2: bb = cc: cannot conclude
1042 + 1f3: bb < cc: sub one ulp, inex = -1
1043 + 2b. sh > 0 and cmp_low = 2 and bb=cc [around 0.5 ulp]
1044 + 2b1. bb > cc: add one ulp, inex = 1
1045 + 2b2: bb = cc: cannot conclude
1046 + 2b3: bb < cc: truncate, inex = -1
1047 + 3b. sh > 0 and cmp_low = 0 [around 0]
1048 + 3b1. bb > cc: truncate, inex = -1
1049 + 3b2: bb = cc: cannot conclude
1050 + 3b3: bb < cc: truncate, inex = +1
1054 - if ((rnd_mode == MPFR_RNDN) && !is_exact)
1055 + if ((rnd_mode == MPFR_RNDN) && cmp_low != 0)
1057 /* even rounding rule */
1058 if ((ap[0] >> sh) & 1)
1067 - inexact = (down) ? 1 : -1;
1068 + inexact = (cmp_low > 0) ? -1 : 1;
1072 diff -rupN mpfr-3.0.0.orig/tests/Makefile.in mpfr-3.0.0/tests/Makefile.in
1073 --- mpfr-3.0.0.orig/tests/Makefile.in 2010-11-17 14:50:50.267052500 -0700
1074 +++ mpfr-3.0.0/tests/Makefile.in 2010-06-10 05:00:52.000000000 -0600
1075 @@ -960,6 +960,7 @@ am__tty_colors = \
1076 red=; grn=; lgn=; blu=; std=
1077 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
1083 diff -rupN mpfr-3.0.0.orig/tests/tcan_round.c mpfr-3.0.0/tests/tcan_round.c
1084 --- mpfr-3.0.0.orig/tests/tcan_round.c 2010-11-17 14:50:50.414058700 -0700
1085 +++ mpfr-3.0.0/tests/tcan_round.c 2010-10-21 14:28:38.000000000 -0600
1086 @@ -41,7 +41,7 @@ check_round_p (void)
1087 /* avoid mpn_random which leaks memory */
1088 for (i = 0; i < n; i++)
1089 buf[i] = randlimb ();
1090 - p = (mpfr_prec_t) randlimb() % ((n-1) * GMP_NUMB_BITS) + MPFR_PREC_MIN;
1091 + p = randlimb() % ((n-1) * GMP_NUMB_BITS) + MPFR_PREC_MIN;
1092 err = p + randlimb () % GMP_NUMB_BITS;
1093 r1 = mpfr_round_p (buf, n, err, p);
1094 r2 = mpfr_can_round_raw (buf, n, MPFR_SIGN_POS, err,
1095 diff -rupN mpfr-3.0.0.orig/tests/tcmp_ui.c mpfr-3.0.0/tests/tcmp_ui.c
1096 --- mpfr-3.0.0.orig/tests/tcmp_ui.c 2010-11-17 14:50:50.421059100 -0700
1097 +++ mpfr-3.0.0/tests/tcmp_ui.c 2010-09-07 02:45:12.000000000 -0600
1098 @@ -88,6 +88,126 @@ check_nan (void)
1102 +/* Since mpfr_cmp_ui and mpfr_cmp_si are also implemented by a macro
1103 + with __builtin_constant_p for GCC, check that side effects are
1104 + handled correctly. */
1106 +check_macros (void)
1111 + mpfr_init2 (x, 32);
1114 + mpfr_set_ui (x, 17, MPFR_RNDN);
1115 + if (mpfr_cmp_ui (x, 17) != 0)
1117 + printf ("Error 1 on mpfr_cmp_ui(x,17) in check_macros\n");
1120 + if (mpfr_cmp_ui (x, (c++, 17)) != 0)
1122 + printf ("Error 2 on mpfr_cmp_ui(x,17) in check_macros\n");
1127 + printf ("Error 3 on mpfr_cmp_ui(x,17) in check_macros\n"
1128 + "(c = %d instead of 1)\n", c);
1131 + if (mpfr_cmp_si (x, 17) != 0)
1133 + printf ("Error 1 on mpfr_cmp_si(x,17) in check_macros\n");
1136 + if (mpfr_cmp_si (x, (c++, 17)) != 0)
1138 + printf ("Error 2 on mpfr_cmp_si(x,17) in check_macros\n");
1143 + printf ("Error 3 on mpfr_cmp_si(x,17) in check_macros\n"
1144 + "(c = %d instead of 2)\n", c);
1149 + mpfr_set_ui (x, 0, MPFR_RNDN);
1150 + if (mpfr_cmp_ui (x, 0) != 0)
1152 + printf ("Error 1 on mpfr_cmp_ui(x,0) in check_macros\n");
1155 + if (mpfr_cmp_ui (x, (c++, 0)) != 0)
1157 + printf ("Error 2 on mpfr_cmp_ui(x,0) in check_macros\n");
1162 + printf ("Error 3 on mpfr_cmp_ui(x,0) in check_macros\n"
1163 + "(c = %d instead of 1)\n", c);
1166 + if (mpfr_cmp_si (x, 0) != 0)
1168 + printf ("Error 1 on mpfr_cmp_si(x,0) in check_macros\n");
1171 + if (mpfr_cmp_si (x, (c++, 0)) != 0)
1173 + printf ("Error 2 on mpfr_cmp_si(x,0) in check_macros\n");
1178 + printf ("Error 3 on mpfr_cmp_si(x,0) in check_macros\n"
1179 + "(c = %d instead of 2)\n", c);
1193 + mpfr_inits (x[0], x[1], x[2], (mpfr_ptr) 0);
1194 + mpfr_set_ui (x[0], 0, MPFR_RNDN);
1196 + if (mpfr_cmp_ui (p++, 0) != 0)
1198 + printf ("Error in mpfr_cmp_ui macro: result should be 0.\n");
1203 + printf ("Error in mpfr_cmp_ui macro: p - x[0] = %d (expecting 1)\n",
1204 + (int) (p - x[0]));
1208 + if (mpfr_cmp_si (p++, 0) != 0)
1210 + printf ("Error in mpfr_cmp_si macro: result should be 0.\n");
1215 + printf ("Error in mpfr_cmp_si macro: p - x[0] = %d (expecting 1)\n",
1216 + (int) (p - x[0]));
1219 + mpfr_clears (x[0], x[1], x[2], (mpfr_ptr) 0);
1225 @@ -216,6 +336,8 @@ main (void)
1234 diff -rupN mpfr-3.0.0.orig/tests/tfma.c mpfr-3.0.0/tests/tfma.c
1235 --- mpfr-3.0.0.orig/tests/tfma.c 2010-11-17 14:50:50.701075100 -0700
1236 +++ mpfr-3.0.0/tests/tfma.c 2010-10-21 14:59:32.000000000 -0600
1237 @@ -337,6 +337,94 @@ test_underflow2 (void)
1238 mpfr_clears (x, y, z, r, (mpfr_ptr) 0);
1244 + mpfr_t x, y, z, t, u;
1247 + mpfr_init2 (x, 64);
1248 + mpfr_init2 (y, 64);
1249 + mpfr_init2 (z, 64);
1250 + mpfr_init2 (t, 64);
1251 + mpfr_init2 (u, 64);
1253 + mpfr_set_str (x, "0xf.fffffffffffffffp-14766", 16, MPFR_RNDN);
1254 + mpfr_set_str (y, "-0xf.fffffffffffffffp+317", 16, MPFR_RNDN);
1255 + mpfr_set_str (z, "0x8.3ffffffffffe3ffp-14443", 16, MPFR_RNDN);
1256 + mpfr_set_str (t, "0x8.7ffffffffffc7ffp-14444", 16, MPFR_RNDN);
1257 + i = mpfr_fma (u, x, y, z, MPFR_RNDN);
1258 + if (mpfr_cmp (u, t) != 0)
1260 + printf ("Wrong result in bug20101018 (a)\n");
1261 + printf ("Expected ");
1262 + mpfr_out_str (stdout, 16, 0, t, MPFR_RNDN);
1263 + printf ("\nGot ");
1264 + mpfr_out_str (stdout, 16, 0, u, MPFR_RNDN);
1270 + printf ("Wrong ternary value in bug20101018 (a)\n");
1271 + printf ("Expected > 0\n");
1272 + printf ("Got %d\n", i);
1276 + mpfr_set_str (x, "-0xf.fffffffffffffffp-11420", 16, MPFR_RNDN);
1277 + mpfr_set_str (y, "0xf.fffffffffffffffp+9863", 16, MPFR_RNDN);
1278 + mpfr_set_str (z, "0x8.fffff80ffffffffp-1551", 16, MPFR_RNDN);
1279 + mpfr_set_str (t, "0x9.fffff01ffffffffp-1552", 16, MPFR_RNDN);
1280 + i = mpfr_fma (u, x, y, z, MPFR_RNDN);
1281 + if (mpfr_cmp (u, t) != 0)
1283 + printf ("Wrong result in bug20101018 (b)\n");
1284 + printf ("Expected ");
1285 + mpfr_out_str (stdout, 16, 0, t, MPFR_RNDN);
1286 + printf ("\nGot ");
1287 + mpfr_out_str (stdout, 16, 0, u, MPFR_RNDN);
1293 + printf ("Wrong ternary value in bug20101018 (b)\n");
1294 + printf ("Expected > 0\n");
1295 + printf ("Got %d\n", i);
1299 + mpfr_set_str (x, "0xf.fffffffffffffffp-2125", 16, MPFR_RNDN);
1300 + mpfr_set_str (y, "-0xf.fffffffffffffffp-6000", 16, MPFR_RNDN);
1301 + mpfr_set_str (z, "0x8p-8119", 16, MPFR_RNDN);
1302 + mpfr_set_str (t, "0x8.000000000000001p-8120", 16, MPFR_RNDN);
1303 + i = mpfr_fma (u, x, y, z, MPFR_RNDN);
1304 + if (mpfr_cmp (u, t) != 0)
1306 + printf ("Wrong result in bug20101018 (c)\n");
1307 + printf ("Expected ");
1308 + mpfr_out_str (stdout, 16, 0, t, MPFR_RNDN);
1309 + printf ("\nGot ");
1310 + mpfr_out_str (stdout, 16, 0, u, MPFR_RNDN);
1316 + printf ("Wrong ternary value in bug20101018 (c)\n");
1317 + printf ("Expected > 0\n");
1318 + printf ("Got %d\n", i);
1330 main (int argc, char *argv[])
1332 @@ -345,6 +433,8 @@ main (int argc, char *argv[])
1334 tests_start_mpfr ();
1341 diff -rupN mpfr-3.0.0.orig/tests/tgamma.c mpfr-3.0.0/tests/tgamma.c
1342 --- mpfr-3.0.0.orig/tests/tgamma.c 2010-11-17 14:50:50.706075400 -0700
1343 +++ mpfr-3.0.0/tests/tgamma.c 2010-07-09 18:11:46.000000000 -0600
1344 @@ -461,6 +461,20 @@ test20071231 (void)
1348 +/* bug found by Stathis, only occurs on 32-bit machines */
1350 +test20100709 (void)
1355 + mpfr_init2 (x, 100);
1356 + mpfr_set_str (x, "-4.6308260837372266e+07", 10, MPFR_RNDN);
1357 + inex = mpfr_gamma (x, x, MPFR_RNDN);
1358 + MPFR_ASSERTN(MPFR_IS_ZERO(x) && MPFR_IS_NEG(x) && inex > 0);
1363 main (int argc, char *argv[])
1365 @@ -471,6 +485,7 @@ main (int argc, char *argv[])
1366 test_generic (2, 100, 2);
1371 data_check ("data/gamma", mpfr_gamma, "mpfr_gamma");
1373 diff -rupN mpfr-3.0.0.orig/tests/tout_str.c mpfr-3.0.0/tests/tout_str.c
1374 --- mpfr-3.0.0.orig/tests/tout_str.c 2010-11-17 14:50:50.753078100 -0700
1375 +++ mpfr-3.0.0/tests/tout_str.c 2010-06-23 05:03:12.000000000 -0600
1376 @@ -46,22 +46,54 @@ static void
1385 - mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
1386 + n = mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
1389 + printf ("Error: mpfr_out_str (file, 10, 0, NaN, MPFR_RNDN) wrote %u "
1390 + "characters instead of 5.\n", n);
1394 mpfr_set_inf (x, 1);
1395 - mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
1396 + n = mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
1399 + printf ("Error: mpfr_out_str (file, 10, 0, +Inf, MPFR_RNDN) wrote %u "
1400 + "characters instead of 5.\n", n);
1404 mpfr_set_inf (x, -1);
1405 - mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
1406 + n = mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
1409 + printf ("Error: mpfr_out_str (file, 10, 0, -Inf, MPFR_RNDN) wrote %u "
1410 + "characters instead of 6.\n", n);
1414 mpfr_set_ui (x, 0, MPFR_RNDN);
1415 - mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
1416 + n = mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
1419 + printf ("Error: mpfr_out_str (file, 10, 0, +0, MPFR_RNDN) wrote %u "
1420 + "characters instead of 1.\n", n);
1424 mpfr_neg (x, x, MPFR_RNDN);
1425 - mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
1426 + n = mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
1429 + printf ("Error: mpfr_out_str (file, 10, 0, -0, MPFR_RNDN) wrote %u "
1430 + "characters instead of 2.\n", n);
1436 diff -rupN mpfr-3.0.0.orig/tests/tset_ld.c mpfr-3.0.0/tests/tset_ld.c
1437 --- mpfr-3.0.0.orig/tests/tset_ld.c 2010-11-17 14:50:50.773079300 -0700
1438 +++ mpfr-3.0.0/tests/tset_ld.c 2010-10-21 15:18:26.000000000 -0600
1439 @@ -147,12 +147,39 @@ static void
1440 test_fixed_bugs (void)
1446 /* bug found by Steve Kargl (2009-03-14) */
1448 mpfr_set_ui_2exp (x, 1, -16447, MPFR_RNDN);
1449 - d = mpfr_get_ld (x, MPFR_RNDN); /* an assertion failed in init2.c:50 */
1450 + mpfr_get_ld (x, MPFR_RNDN); /* an assertion failed in init2.c:50 */
1452 + /* bug reported by Jakub Jelinek (2010-10-17)
1453 + https://gforge.inria.fr/tracker/?func=detail&aid=11300 */
1454 + mpfr_set_prec (x, MPFR_LDBL_MANT_DIG);
1455 + /* l = 0x1.23456789abcdef0123456789abcdp-914L; */
1456 + l = 8.215640181713713164092636634579e-276;
1457 + mpfr_set_ld (x, l, MPFR_RNDN);
1458 + m = mpfr_get_ld (x, MPFR_RNDN);
1461 + printf ("Error in get_ld o set_ld for l=%Le\n", l);
1462 + printf ("Got m=%Le instead of l\n", m);
1466 + /* another similar test which failed with extended double precision and the
1467 + generic code for mpfr_set_ld */
1468 + /* l = 0x1.23456789abcdef0123456789abcdp-968L; */
1469 + l = 4.560596445887084662336528403703e-292;
1470 + mpfr_set_ld (x, l, MPFR_RNDN);
1471 + m = mpfr_get_ld (x, MPFR_RNDN);
1474 + printf ("Error in get_ld o set_ld for l=%Le\n", l);
1475 + printf ("Got m=%Le instead of l\n", m);
1481 diff -rupN mpfr-3.0.0.orig/tests/tsub.c mpfr-3.0.0/tests/tsub.c
1482 --- mpfr-3.0.0.orig/tests/tsub.c 2010-11-17 14:50:50.791080300 -0700
1483 +++ mpfr-3.0.0/tests/tsub.c 2010-10-21 14:59:32.000000000 -0600
1484 @@ -201,6 +201,8 @@ check_diverse (void)
1485 if (mpfr_cmp (z, x))
1487 printf ("Error in mpfr_sub (2)\n");
1488 + printf ("Expected "); mpfr_print_binary (x); puts ("");
1489 + printf ("Got "); mpfr_print_binary (z); puts ("");
1492 mpfr_set_str_binary (x, "1.1110111011110001110111011111111111101000011001011100101100101101");
1493 @@ -478,6 +480,156 @@ check_inexact (void)
1497 +/* Bug found by Jakub Jelinek
1498 + * http://bugzilla.redhat.com/643657
1499 + * https://gforge.inria.fr/tracker/index.php?func=detail&aid=11301
1500 + * The consequence can be either an assertion failure (i = 2 in the
1501 + * testcase below, in debug mode) or an incorrectly rounded value.
1510 + mpfr_init2 (a, GMP_NUMB_BITS * 2);
1511 + mpfr_init2 (b, GMP_NUMB_BITS);
1512 + mpfr_init2 (c, GMP_NUMB_BITS);
1514 + /* a = 2^(2N) + k.2^(2N-1) + 2^N and b = 1
1515 + with N = GMP_NUMB_BITS and k = 0 or 1.
1516 + c = a - b should round to the same value as a. */
1518 + for (i = 2; i <= 3; i++)
1520 + mpfr_set_ui_2exp (a, i, GMP_NUMB_BITS - 1, MPFR_RNDN);
1521 + mpfr_add_ui (a, a, 1, MPFR_RNDN);
1522 + mpfr_mul_2ui (a, a, GMP_NUMB_BITS, MPFR_RNDN);
1523 + mpfr_set_ui (b, 1, MPFR_RNDN);
1524 + inex = mpfr_sub (c, a, b, MPFR_RNDN);
1525 + mpfr_set (b, a, MPFR_RNDN);
1526 + if (! mpfr_equal_p (c, b))
1528 + printf ("Error in bug20101017 for i = %d.\n", i);
1529 + printf ("Expected ");
1530 + mpfr_out_str (stdout, 16, 0, b, MPFR_RNDN);
1533 + mpfr_out_str (stdout, 16, 0, c, MPFR_RNDN);
1539 + printf ("Error in bug20101017 for i = %d: bad inex value.\n", i);
1540 + printf ("Expected negative, got %d.\n", inex);
1545 + mpfr_set_prec (a, 64);
1546 + mpfr_set_prec (b, 129);
1547 + mpfr_set_prec (c, 2);
1548 + mpfr_set_str_binary (b, "0.100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001E65");
1549 + mpfr_set_str_binary (c, "0.10E1");
1550 + inex = mpfr_sub (a, b, c, MPFR_RNDN);
1551 + if (mpfr_cmp_ui_2exp (a, 1, 64) != 0 || inex >= 0)
1553 + printf ("Error in mpfr_sub for b-c for b=2^64+1+2^(-64), c=1\n");
1554 + printf ("Expected result 2^64 with inex < 0\n");
1555 + printf ("Got "); mpfr_print_binary (a);
1556 + printf (" with inex=%d\n", inex);
1560 + mpfr_clears (a, b, c, (mpfr_ptr) 0);
1563 +/* hard test of rounding */
1565 +check_rounding (void)
1567 + mpfr_t a, b, c, res;
1572 +#define MAXKL (2 * GMP_NUMB_BITS)
1573 + for (p = MPFR_PREC_MIN; p <= GMP_NUMB_BITS; p++)
1575 + mpfr_init2 (a, p);
1576 + mpfr_init2 (res, p);
1577 + mpfr_init2 (b, p + 1 + MAXKL);
1578 + mpfr_init2 (c, MPFR_PREC_MIN);
1580 + /* b = 2^p + 1 + 2^(-k), c = 2^(-l) */
1581 + for (k = 0; k <= MAXKL; k++)
1582 + for (l = 0; l <= MAXKL; l++)
1584 + mpfr_set_ui_2exp (b, 1, p, MPFR_RNDN);
1585 + mpfr_add_ui (b, b, 1, MPFR_RNDN);
1586 + mpfr_mul_2ui (b, b, k, MPFR_RNDN);
1587 + mpfr_add_ui (b, b, 1, MPFR_RNDN);
1588 + mpfr_div_2ui (b, b, k, MPFR_RNDN);
1589 + mpfr_set_ui_2exp (c, 1, -l, MPFR_RNDN);
1590 + i = mpfr_sub (a, b, c, MPFR_RNDN);
1591 + /* b - c = 2^p + 1 + 2^(-k) - 2^(-l), should be rounded to
1592 + 2^p for l <= k, and 2^p+2 for l < k */
1595 + if (mpfr_cmp_ui_2exp (a, 1, p) != 0)
1597 + printf ("Wrong result in check_rounding\n");
1598 + printf ("p=%lu k=%ld l=%ld\n", p, k, l);
1599 + printf ("b="); mpfr_print_binary (b); puts ("");
1600 + printf ("c="); mpfr_print_binary (c); puts ("");
1601 + printf ("Expected 2^%lu\n", p);
1602 + printf ("Got "); mpfr_print_binary (a); puts ("");
1607 + printf ("Wrong ternary value in check_rounding\n");
1608 + printf ("p=%lu k=%ld l=%ld\n", p, k, l);
1609 + printf ("b="); mpfr_print_binary (b); puts ("");
1610 + printf ("c="); mpfr_print_binary (c); puts ("");
1611 + printf ("a="); mpfr_print_binary (a); puts ("");
1612 + printf ("Expected < 0, got %d\n", i);
1618 + mpfr_set_ui_2exp (res, 1, p, MPFR_RNDN);
1619 + mpfr_add_ui (res, res, 2, MPFR_RNDN);
1620 + if (mpfr_cmp (a, res) != 0)
1622 + printf ("Wrong result in check_rounding\n");
1623 + printf ("b="); mpfr_print_binary (b); puts ("");
1624 + printf ("c="); mpfr_print_binary (c); puts ("");
1625 + printf ("Expected "); mpfr_print_binary (res); puts ("");
1626 + printf ("Got "); mpfr_print_binary (a); puts ("");
1631 + printf ("Wrong ternary value in check_rounding\n");
1632 + printf ("b="); mpfr_print_binary (b); puts ("");
1633 + printf ("c="); mpfr_print_binary (c); puts ("");
1634 + printf ("Expected > 0, got %d\n", i);
1647 #define TEST_FUNCTION test_sub
1649 #define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), randlimb () % 100, RANDS)
1650 @@ -491,6 +643,8 @@ main (void)
1652 tests_start_mpfr ();
1655 + check_rounding ();
1659 diff -rupN mpfr-3.0.0.orig/version.c mpfr-3.0.0/version.c
1660 --- mpfr-3.0.0.orig/version.c 2010-11-17 14:50:50.822082100 -0700
1661 +++ mpfr-3.0.0/version.c 2010-11-09 08:15:07.000000000 -0700
1662 @@ -25,5 +25,5 @@ http://www.gnu.org/licenses/ or write to
1664 mpfr_get_version (void)
1667 + return "3.0.0-p8";