summaryrefslogtreecommitdiff
path: root/tests/tsubnormal.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2007-10-23 02:35:00 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2007-10-23 02:35:00 +0000
commit292d5cabe0197711540604ccfd2fa413c3e2b994 (patch)
treece58fe7148d70f6daa199aaa15f1f34b06b566cb /tests/tsubnormal.c
parent4ebb4746ae4576006796d92b624cb85d52ff67b6 (diff)
downloadmpfr-292d5cabe0197711540604ccfd2fa413c3e2b994.tar.gz
tsubnormal.c: added some tests showing bugs when old_inex is INT_MIN
or INT_MAX. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@4907 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tsubnormal.c')
-rw-r--r--tests/tsubnormal.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/tests/tsubnormal.c b/tests/tsubnormal.c
index 023e848de..5e045bfa6 100644
--- a/tests/tsubnormal.c
+++ b/tests/tsubnormal.c
@@ -22,6 +22,7 @@ MA 02110-1301, USA. */
#include <stdio.h>
#include <stdlib.h>
+#include <limits.h>
#include "mpfr-test.h"
@@ -41,6 +42,8 @@ static const struct {
{"0.11001E-10", 0, GMP_RNDZ, "0.1E-10"},
{"0.11001E-10", 0, GMP_RNDU, "0.1E-9"},
{"0.11000E-10", 0, GMP_RNDN, "0.1E-9"},
+ {"0.11000E-10", -1, GMP_RNDN, "0.1E-9"},
+ {"0.11000E-10", 1, GMP_RNDN, "0.1E-10"},
{"0.11111E-8", 0, GMP_RNDN, "0.10E-7"},
{"0.10111E-8", 0, GMP_RNDN, "0.11E-8"},
{"0.11110E-8", -1, GMP_RNDN, "0.10E-7"},
@@ -51,7 +54,7 @@ static void
check1 (void)
{
mpfr_t x;
- int i, j;
+ int i, j, k, s, old_inex;
mpfr_set_default_prec (9);
mpfr_set_emin (-10);
@@ -59,17 +62,34 @@ check1 (void)
mpfr_init (x);
for (i = 0; i < (sizeof (tab) / sizeof (tab[0])); i++)
- {
- mpfr_set_str (x, tab[i].in, 2, GMP_RNDN);
- j = mpfr_subnormalize (x, tab[i].i, tab[i].rnd);
- if (mpfr_cmp_str (x, tab[i].out, 2, GMP_RNDN) != 0)
+ for (s = 0; s <= (tab[i].rnd == GMP_RNDN); s++)
+ for (k = 0; k <= 1; k++)
{
- printf ("Error for i=%d\nFor:%s\nExpected:%s\nGot:",
- i, tab[i].in, tab[i].out);
- mpfr_dump (x);
- exit (1);
+ mpfr_set_str (x, tab[i].in, 2, GMP_RNDN);
+ old_inex = tab[i].i;
+ if (s)
+ {
+ mpfr_neg (x, x, GMP_RNDN);
+ old_inex = - old_inex;
+ }
+ if (k && old_inex)
+ old_inex = old_inex < 0 ? INT_MIN : INT_MAX;
+ j = mpfr_subnormalize (x, old_inex, tab[i].rnd);
+ /* TODO: test j. */
+ if (s)
+ mpfr_neg (x, x, GMP_RNDN);
+ if (mpfr_cmp_str (x, tab[i].out, 2, GMP_RNDN) != 0)
+ {
+ char *sgn = s ? "-" : "";
+ printf ("Error for i = %d (old_inex = %d), k = %d, x = %s%s\n"
+ "Expected: %s%s\nGot: ", i, old_inex, k,
+ sgn, tab[i].in, sgn, tab[i].out);
+ if (s)
+ mpfr_neg (x, x, GMP_RNDN);
+ mpfr_dump (x);
+ exit (1);
+ }
}
- }
mpfr_clear (x);
}