summaryrefslogtreecommitdiff
path: root/src/log.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-12-26 02:17:10 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-12-26 02:17:10 +0000
commit8528be18e1186a71aae73a3691b17a4d4e2ac327 (patch)
treee8c4a4862708b6a26f15bcaddb1ade8ccb13c276 /src/log.c
parent0cafea35711f386c00c8b443ced4371e314b2cec (diff)
downloadmpfr-8528be18e1186a71aae73a3691b17a4d4e2ac327.tar.gz
[src/log.c] Get the exponent of the input only once.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@11085 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/log.c')
-rw-r--r--src/log.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/log.c b/src/log.c
index c9fe138d7..7d177f24d 100644
--- a/src/log.c
+++ b/src/log.c
@@ -44,6 +44,7 @@ mpfr_log (mpfr_ptr r, mpfr_srcptr a, mpfr_rnd_t rnd_mode)
int inexact;
mpfr_prec_t p, q;
mpfr_t tmp1, tmp2;
+ mpfr_exp_t exp_a;
MPFR_SAVE_EXPO_DECL (expo);
MPFR_ZIV_DECL (loop);
MPFR_GROUP_DECL(group);
@@ -87,14 +88,18 @@ mpfr_log (mpfr_ptr r, mpfr_srcptr a, mpfr_rnd_t rnd_mode)
MPFR_RET (0); /* log(0) is an exact -infinity */
}
}
+
/* If a is negative, the result is NaN */
- else if (MPFR_UNLIKELY (MPFR_IS_NEG (a)))
+ if (MPFR_UNLIKELY (MPFR_IS_NEG (a)))
{
MPFR_SET_NAN (r);
MPFR_RET_NAN;
}
+
+ exp_a = MPFR_GET_EXP (a);
+
/* If a is 1, the result is +0 */
- else if (MPFR_UNLIKELY (MPFR_GET_EXP (a) == 1 && mpfr_cmp_ui (a, 1) == 0))
+ if (MPFR_UNLIKELY (exp_a == 1 && mpfr_cmp_ui (a, 1) == 0))
{
MPFR_SET_ZERO (r);
MPFR_SET_POS (r);
@@ -120,7 +125,7 @@ mpfr_log (mpfr_ptr r, mpfr_srcptr a, mpfr_rnd_t rnd_mode)
mpfr_exp_t cancel;
/* Calculus of m (depends on p) */
- m = (p + 1) / 2 - MPFR_GET_EXP (a) + 1;
+ m = (p + 1) / 2 - exp_a + 1;
mpfr_mul_2si (tmp2, a, m, MPFR_RNDN); /* s=a*2^m, err<=1 ulp */
mpfr_div (tmp1, __gmpfr_four, tmp2, MPFR_RNDN);/* 4/s, err<=2 ulps */