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 --- erf.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'erf.c') diff --git a/erf.c b/erf.c index 8499ab260..7f835e3fa 100644 --- a/erf.c +++ b/erf.c @@ -44,26 +44,27 @@ mpfr_erf (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) double n = (double) MPFR_PREC(y); int inex; - if (MPFR_IS_NAN(x)) + sign_x = MPFR_SIGN (x); + if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(x) )) { - MPFR_SET_NAN(y); - MPFR_RET_NAN; + if (MPFR_IS_NAN(x)) + { + MPFR_SET_NAN(y); + MPFR_RET_NAN; + } + if (MPFR_IS_INF(x)) /* erf(+inf) = +1, erf(-inf) = -1 */ + return mpfr_set_si (y, MPFR_FROM_SIGN_TO_INT(sign_x), GMP_RNDN); + if (MPFR_IS_ZERO(x)) /* erf(+0) = +0, erf(-0) = -0 */ + return mpfr_set (y, x, GMP_RNDN); /* should keep the sign of x */ + MPFR_ASSERTN(1); } - sign_x = MPFR_SIGN (x); - - if (MPFR_IS_INF(x)) /* erf(+inf) = +1, erf(-inf) = -1 */ - return mpfr_set_si (y, sign_x, GMP_RNDN); - - if (MPFR_IS_ZERO(x)) /* erf(+0) = +0, erf(-0) = -0 */ - return mpfr_set (y, x, GMP_RNDN); /* should keep the sign of x */ - /* now x is neither NaN, Inf nor 0 */ xf = mpfr_get_d (x, GMP_RNDN); xf = xf * xf; /* xf ~ x^2 */ - if (sign_x > 0) + if (MPFR_IS_POS_SIGN(sign_x)) rnd2 = rnd_mode; else { @@ -96,7 +97,7 @@ mpfr_erf (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) inex = mpfr_erf_0 (y, x, rnd2); } - if (sign_x < 0) + if (MPFR_IS_NEG_SIGN(sign_x)) { MPFR_CHANGE_SIGN (y); return - inex; -- cgit v1.2.1