diff options
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | doc/mpfr.texi | 15 | ||||
-rw-r--r-- | src/get_str.c | 1 | ||||
-rw-r--r-- | tests/tget_str.c | 8 |
4 files changed, 25 insertions, 4 deletions
@@ -49,8 +49,9 @@ Changes from versions 3.1.* to version 3.2.0: - Speedup in the mpfr_const_euler function (contributed by Fredrik Johansson), in the computation of Bernoulli numbers (used in mpfr_gamma, mpfr_li2, mpfr_digamma, mpfr_lngamma and mpfr_lgamma), and in mpfr_div. -- Bug fixes. In particular, a speed improvement when the --enable-assert - or --enable-assert=full configure option is used with GCC. +- Bug fixes. In particular: a speed improvement when the --enable-assert + or --enable-assert=full configure option is used with GCC; mpfr_get_str + now sets the NaN flag on NaN input. Changes from versions 3.0.* to version 3.1.0: - The "canard à l'orange" release. diff --git a/doc/mpfr.texi b/doc/mpfr.texi index fb39599c9..2326a693b 100644 --- a/doc/mpfr.texi +++ b/doc/mpfr.texi @@ -1484,7 +1484,12 @@ the direction @var{rnd}, where @var{n} is either zero (see below) or the number of significant digits output in the string; in the latter case, @var{n} must be greater or equal to 2. The base may vary from 2 to 62; otherwise the function does nothing and immediately returns a null pointer. -If the input number is an ordinary number, the exponent is written through + +If the input is NaN, then the returned string is @code{@@NaN@@} and the +NaN flag is set. If the input is +Inf (resp.@: @minus{}Inf), then the +returned string is @code{@@Inf@@} (resp.@: @code{-@@Inf@@}). + +If the input number is a finite number, the exponent is written through the pointer @var{expptr} (for input 0, the current minimal exponent is written); the type @code{mpfr_exp_t} is large enough to hold the exponent in all cases. @@ -1532,6 +1537,9 @@ The extra two bytes are for a possible minus sign, and for the terminating null character, and the value 7 accounts for @code{-@@Inf@@} plus the terminating null character. The pointer to the string @var{str} is returned (unless the base is invalid). + +Note: The inexact flag is currently not set when the conversion is inexact; +this is regarded as a bug. @end deftypefun @deftypefun void mpfr_free_str (char *@var{str}) @@ -3610,6 +3618,11 @@ and @code{mpfr_get_uj} changed in MPFR 3.0. In previous MPFR versions, the cases where the @emph{erange} flag is set were unspecified. +@item @code{mpfr_get_str} changed in MPFR 3.2. +This function now sets the NaN flag on NaN input (to follow the usual MPFR +rules on NaN and IEEE 754-2008 recommendations on string conversions from +Subclause 5.12.1). The previous behavior was regarded as a bug. + @item @code{mpfr_get_z} changed in MPFR 3.0. The return type was @code{void}; it is now @code{int}, and the usual ternary value is returned. Thus programs that need to work with both diff --git a/src/get_str.c b/src/get_str.c index 14958db02..b9665480b 100644 --- a/src/get_str.c +++ b/src/get_str.c @@ -2276,6 +2276,7 @@ mpfr_get_str (char *s, mpfr_exp_t *e, int b, size_t m, mpfr_srcptr x, if (s == NULL) s = (char *) (*__gmp_allocate_func) (6); strcpy (s, "@NaN@"); + __gmpfr_flags |= MPFR_FLAGS_NAN; return s; } diff --git a/tests/tget_str.c b/tests/tget_str.c index c3c4f0724..97d69320c 100644 --- a/tests/tget_str.c +++ b/tests/tget_str.c @@ -1012,10 +1012,16 @@ check_large (void) mpfr_free_str (s); mpfr_set_nan (x); + mpfr_clear_flags (); s = mpfr_get_str (NULL, &e, 10, 1000, x, MPFR_RNDN); if (strcmp (s, "@NaN@")) { - printf ("Error for NaN\n"); + printf ("Error for NaN (incorrect string)\n"); + exit (1); + } + if (__gmpfr_flags != MPFR_FLAGS_NAN) + { + printf ("Error for NaN (incorrect flags)\n"); exit (1); } mpfr_free_str (s); |