From 117edf14c822a22cdd9c25689aeadc904a1a30d1 Mon Sep 17 00:00:00 2001 From: pelissip Date: Tue, 28 Oct 2003 16:31:13 +0000 Subject: 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 --- log1p.c | 77 +++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) (limited to 'log1p.c') diff --git a/log1p.c b/log1p.c index 7bd641f7a..9e831da2b 100644 --- a/log1p.c +++ b/log1p.c @@ -34,53 +34,54 @@ mpfr_log1p (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) { int comp, inexact = 0; - if (MPFR_IS_NAN(x)) + if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(x))) { - MPFR_SET_NAN(y); - MPFR_RET_NAN; - } - - MPFR_CLEAR_NAN(y); - - /* check for inf or -inf (result is not defined) */ - if (MPFR_IS_INF(x)) - { - if (MPFR_SIGN(x) > 0) - { - MPFR_SET_INF(y); - MPFR_SET_POS(y); - MPFR_RET(0); - } - else - { - MPFR_SET_NAN(y); - MPFR_RET_NAN; - } + if (MPFR_IS_NAN(x)) + { + MPFR_SET_NAN(y); + MPFR_RET_NAN; + } + MPFR_CLEAR_NAN(y); + /* check for inf or -inf (result is not defined) */ + if (MPFR_IS_INF(x)) + { + if (MPFR_IS_POS(x)) + { + MPFR_SET_INF(y); + MPFR_SET_POS(y); + MPFR_RET(0); + } + else + { + MPFR_SET_NAN(y); + MPFR_RET_NAN; + } + } + if (MPFR_IS_ZERO(x)) + { + MPFR_SET_ZERO(y); /* log1p(+/- 0) = +/- 0 */ + MPFR_SET_SAME_SIGN(y, x); + MPFR_RET(0); + } + MPFR_ASSERTN(1); } - + comp = mpfr_cmp_si(x,-1); /* x<-1 undefined */ - if (comp < 0) + if (MPFR_UNLIKELY(comp <= 0)) { + if (comp == 0) + /* x=0: log1p(-1)=-inf (division by zero) */ + { + MPFR_SET_INF(y); + MPFR_SET_POS(y); + MPFR_RET_NAN; + } MPFR_SET_NAN(y); MPFR_RET_NAN; } - /* x=0: log1p(-1)=-inf (division by zero) */ - if (comp == 0) - { - MPFR_SET_INF(y); - MPFR_SET_POS(y); - MPFR_RET_NAN; - } - MPFR_CLEAR_INF(y); - - if (MPFR_IS_ZERO(x)) - { - MPFR_SET_ZERO(y); /* log1p(+/- 0) = +/- 0 */ - MPFR_SET_SAME_SIGN(y, x); - MPFR_RET(0); - } + MPFR_CLEAR_FLAGS(y); /* General case */ { -- cgit v1.2.1