diff options
author | zimmerma <zimmerma@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2011-09-02 19:43:35 +0000 |
---|---|---|
committer | zimmerma <zimmerma@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2011-09-02 19:43:35 +0000 |
commit | 6fc0e26954b42757e47ab1304d649eae07864e6f (patch) | |
tree | 854f4bd10de75c93bab7f29b44bf270f50a8fccb | |
parent | d80a34db98de64cad2bcbf632981fb84d8591c6a (diff) | |
download | mpc-6fc0e26954b42757e47ab1304d649eae07864e6f.tar.gz |
[tests/tnorm.c] added test exposing bug in underflow case
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@1080 211d60ee-9f03-0410-a15a-8952a2c7a4e4
-rw-r--r-- | tests/tnorm.c | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/tests/tnorm.c b/tests/tnorm.c index 7cd53e6..23d76df 100644 --- a/tests/tnorm.c +++ b/tests/tnorm.c @@ -1,6 +1,6 @@ /* tnorm -- test file for mpc_norm. -Copyright (C) 2008 INRIA +Copyright (C) 2008, 2011 INRIA This file is part of GNU MPC. @@ -20,6 +20,79 @@ along with this program. If not, see http://www.gnu.org/licenses/ . #include "mpc-tests.h" +static void +test_underflow (void) +{ + mpfr_exp_t emin = mpfr_get_emin (); + mpc_t z; + mpfr_t f; + int inex; + + mpfr_set_emin (-1); /* smallest positive number is 0.5*2^emin = 0.25 */ + mpc_init2 (z, 10); + mpfr_set_ui_2exp (mpc_realref (z), 1023, -11, MPFR_RNDN); /* exact */ + mpfr_set_ui_2exp (mpc_imagref (z), 1023, -11, MPFR_RNDN); /* exact */ + mpfr_init2 (f, 10); + + inex = mpc_norm (f, z, MPFR_RNDZ); /* should give 511/1024 */ + if (inex >= 0) + { + printf ("Error in underflow case (1)\n"); + printf ("expected inex < 0, got %d\n", inex); + exit (1); + } + if (mpfr_cmp_ui_2exp (f, 511, -10) != 0) + { + printf ("Error in underflow case (1)\n"); + printf ("got "); + mpfr_dump (f); + printf ("expected "); + mpfr_set_ui_2exp (f, 511, -10, MPFR_RNDZ); + mpfr_dump (f); + exit (1); + } + + inex = mpc_norm (f, z, MPFR_RNDN); /* should give 511/1024 */ + if (inex >= 0) + { + printf ("Error in underflow case (2)\n"); + printf ("expected inex < 0, got %d\n", inex); + exit (1); + } + if (mpfr_cmp_ui_2exp (f, 511, -10) != 0) + { + printf ("Error in underflow case (2)\n"); + printf ("got "); + mpfr_dump (f); + printf ("expected "); + mpfr_set_ui_2exp (f, 511, -10, MPFR_RNDZ); + mpfr_dump (f); + exit (1); + } + + inex = mpc_norm (f, z, MPFR_RNDU); /* should give 1023/2048 */ + if (inex <= 0) + { + printf ("Error in underflow case (3)\n"); + printf ("expected inex > 0, got %d\n", inex); + exit (1); + } + if (mpfr_cmp_ui_2exp (f, 1023, -11) != 0) + { + printf ("Error in underflow case (3)\n"); + printf ("got "); + mpfr_dump (f); + printf ("expected "); + mpfr_set_ui_2exp (f, 1023, -11, MPFR_RNDZ); + mpfr_dump (f); + exit (1); + } + + mpc_clear (z); + mpfr_clear (f); + mpfr_set_emin (emin); +} + int main (void) { @@ -29,6 +102,7 @@ main (void) data_check (f, "norm.dat"); tgeneric (f, 2, 1024, 1, 4096); + test_underflow (); test_end (); |