diff -Naurd mpfr-3.0.0-a/PATCHES mpfr-3.0.0-b/PATCHES --- mpfr-3.0.0-a/PATCHES 2010-06-23 11:02:49.000000000 +0000 +++ mpfr-3.0.0-b/PATCHES 2010-06-23 11:03:36.000000000 +0000 @@ -0,0 +1 @@ +mpfr_out_str diff -Naurd mpfr-3.0.0-a/VERSION mpfr-3.0.0-b/VERSION --- mpfr-3.0.0-a/VERSION 2010-06-10 11:00:14.000000000 +0000 +++ mpfr-3.0.0-b/VERSION 2010-06-23 11:03:20.000000000 +0000 @@ -1 +1 @@ -3.0.0 +3.0.0-p1 diff -Naurd mpfr-3.0.0-a/mpfr.h mpfr-3.0.0-b/mpfr.h --- mpfr-3.0.0-a/mpfr.h 2010-06-10 11:00:14.000000000 +0000 +++ mpfr-3.0.0-b/mpfr.h 2010-06-23 11:03:20.000000000 +0000 @@ -27,7 +27,7 @@ #define MPFR_VERSION_MAJOR 3 #define MPFR_VERSION_MINOR 0 #define MPFR_VERSION_PATCHLEVEL 0 -#define MPFR_VERSION_STRING "3.0.0" +#define MPFR_VERSION_STRING "3.0.0-p1" /* Macros dealing with MPFR VERSION */ #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c)) diff -Naurd mpfr-3.0.0-a/mpfr.texi mpfr-3.0.0-b/mpfr.texi --- mpfr-3.0.0-a/mpfr.texi 2010-06-10 11:00:14.000000000 +0000 +++ mpfr-3.0.0-b/mpfr.texi 2010-06-23 11:03:12.000000000 +0000 @@ -2050,7 +2050,7 @@ are printed. If @var{base} is greater than 10, @samp{@@} will be used instead of @samp{e} as exponent delimiter. -Return the number of bytes written, or if an error occurred, return 0. +Return the number of characters written, or if an error occurred, return 0. @end deftypefun @deftypefun size_t mpfr_inp_str (mpfr_t @var{rop}, FILE *@var{stream}, int @var{base}, mpfr_rnd_t @var{rnd}) diff -Naurd mpfr-3.0.0-a/out_str.c mpfr-3.0.0-b/out_str.c --- mpfr-3.0.0-a/out_str.c 2010-06-10 11:00:14.000000000 +0000 +++ mpfr-3.0.0-b/out_str.c 2010-06-23 11:03:12.000000000 +0000 @@ -22,6 +22,16 @@ #include "mpfr-impl.h" +/* Warning! S should not contain "%". */ +#define OUT_STR_RET(S) \ + do \ + { \ + int r; \ + r = fprintf (stream, (S)); \ + return r < 0 ? 0 : r; \ + } \ + while (0) + size_t mpfr_out_str (FILE *stream, int base, size_t n_digits, mpfr_srcptr op, mpfr_rnd_t rnd_mode) @@ -29,6 +39,7 @@ char *s, *s0; size_t l; mpfr_exp_t e; + int err; MPFR_ASSERTN (base >= 2 && base <= 62); @@ -36,37 +47,16 @@ if (stream == NULL) stream = stdout; - if (MPFR_IS_NAN(op)) - { - fprintf (stream, "@NaN@"); - return 3; - } - - if (MPFR_IS_INF(op)) - { - if (MPFR_SIGN(op) > 0) - { - fprintf (stream, "@Inf@"); - return 3; - } - else - { - fprintf (stream, "-@Inf@"); - return 4; - } - } - - if (MPFR_IS_ZERO(op)) + if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (op))) { - if (MPFR_SIGN(op) > 0) - { - fprintf(stream, "0"); - return 1; - } + if (MPFR_IS_NAN (op)) + OUT_STR_RET ("@NaN@"); + else if (MPFR_IS_INF (op)) + OUT_STR_RET (MPFR_IS_POS (op) ? "@Inf@" : "-@Inf@"); else { - fprintf(stream, "-0"); - return 2; + MPFR_ASSERTD (MPFR_IS_ZERO (op)); + OUT_STR_RET (MPFR_IS_POS (op) ? "0" : "-0"); } } @@ -77,21 +67,31 @@ l = strlen (s) + 1; /* size of allocated block returned by mpfr_get_str - may be incorrect, as only an upper bound? */ - if (*s == '-') - fputc (*s++, stream); - /* outputs mantissa */ - fputc (*s++, stream); e--; /* leading digit */ - fputc ((unsigned char) MPFR_DECIMAL_POINT, stream); - fputs (s, stream); /* rest of mantissa */ + /* outputs possible sign and significand */ + err = (*s == '-' && fputc (*s++, stream) == EOF) + || fputc (*s++, stream) == EOF /* leading digit */ + || fputc ((unsigned char) MPFR_DECIMAL_POINT, stream) == EOF + || fputs (s, stream) == EOF; /* trailing significand */ (*__gmp_free_func) (s0, l); + if (MPFR_UNLIKELY (err)) + return 0; + + e--; /* due to the leading digit */ /* outputs exponent */ if (e) { + int r; + MPFR_ASSERTN(e >= LONG_MIN); MPFR_ASSERTN(e <= LONG_MAX); - l += fprintf (stream, (base <= 10 ? "e%ld" : "@%ld"), (long) e); + + r = fprintf (stream, (base <= 10 ? "e%ld" : "@%ld"), (long) e); + if (MPFR_UNLIKELY (r < 0)) + return 0; + + l += r; } return l; diff -Naurd mpfr-3.0.0-a/tests/tout_str.c mpfr-3.0.0-b/tests/tout_str.c --- mpfr-3.0.0-a/tests/tout_str.c 2010-06-10 11:00:13.000000000 +0000 +++ mpfr-3.0.0-b/tests/tout_str.c 2010-06-23 11:03:12.000000000 +0000 @@ -46,22 +46,54 @@ special (void) { mpfr_t x; + unsigned int n; mpfr_init (x); mpfr_set_nan (x); - mpfr_out_str (fout, 10, 0, x, MPFR_RNDN); + n = mpfr_out_str (fout, 10, 0, x, MPFR_RNDN); + if (n != 5) + { + printf ("Error: mpfr_out_str (file, 10, 0, NaN, MPFR_RNDN) wrote %u " + "characters instead of 5.\n", n); + exit (1); + } mpfr_set_inf (x, 1); - mpfr_out_str (fout, 10, 0, x, MPFR_RNDN); + n = mpfr_out_str (fout, 10, 0, x, MPFR_RNDN); + if (n != 5) + { + printf ("Error: mpfr_out_str (file, 10, 0, +Inf, MPFR_RNDN) wrote %u " + "characters instead of 5.\n", n); + exit (1); + } mpfr_set_inf (x, -1); - mpfr_out_str (fout, 10, 0, x, MPFR_RNDN); + n = mpfr_out_str (fout, 10, 0, x, MPFR_RNDN); + if (n != 6) + { + printf ("Error: mpfr_out_str (file, 10, 0, -Inf, MPFR_RNDN) wrote %u " + "characters instead of 6.\n", n); + exit (1); + } mpfr_set_ui (x, 0, MPFR_RNDN); - mpfr_out_str (fout, 10, 0, x, MPFR_RNDN); + n = mpfr_out_str (fout, 10, 0, x, MPFR_RNDN); + if (n != 1) + { + printf ("Error: mpfr_out_str (file, 10, 0, +0, MPFR_RNDN) wrote %u " + "characters instead of 1.\n", n); + exit (1); + } + mpfr_neg (x, x, MPFR_RNDN); - mpfr_out_str (fout, 10, 0, x, MPFR_RNDN); + n = mpfr_out_str (fout, 10, 0, x, MPFR_RNDN); + if (n != 2) + { + printf ("Error: mpfr_out_str (file, 10, 0, -0, MPFR_RNDN) wrote %u " + "characters instead of 2.\n", n); + exit (1); + } mpfr_clear (x); } diff -Naurd mpfr-3.0.0-a/version.c mpfr-3.0.0-b/version.c --- mpfr-3.0.0-a/version.c 2010-06-10 11:00:14.000000000 +0000 +++ mpfr-3.0.0-b/version.c 2010-06-23 11:03:20.000000000 +0000 @@ -25,5 +25,5 @@ const char * mpfr_get_version (void) { - return "3.0.0"; + return "3.0.0-p1"; }