diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2014-01-29 23:43:47 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2014-01-29 23:43:47 +0000 |
commit | 2da0783d9f5d4124e0efea3de55384408e47937d (patch) | |
tree | d8cb9dddf51685b7026529de671a5d8a4fd6c663 | |
parent | f027fb01c44b45faac26db2fd79d4920fc7ea254 (diff) | |
download | mpfr-2da0783d9f5d4124e0efea3de55384408e47937d.tar.gz |
[src] Add constants:
* __gmpfr_mone = -1
* mpfr_const_log2_RNDD = log(2) rounded down in precision 64 bits
* mpfr_const_log2_RNDU = log(2) rounded up in precision 64 bits
(modified patch from Patrick PĂ©lissier).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@8913 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | src/constant.c | 37 | ||||
-rw-r--r-- | src/eint.c | 3 | ||||
-rw-r--r-- | src/erf.c | 5 | ||||
-rw-r--r-- | src/exp.c | 5 | ||||
-rw-r--r-- | src/exp_2.c | 3 | ||||
-rw-r--r-- | src/expm1.c | 16 | ||||
-rw-r--r-- | src/mpfr-impl.h | 3 |
7 files changed, 53 insertions, 19 deletions
diff --git a/src/constant.c b/src/constant.c index 0599ef7fa..87eabf7c5 100644 --- a/src/constant.c +++ b/src/constant.c @@ -26,3 +26,40 @@ static const mp_limb_t __gmpfr_limb1[1] = {MPFR_LIMB_HIGHBIT}; const mpfr_t __gmpfr_one = {{2, MPFR_SIGN_POS, 1, (mp_limb_t*)__gmpfr_limb1}}; const mpfr_t __gmpfr_two = {{2, MPFR_SIGN_POS, 2, (mp_limb_t*)__gmpfr_limb1}}; const mpfr_t __gmpfr_four ={{2, MPFR_SIGN_POS, 3, (mp_limb_t*)__gmpfr_limb1}}; +const mpfr_t __gmpfr_mone ={{2, MPFR_SIGN_NEG, 1, (mp_limb_t*)__gmpfr_limb1}}; + +#if 0 +#elif GMP_NUMB_BITS == 16 +static const mp_limb_t mpfr_l2_dd__tab[] = { 0x79ab, 0xd1cf, 0x17f7, 0xb172 }; +#elif GMP_NUMB_BITS == 32 +static const mp_limb_t mpfr_l2_dd__tab[] = { 0xd1cf79ab, 0xb17217f7}; +#elif GMP_NUMB_BITS == 64 +static const mp_limb_t mpfr_l2_dd__tab[] = { 0xb17217f7d1cf79ab }; +#elif GMP_NUMB_BITS == 96 +static const mp_limb_t mpfr_l2_dd__tab[] = { 0xb17217f7d1cf79ab00000000 }; +#elif GMP_NUMB_BITS == 128 +static const mp_limb_t mpfr_l2_dd__tab[] = { 0xb17217f7d1cf79ab0000000000000000 }; +#elif GMP_NUMB_BITS == 256 +static const mp_limb_t mpfr_l2_dd__tab[] = { 0xb17217f7d1cf79ab000000000000000000000000000000000000000000000000 }; +#endif + +const mpfr_t __gmpfr_const_log2_RNDD = + {{64, MPFR_SIGN_POS, 0, (mp_limb_t*)mpfr_l2_dd__tab}}; + +#if 0 +#elif GMP_NUMB_BITS == 16 +static const mp_limb_t mpfr_l2_du__tab[] = { 0x79ac, 0xd1cf, 0x17f7, 0xb172 }; +#elif GMP_NUMB_BITS == 32 +static const mp_limb_t mpfr_l2_du__tab[] = { 0xd1cf79ac, 0xb17217f7}; +#elif GMP_NUMB_BITS == 64 +static const mp_limb_t mpfr_l2_du__tab[] = { 0xb17217f7d1cf79ac }; +#elif GMP_NUMB_BITS == 96 +static const mp_limb_t mpfr_l2_du__tab[] = { 0xb17217f7d1cf79ac00000000 }; +#elif GMP_NUMB_BITS == 128 +static const mp_limb_t mpfr_l2_du__tab[] = { 0xb17217f7d1cf79ac0000000000000000 }; +#elif GMP_NUMB_BITS == 256 +static const mp_limb_t mpfr_l2_du__tab[] = { 0xb17217f7d1cf79ac000000000000000000000000000000000000000000000000 }; +#endif + +const mpfr_t __gmpfr_const_log2_RNDU = + {{64, MPFR_SIGN_POS, 0, (mp_limb_t*)mpfr_l2_du__tab}}; diff --git a/src/eint.c b/src/eint.c index 9ee948e75..6da7af331 100644 --- a/src/eint.c +++ b/src/eint.c @@ -244,8 +244,7 @@ mpfr_eint (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t rnd) mpfr_init2 (ump, 64); mpfr_log (tmp, x, MPFR_RNDU); mpfr_sub (ump, x, tmp, MPFR_RNDD); - mpfr_const_log2 (tmp, MPFR_RNDU); - mpfr_div (ump, ump, tmp, MPFR_RNDD); + mpfr_div (ump, ump, __gmpfr_const_log2_RNDU, MPFR_RNDD); /* FIXME: We really need mpfr_set_exp_t and mpfr_cmpfr_exp_t functions. */ MPFR_ASSERTN (MPFR_EMAX_MAX <= LONG_MAX); if (mpfr_cmp_ui (ump, __gmpfr_emax) >= 0) @@ -110,9 +110,8 @@ mpfr_erf (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t rnd_mode) } MPFR_TMP_INIT1(xf_limb, xf, 53); - mpfr_const_log2 (xf, MPFR_RNDU); - mpfr_div (xf, x, xf, MPFR_RNDZ); /* round to zero ensures we get a lower - bound of |x/log(2)| */ + mpfr_div (xf, x, __gmpfr_const_log2_RNDU, MPFR_RNDZ); /* round to zero + ensures we get a lower bound of |x/log(2)| */ mpfr_mul (xf, xf, x, MPFR_RNDZ); large = mpfr_cmp_ui (xf, MPFR_PREC (y) + 1) > 0; @@ -86,8 +86,9 @@ mpfr_exp (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t rnd_mode) inexact = mpfr_set_exp_t (e, expo.saved_emax, MPFR_RNDN); MPFR_ASSERTD (inexact == 0); - mpfr_const_log2 (bound_emax, expo.saved_emax < 0 ? MPFR_RNDD : MPFR_RNDU); - mpfr_mul (bound_emax, bound_emax, e, MPFR_RNDU); + mpfr_mul (bound_emax, expo.saved_emax < 0 ? + __gmpfr_const_log2_RNDD : __gmpfr_const_log2_RNDU, + e, MPFR_RNDU); previous_emax = expo.saved_emax; MPFR_SAVE_EXPO_FREE (expo); } diff --git a/src/exp_2.c b/src/exp_2.c index 5dade2a9a..247f1a960 100644 --- a/src/exp_2.c +++ b/src/exp_2.c @@ -106,8 +106,7 @@ mpfr_exp_2 (mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t rnd_mode) { mp_limb_t r_limb[(sizeof (long) -1) / sizeof(mp_limb_t) + 1]; MPFR_TMP_INIT1(r_limb, r, sizeof (long) * CHAR_BIT); - mpfr_const_log2 (r, MPFR_RNDZ); - mpfr_div (r, x, r, MPFR_RNDN); + mpfr_div (r, x, __gmpfr_const_log2_RNDD, MPFR_RNDN); n = mpfr_get_si (r, MPFR_RNDN); } /* we have |x| <= (|n|+1)*log(2) */ diff --git a/src/expm1.c b/src/expm1.c index a855dfee3..e3cd64b2d 100644 --- a/src/expm1.c +++ b/src/expm1.c @@ -82,14 +82,12 @@ mpfr_expm1 (mpfr_ptr y, mpfr_srcptr x , mpfr_rnd_t rnd_mode) if (MPFR_IS_NEG (x) && ex > 5) /* x <= -32 */ { - mpfr_t minus_one, t; + mp_limb_t t_limb[(64 - 1) / GMP_NUMB_BITS + 1]; + mpfr_t t; mpfr_exp_t err; - mpfr_init2 (minus_one, 2); - mpfr_init2 (t, 64); - mpfr_set_si (minus_one, -1, MPFR_RNDN); - mpfr_const_log2 (t, MPFR_RNDU); /* round upward since x is negative */ - mpfr_div (t, x, t, MPFR_RNDU); /* > x / ln(2) */ + MPFR_TMP_INIT1(t_limb, t, 64); + mpfr_div (t, x, __gmpfr_const_log2_RNDU, MPFR_RNDU); /* > x / ln(2) */ err = mpfr_cmp_si (t, MPFR_EMIN_MIN >= -LONG_MAX ? MPFR_EMIN_MIN : -LONG_MAX) <= 0 ? - (MPFR_EMIN_MIN >= -LONG_MAX ? MPFR_EMIN_MIN : -LONG_MAX) : @@ -97,10 +95,8 @@ mpfr_expm1 (mpfr_ptr y, mpfr_srcptr x , mpfr_rnd_t rnd_mode) /* exp(x) = 2^(x/ln(2)) <= 2^max(MPFR_EMIN_MIN,-LONG_MAX,ceil(x/ln(2)+epsilon)) with epsilon > 0 */ - mpfr_clear (t); - MPFR_SMALL_INPUT_AFTER_SAVE_EXPO (y, minus_one, err, 0, 0, rnd_mode, - expo, { mpfr_clear (minus_one); }); - mpfr_clear (minus_one); + MPFR_SMALL_INPUT_AFTER_SAVE_EXPO (y, __gmpfr_mone, err, 0, 0, + rnd_mode, expo, {}); } /* General case */ diff --git a/src/mpfr-impl.h b/src/mpfr-impl.h index 77ea752f6..569bb8336 100644 --- a/src/mpfr-impl.h +++ b/src/mpfr-impl.h @@ -249,6 +249,9 @@ __MPFR_DECLSPEC extern const __mpfr_struct __gmpfr_l2b[BASE_MAX-1][2]; __MPFR_DECLSPEC extern const mpfr_t __gmpfr_one; __MPFR_DECLSPEC extern const mpfr_t __gmpfr_two; __MPFR_DECLSPEC extern const mpfr_t __gmpfr_four; +__MPFR_DECLSPEC extern const mpfr_t __gmpfr_mone; +__MPFR_DECLSPEC extern const mpfr_t __gmpfr_const_log2_RNDD; +__MPFR_DECLSPEC extern const mpfr_t __gmpfr_const_log2_RNDU; #if defined (__cplusplus) |