summaryrefslogtreecommitdiff
path: root/pow.c
diff options
context:
space:
mode:
Diffstat (limited to 'pow.c')
-rw-r--r--pow.c93
1 files changed, 40 insertions, 53 deletions
diff --git a/pow.c b/pow.c
index 472ac51c7..f0afa00ff 100644
--- a/pow.c
+++ b/pow.c
@@ -165,10 +165,8 @@ is_odd (mpfr_srcptr y)
mp_size_t yn;
mp_limb_t *yp;
- MPFR_ASSERTN(MPFR_IS_FP(y));
-
- if (MPFR_IS_ZERO(y))
- return 0;
+ /* NAN, INF or ZERO are not allowed */
+ MPFR_ASSERTD (!MPFR_IS_SINGULAR (y));
expo = MPFR_GET_EXP (y);
if (expo <= 0)
@@ -228,54 +226,48 @@ mpfr_pow (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y, mp_rnd_t rnd_mode)
if (MPFR_ARE_SINGULAR (x, y))
{
/* pow(x, 0) returns 1 for any x, even a NaN. */
- if (MPFR_UNLIKELY( MPFR_IS_ZERO(y) ))
+ if (MPFR_UNLIKELY (MPFR_IS_ZERO (y)))
return mpfr_set_ui (z, 1, GMP_RNDN);
- else if (MPFR_IS_NAN(x))
+ else if (MPFR_IS_NAN (x))
{
- MPFR_SET_NAN(z);
+ MPFR_SET_NAN (z);
MPFR_RET_NAN;
}
- else if (MPFR_IS_NAN(y))
+ else if (MPFR_IS_NAN (y))
{
/* pow(+1, NaN) returns 1. */
- if (mpfr_cmp_ui(x, 1) == 0)
+ if (mpfr_cmp_ui (x, 1) == 0)
return mpfr_set_ui (z, 1, GMP_RNDN);
- MPFR_SET_NAN(z);
+ MPFR_SET_NAN (z);
MPFR_RET_NAN;
}
- else if (MPFR_IS_INF(y))
+ else if (MPFR_IS_INF (y))
{
- if (MPFR_IS_INF(x))
+ if (MPFR_IS_INF (x))
{
- MPFR_CLEAR_FLAGS(z);
- if (MPFR_IS_POS(y))
- MPFR_SET_INF(z);
+ if (MPFR_IS_POS (y))
+ MPFR_SET_INF (z);
else
- MPFR_SET_ZERO(z);
- MPFR_SET_POS(z);
- MPFR_RET(0);
+ MPFR_SET_ZERO (z);
+ MPFR_SET_POS (z);
+ MPFR_RET (0);
}
else
{
- mpfr_t one;
int cmp;
- mpfr_init2(one, BITS_PER_MP_LIMB);
- mpfr_set_ui(one, 1, GMP_RNDN);
- cmp = mpfr_cmpabs(x, one) * MPFR_FROM_SIGN_TO_INT(MPFR_SIGN(y));
- mpfr_clear(one);
- MPFR_CLEAR_FLAGS(z);
- MPFR_SET_POS(z);
+ cmp = mpfr_cmpabs (x, __gmpfr_one) * MPFR_INT_SIGN (y);
+ MPFR_SET_POS (z);
if (cmp > 0)
{
/* Return +inf. */
- MPFR_SET_INF(z);
- MPFR_RET(0);
+ MPFR_SET_INF (z);
+ MPFR_RET (0);
}
else if (cmp < 0)
{
/* Return +0. */
- MPFR_SET_ZERO(z);
- MPFR_RET(0);
+ MPFR_SET_ZERO (z);
+ MPFR_RET (0);
}
else
{
@@ -284,43 +276,37 @@ mpfr_pow (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y, mp_rnd_t rnd_mode)
}
}
}
- MPFR_ASSERTD(MPFR_IS_FP(y));
- if (MPFR_IS_INF(x))
+ else if (MPFR_IS_INF (x))
{
int negative;
/* Determine the sign now, in case y and z are the same object */
- negative = MPFR_IS_NEG(x) && is_odd(y);
- MPFR_CLEAR_FLAGS(z);
- if (MPFR_IS_POS(y))
- MPFR_SET_INF(z);
+ negative = MPFR_IS_NEG (x) && is_odd (y);
+ if (MPFR_IS_POS (y))
+ MPFR_SET_INF (z);
else
- MPFR_SET_ZERO(z);
+ MPFR_SET_ZERO (z);
if (negative)
- MPFR_SET_NEG(z);
+ MPFR_SET_NEG (z);
else
- MPFR_SET_POS(z);
- MPFR_RET(0);
+ MPFR_SET_POS (z);
+ MPFR_RET (0);
}
- MPFR_ASSERTD(MPFR_IS_FP(x));
- if (MPFR_IS_ZERO(x))
+ else
{
int negative;
+ MPFR_ASSERTD (MPFR_IS_ZERO (x));
/* Determine the sign now, in case y and z are the same object */
negative = MPFR_IS_NEG(x) && is_odd (y);
- MPFR_CLEAR_FLAGS(z);
- if (MPFR_IS_NEG(y))
- MPFR_SET_INF(z);
+ if (MPFR_IS_NEG (y))
+ MPFR_SET_INF (z);
else
- MPFR_SET_ZERO(z);
+ MPFR_SET_ZERO (z);
if (negative)
- MPFR_SET_NEG(z);
+ MPFR_SET_NEG (z);
else
- MPFR_SET_POS(z);
- MPFR_RET(0);
+ MPFR_SET_POS (z);
+ MPFR_RET (0);
}
- /* Should never reach this code */
- MPFR_ASSERTN(0);
- return 0;
}
if (mpfr_cmp_ui (x, 1) == 0) /* 1^y is always 1 */
@@ -355,9 +341,10 @@ mpfr_pow (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y, mp_rnd_t rnd_mode)
return inexact;
}
- if (MPFR_IS_NEG(x))
+ /* x^y for x<0 and y not an integer is not defined */
+ if (MPFR_IS_NEG (x))
{
- MPFR_SET_NAN(z);
+ MPFR_SET_NAN (z);
MPFR_RET_NAN;
}