summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2005-03-04 17:40:53 +0000
committerpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2005-03-04 17:40:53 +0000
commitca8aadf5c9ea5351151e8c7425d27388a4d7e5dc (patch)
treefba0ba2ff07c59bd6de66f18c8f53200eb1f32ee
parent7c2a4276339fe8771cc879c9aa31139b90e6c3e1 (diff)
downloadmpfr-ca8aadf5c9ea5351151e8c7425d27388a4d7e5dc.tar.gz
Fix bug due to wrong estimation of (get_d (x) / LOG2).
TODO: Rexamine the algorithm of mpfr_exp_2! git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@3362 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--exp_2.c2
-rw-r--r--tests/texp.c15
2 files changed, 16 insertions, 1 deletions
diff --git a/exp_2.c b/exp_2.c
index e9175d16b..f1cf47495 100644
--- a/exp_2.c
+++ b/exp_2.c
@@ -144,7 +144,7 @@ mpfr_exp_2 (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode)
mpfr_sub (r, x, r, GMP_RNDU);
/* possible cancellation here: the error on r is at most
3*2^(EXP(old_r)-EXP(new_r)) */
- if (MPFR_IS_NEG (r))
+ while (MPFR_IS_NEG (r))
{ /* initial approximation n was too large */
n--;
mpfr_add (r, r, s, GMP_RNDU);
diff --git a/tests/texp.c b/tests/texp.c
index a7140792d..3057652f8 100644
--- a/tests/texp.c
+++ b/tests/texp.c
@@ -345,6 +345,21 @@ check_special ()
mpfr_mul_2ui (x, x, 32, GMP_RNDN);
test_exp (y, x, GMP_RNDN); /* Can't test return value: May overflow or not*/
+ /* Bug due to wrong approximation of (x)/log2 */
+ mpfr_set_prec (x, 163);
+
+ mpfr_set_str (x, "-4.28ac8fceeadcda06bb56359017b1c81b85b392e7", 16,
+ GMP_RNDN);
+ mpfr_exp (x, x, GMP_RNDN);
+ if (mpfr_cmp_str (x, "3.fffffffffffffffffffffffffffffffffffffffe8@-2",
+ 16, GMP_RNDN))
+ {
+ printf ("Error for x= -4.28ac8fceeadcda06bb56359017b1c81b85b392e7");
+ printf ("expected 3.fffffffffffffffffffffffffffffffffffffffe8@-2");
+ printf ("Got ");
+ mpfr_out_str (stdout, 16, 0, x, GMP_RNDN); putchar ('\n');
+ }
+
mpfr_clear (x);
mpfr_clear (y);
mpfr_clear (z);