summaryrefslogtreecommitdiff
path: root/log.c
diff options
context:
space:
mode:
authorpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2003-10-28 16:31:13 +0000
committerpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2003-10-28 16:31:13 +0000
commit117edf14c822a22cdd9c25689aeadc904a1a30d1 (patch)
treee39bd61cefc24cc6cfbc5b2b956e4fb36015d111 /log.c
parent734c0a144b04e2cae4e67b394010e3f6e3cadecc (diff)
downloadmpfr-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 'log.c')
-rw-r--r--log.c59
1 files changed, 30 insertions, 29 deletions
diff --git a/log.c b/log.c
index f92eca156..43198f937 100644
--- a/log.c
+++ b/log.c
@@ -51,50 +51,51 @@ mpfr_log (mpfr_ptr r, mpfr_srcptr a, mp_rnd_t rnd_mode)
double ref;
TMP_DECL(marker);
- /* If a is NaN, the result is NaN */
- if (MPFR_IS_NAN(a))
+ /* Special cases */
+ if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(a) ))
{
- MPFR_SET_NAN(r);
- MPFR_RET_NAN;
- }
-
- MPFR_CLEAR_NAN(r);
-
- /* check for infinity before zero */
- if (MPFR_IS_INF(a))
- {
- if (MPFR_SIGN(a) < 0) /* log(-Inf) = NaN */
+ /* If a is NaN, the result is NaN */
+ if (MPFR_IS_NAN(a))
{
MPFR_SET_NAN(r);
- MPFR_RET_NAN;
+ MPFR_RET_NAN;
}
- else /* log(+Inf) = +Inf */
+ MPFR_CLEAR_NAN(r);
+ /* check for infinity before zero */
+ if (MPFR_IS_INF(a))
+ {
+ if (MPFR_IS_NEG(a))
+ /* log(-Inf) = NaN */
+ {
+ MPFR_SET_NAN(r);
+ MPFR_RET_NAN;
+ }
+ else /* log(+Inf) = +Inf */
+ {
+ MPFR_SET_INF(r);
+ MPFR_SET_POS(r);
+ MPFR_RET(0);
+ }
+ }
+ /* Now we can clear the flags without damage even if r == a */
+ MPFR_CLEAR_INF(r);
+ if (MPFR_IS_ZERO(a))
{
MPFR_SET_INF(r);
- MPFR_SET_POS(r);
- MPFR_RET(0);
+ MPFR_SET_NEG(r);
+ MPFR_RET(0); /* log(0) is an exact -infinity */
}
}
-
- /* Now we can clear the flags without damage even if r == a */
- MPFR_CLEAR_INF(r);
-
- if (MPFR_IS_ZERO(a))
- {
- MPFR_SET_INF(r);
- MPFR_SET_NEG(r);
- MPFR_RET(0); /* log(0) is an exact -infinity */
- }
-
+
/* If a is negative, the result is NaN */
- if (MPFR_SIGN(a) < 0)
+ if (MPFR_UNLIKELY( MPFR_IS_NEG(a) ))
{
MPFR_SET_NAN(r);
MPFR_RET_NAN;
}
/* If a is 1, the result is 0 */
- if (mpfr_cmp_ui (a, 1) == 0)
+ if (MPFR_UNLIKELY( mpfr_cmp_ui (a, 1) == 0) )
{
MPFR_SET_ZERO(r);
MPFR_SET_POS(r);