summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/mpfr.texi4
-rw-r--r--src/compound.c12
-rw-r--r--tests/tcompound.c12
3 files changed, 15 insertions, 13 deletions
diff --git a/doc/mpfr.texi b/doc/mpfr.texi
index f87600ca0..a00435dd2 100644
--- a/doc/mpfr.texi
+++ b/doc/mpfr.texi
@@ -2268,8 +2268,8 @@ used for @code{pow}.
@deftypefun int mpfr_compound (mpfr_t @var{rop}, mpfr_t @var{op}, long int @var{n}, mpfr_rnd_t @var{rnd})
Set @var{rop} to the power @var{n} of one plus @var{op},
following IEEE@tie{}754-2019 for the special cases and exceptions.
-When @var{n} is zero and @var{op} is larger or equal @minus{}1,
-@var{rop} is set to 1 (IEEE@tie{}754-2019 also allows NaN)@.
+When @var{n} is zero and @var{op} is NaN or greater or equal to @minus{}1,
+@var{rop} is set to 1.
@end deftypefun
@deftypefun int mpfr_cos (mpfr_t @var{rop}, mpfr_t @var{op}, mpfr_rnd_t @var{rnd})
diff --git a/src/compound.c b/src/compound.c
index 55a9e9205..0e63e7cb3 100644
--- a/src/compound.c
+++ b/src/compound.c
@@ -69,15 +69,15 @@ mpfr_compound (mpfr_ptr y, mpfr_srcptr x, long n, mpfr_rnd_t rnd_mode)
/* Special cases */
if (MPFR_IS_SINGULAR (x))
{
- if (MPFR_IS_NAN (x) || (MPFR_IS_INF (x) && MPFR_SIGN (x) < 0))
+ if (n == 0 || MPFR_IS_ZERO (x))
{
- MPFR_SET_NAN (y);
- MPFR_RET_NAN;
+ /* (1+Inf)^0 = 1 and (1+x)^0 = 1, even for x = NaN */
+ return mpfr_set_ui (y, 1, rnd_mode);
}
- else if (n == 0 || MPFR_IS_ZERO (x))
+ else if (MPFR_IS_NAN (x) || (MPFR_IS_INF (x) && MPFR_SIGN (x) < 0))
{
- /* (1+Inf)^0 = 1 and (1+x)^0 = 1 */
- return mpfr_set_ui (y, 1, rnd_mode);
+ MPFR_SET_NAN (y);
+ MPFR_RET_NAN;
}
else if (MPFR_IS_INF (x)) /* x = +Inf */
{
diff --git a/tests/tcompound.c b/tests/tcompound.c
index 3ac18ceaa..7c41af0aa 100644
--- a/tests/tcompound.c
+++ b/tests/tcompound.c
@@ -55,13 +55,15 @@ check_ieee754 (void)
exit (1);
}
- /* compound(x,0) = 1 for x >= -1 or x = qNaN */
- for (i = -1; i <= 2; i++)
+ /* compound(x,0) = 1 for x >= -1 or x = NaN */
+ for (i = -2; i <= 2; i++)
{
- if (i != 2)
- mpfr_set_si (x, i, MPFR_RNDN);
- else
+ if (i == -2)
+ mpfr_set_nan (x);
+ else if (i == 2)
mpfr_set_inf (x, 1);
+ else
+ mpfr_set_si (x, i, MPFR_RNDN);
mpfr_compound (y, x, 0, MPFR_RNDN);
if (mpfr_cmp_ui (y, 1) != 0)
{