summaryrefslogtreecommitdiff
path: root/tests/tgamma.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2012-05-04 14:09:23 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2012-05-04 14:09:23 +0000
commite176f80639c4e322161974cae27a92d3f6a2c934 (patch)
tree412f257d99aa498e7cc9e525de04384271b29ce7 /tests/tgamma.c
parent72afc59300a4ab325513c6e9e14b40127b1c503d (diff)
downloadmpfr-e176f80639c4e322161974cae27a92d3f6a2c934.tar.gz
[tests/tgamma.c] Updated exp_lgamma to test underflow & overflow flags.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@8191 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tgamma.c')
-rw-r--r--tests/tgamma.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/tests/tgamma.c b/tests/tgamma.c
index 63c8eab95..826dd0dd9 100644
--- a/tests/tgamma.c
+++ b/tests/tgamma.c
@@ -882,6 +882,8 @@ exp_lgamma (mpfr_t x, mpfr_prec_t p1, mpfr_prec_t p2)
{
mpfr_t yd, yu, z;
int inex, sign;
+ int underflow = -1, overflow = -1; /* -1: we don't know */
+ int got_underflow, got_overflow;
if (mpfr_integer_p (x) && mpfr_cmp_si (x, 2) <= 0)
{
@@ -894,8 +896,18 @@ exp_lgamma (mpfr_t x, mpfr_prec_t p1, mpfr_prec_t p2)
mpfr_set (yu, yd, MPFR_RNDN); /* exact */
if (inex)
mpfr_nextabove (yu);
+ mpfr_clear_flags ();
mpfr_exp (yd, yd, MPFR_RNDD);
+ if (! mpfr_underflow_p ())
+ underflow = 0;
+ if (mpfr_overflow_p ())
+ overflow = 1;
+ mpfr_clear_flags ();
mpfr_exp (yu, yu, MPFR_RNDU);
+ if (mpfr_underflow_p ())
+ underflow = 1;
+ if (! mpfr_overflow_p ())
+ overflow = 0;
if (sign < 0)
{
mpfr_neg (yd, yd, MPFR_RNDN); /* exact */
@@ -904,8 +916,13 @@ exp_lgamma (mpfr_t x, mpfr_prec_t p1, mpfr_prec_t p2)
}
/* yd < Gamma(x) < yu (strict inequalities since x != 1 and x != 2) */
mpfr_init2 (z, p1);
+ mpfr_clear_flags ();
mpfr_gamma (z, x, MPFR_RNDD); /* z <= Gamma(x) < yu */
- if (! mpfr_less_p (z, yu))
+ got_underflow = underflow == -1 ? -1 : !! mpfr_underflow_p ();
+ got_overflow = overflow == -1 ? -1 : !! mpfr_overflow_p ();
+ if (! mpfr_less_p (z, yu) ||
+ got_underflow != underflow ||
+ got_overflow != overflow)
{
printf ("Error in exp_lgamma on x = ");
mpfr_out_str (stdout, 16, 0, x, MPFR_RNDN); putchar ('\n');
@@ -913,10 +930,17 @@ exp_lgamma (mpfr_t x, mpfr_prec_t p1, mpfr_prec_t p2)
mpfr_dump (yu);
printf ("z = ");
mpfr_dump (z);
+ printf ("got underflow = %d, expected %d\n", got_underflow, underflow);
+ printf ("got overflow = %d, expected %d\n", got_overflow, overflow);
exit (1);
}
+ mpfr_clear_flags ();
mpfr_gamma (z, x, MPFR_RNDU); /* z >= Gamma(x) > yd */
- if (! mpfr_greater_p (z, yd))
+ got_underflow = underflow == -1 ? -1 : !! mpfr_underflow_p ();
+ got_overflow = overflow == -1 ? -1 : !! mpfr_overflow_p ();
+ if (! mpfr_greater_p (z, yd) ||
+ got_underflow != underflow ||
+ got_overflow != overflow)
{
printf ("Error in exp_lgamma on x = ");
mpfr_out_str (stdout, 16, 0, x, MPFR_RNDN); putchar ('\n');
@@ -924,6 +948,8 @@ exp_lgamma (mpfr_t x, mpfr_prec_t p1, mpfr_prec_t p2)
mpfr_dump (yd);
printf ("z = ");
mpfr_dump (z);
+ printf ("got underflow = %d, expected %d\n", got_underflow, underflow);
+ printf ("got overflow = %d, expected %d\n", got_overflow, overflow);
exit (1);
}
mpfr_clears (yd, yu, z, (mpfr_ptr) 0);