summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2012-04-27 01:08:44 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2012-04-27 01:08:44 +0000
commit38426dfca9ab081a061d54277f076748c19d3d7f (patch)
tree3f0b77241999ce841b369e65ede247d2a9b2f812
parent6f21e77d0896b0e233db6c5bd6f590b658ecd5d0 (diff)
downloadmpfr-38426dfca9ab081a061d54277f076748c19d3d7f.tar.gz
[src/gamma.c] Fixed bug in the underflow detection code of mpfr_gamma,
found by Giridhar Tammana: some results may incorrectly be regarded as underflow. [tests/tgamma.c] Added testcase. (merged changeset r8159 from the trunk) git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/3.1@8160 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--src/gamma.c2
-rw-r--r--tests/tgamma.c31
2 files changed, 32 insertions, 1 deletions
diff --git a/src/gamma.c b/src/gamma.c
index cd60041f0..a346f8b1b 100644
--- a/src/gamma.c
+++ b/src/gamma.c
@@ -296,7 +296,7 @@ mpfr_gamma (mpfr_ptr gamma, mpfr_srcptr x, mpfr_rnd_t rnd_mode)
/* we want an upper bound for x * [log(2-x)-1].
since x < 0, we need a lower bound on log(2-x) */
mpfr_ui_sub (xp, 2, x, MPFR_RNDD);
- mpfr_log2 (xp, xp, MPFR_RNDD);
+ mpfr_log (xp, xp, MPFR_RNDD);
mpfr_sub_ui (xp, xp, 1, MPFR_RNDD);
mpfr_mul (xp, xp, x, MPFR_RNDU);
diff --git a/tests/tgamma.c b/tests/tgamma.c
index 9100c7c45..62fec4b63 100644
--- a/tests/tgamma.c
+++ b/tests/tgamma.c
@@ -478,6 +478,36 @@ test20100709 (void)
mpfr_clear (x);
}
+/* bug found by Giridhar Tammana */
+static void
+test20120426 (void)
+{
+ mpfr_t xa, xb;
+ int i;
+ mpfr_exp_t emin;
+
+ mpfr_init2 (xa, 53);
+ mpfr_init2 (xb, 53);
+ mpfr_set_d (xb, -168.5, MPFR_RNDN);
+ emin = mpfr_get_emin ();
+ mpfr_set_emin (-1073);
+ i = mpfr_gamma (xa, xb, MPFR_RNDN);
+ i = mpfr_subnormalize (xa, i, MPFR_RNDN); /* new ternary value */
+ mpfr_set_str (xb, "-9.5737343987585366746184749943e-304", 10, MPFR_RNDN);
+ if (!((i > 0) && (mpfr_cmp (xa, xb) == 0)))
+ {
+ printf ("Error in test20120426, i=%d\n", i);
+ printf ("expected ");
+ mpfr_print_binary (xb); putchar ('\n');
+ printf ("got ");
+ mpfr_print_binary (xa); putchar ('\n');
+ exit (1);
+ }
+ mpfr_set_emin (emin);
+ mpfr_clear (xa);
+ mpfr_clear (xb);
+}
+
static void
exprange (void)
{
@@ -821,6 +851,7 @@ main (int argc, char *argv[])
gamma_integer ();
test20071231 ();
test20100709 ();
+ test20120426 ();
data_check ("data/gamma", mpfr_gamma, "mpfr_gamma");