diff options
author | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2003-10-28 16:31:13 +0000 |
---|---|---|
committer | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2003-10-28 16:31:13 +0000 |
commit | 117edf14c822a22cdd9c25689aeadc904a1a30d1 (patch) | |
tree | e39bd61cefc24cc6cfbc5b2b956e4fb36015d111 /pow_si.c | |
parent | 734c0a144b04e2cae4e67b394010e3f6e3cadecc (diff) | |
download | mpfr-117edf14c822a22cdd9c25689aeadc904a1a30d1.tar.gz |
Use of MPFR_UNLIKELY and MPFR_IS_SINGULAR for fast detection of special values (Nan, Inf or Zero).
Start to encapsulate the sign to be independant of the reprensation (Must be 1 or -1).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2525 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'pow_si.c')
-rw-r--r-- | pow_si.c | 67 |
1 files changed, 34 insertions, 33 deletions
@@ -34,42 +34,39 @@ MA 02111-1307, USA. */ int mpfr_pow_si (mpfr_ptr y, mpfr_srcptr x, long int n, mp_rnd_t rnd_mode) { - if (n > 0) + if (n >= 0) return mpfr_pow_ui (y, x, n, rnd_mode); else { - if (MPFR_IS_NAN(x)) - { - MPFR_SET_NAN(y); - MPFR_RET_NAN; - } - - MPFR_CLEAR_NAN(y); - - if (n == 0) - return mpfr_set_ui (y, 1, GMP_RNDN); - - if (MPFR_IS_INF(x)) - { - MPFR_SET_ZERO(y); - if (MPFR_SIGN(x) > 0 || ((unsigned) n & 1) == 0) - MPFR_SET_POS(y); - else - MPFR_SET_NEG(y); - MPFR_RET(0); - } - - if (MPFR_IS_ZERO(x)) - { - MPFR_SET_INF(y); - if (MPFR_SIGN(x) > 0 || ((unsigned) n & 1) == 0) - MPFR_SET_POS(y); - else - MPFR_SET_NEG(y); - MPFR_RET(0); - } - - MPFR_CLEAR_INF(y); + MPFR_CLEAR_FLAGS(y); + if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(x) )) + { + if (MPFR_IS_NAN(x)) + { + MPFR_SET_NAN(y); + MPFR_RET_NAN; + } + else if (MPFR_IS_INF(x)) + { + MPFR_SET_ZERO(y); + if (MPFR_IS_POS(x) || ((unsigned) n & 1) == 0) + MPFR_SET_POS(y); + else + MPFR_SET_NEG(y); + MPFR_RET(0); + } + else if (MPFR_IS_ZERO(x)) + { + MPFR_SET_INF(y); + if (MPFR_IS_POS(x) || ((unsigned) n & 1) == 0) + MPFR_SET_POS(y); + else + MPFR_SET_NEG(y); + MPFR_RET(0); + } + else + MPFR_ASSERTN(1); + } /* detect exact powers: x^(-n) is exact iff x is a power of 2 */ if (mpfr_cmp_si_2exp (x, MPFR_SIGN(x), MPFR_EXP(x) - 1) == 0) @@ -132,3 +129,7 @@ mpfr_pow_si (mpfr_ptr y, mpfr_srcptr x, long int n, mp_rnd_t rnd_mode) } } } + + + + |