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 /erf.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 'erf.c')
-rw-r--r-- | erf.c | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -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; |