summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-08-25 11:31:08 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-08-25 11:31:08 +0000
commit2c28f352e6f9ebaadc8b2c67a1a7684beaa7c32f (patch)
tree23f7a9edcabcc51799d7e3c4d24011a24998bbc9
parent4bbe4ea98670fc7c1fda585ef2780d25e9b72cc7 (diff)
downloadmpfr-2c28f352e6f9ebaadc8b2c67a1a7684beaa7c32f.tar.gz
[tests/tget_sj.c] Improved check_sj and check_uj (flags testing).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@9656 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--tests/tget_sj.c52
1 files changed, 37 insertions, 15 deletions
diff --git a/tests/tget_sj.c b/tests/tget_sj.c
index 04cca6fa0..c20ea2c92 100644
--- a/tests/tget_sj.c
+++ b/tests/tget_sj.c
@@ -43,15 +43,21 @@ check_sj (intmax_t s, mpfr_ptr x)
mpfr_t y;
int i;
- mpfr_init2 (y, MPFR_PREC (x));
+ mpfr_init2 (y, MPFR_PREC (x) + 2);
for (i = -1; i <= 1; i++)
{
int rnd;
-
- mpfr_set_si_2exp (y, i, -2, MPFR_RNDN);
- mpfr_add (y, y, x, MPFR_RNDN);
- for (rnd = 0; rnd < MPFR_RND_MAX; rnd++)
+ int inex;
+ mpfr_flags_t ex_flags, flags;
+
+ inex = mpfr_set_si_2exp (y, i, -2, MPFR_RNDN);
+ MPFR_ASSERTN (inex == 0);
+ inex = mpfr_add (y, y, x, MPFR_RNDN);
+ MPFR_ASSERTN (inex == 0);
+ /* y = x + i/4, with -1 <= i <= 1 */
+ ex_flags = i != 0 ? MPFR_FLAGS_INEXACT : 0;
+ RND_LOOP (rnd)
{
intmax_t r;
@@ -64,16 +70,21 @@ check_sj (intmax_t s, mpfr_ptr x)
if (rnd == MPFR_RNDU && i > 0)
continue;
if (rnd == MPFR_RNDA && ((MPFR_IS_POS(y) && i > 0) ||
- (MPFR_IS_NEG(y) && i < 0)))
+ (MPFR_IS_NEG(y) && i < 0)))
continue;
/* rint (y) == x == s */
+ mpfr_clear_flags ();
r = mpfr_get_sj (y, (mpfr_rnd_t) rnd);
- if (r != s)
+ flags = __gmpfr_flags;
+ if (r != s || flags != ex_flags)
{
printf ("Error in check_sj for y = ");
mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN);
printf (" in %s\n", mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
- printf ("Got %jd instead of %jd.\n", r, s);
+ printf ("Expected: %jd,", s);
+ flags_out (ex_flags);
+ printf ("Got: %jd,", r);
+ flags_out (flags);
exit (1);
}
}
@@ -93,10 +104,16 @@ check_uj (uintmax_t u, mpfr_ptr x)
for (i = -1; i <= 1; i++)
{
int rnd;
-
- mpfr_set_si_2exp (y, i, -2, MPFR_RNDN);
- mpfr_add (y, y, x, MPFR_RNDN);
- for (rnd = 0; rnd < MPFR_RND_MAX; rnd++)
+ int inex;
+ mpfr_flags_t ex_flags, flags;
+
+ inex = mpfr_set_si_2exp (y, i, -2, MPFR_RNDN);
+ MPFR_ASSERTN (inex == 0);
+ inex = mpfr_add (y, y, x, MPFR_RNDN);
+ MPFR_ASSERTN (inex == 0);
+ /* y = x + i/4, with -1 <= i <= 1 */
+ ex_flags = i != 0 ? MPFR_FLAGS_INEXACT : 0;
+ RND_LOOP (rnd)
{
uintmax_t r;
@@ -107,16 +124,21 @@ check_uj (uintmax_t u, mpfr_ptr x)
if (rnd == MPFR_RNDU && i > 0)
continue;
if (rnd == MPFR_RNDA && ((MPFR_IS_POS(y) && i > 0) ||
- (MPFR_IS_NEG(y) && i < 0)))
+ (MPFR_IS_NEG(y) && i < 0)))
continue;
/* rint (y) == x == u */
+ mpfr_clear_flags ();
r = mpfr_get_uj (y, (mpfr_rnd_t) rnd);
- if (r != u)
+ flags = __gmpfr_flags;
+ if (r != u || flags != ex_flags)
{
printf ("Error in check_uj for y = ");
mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN);
printf (" in %s\n", mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
- printf ("Got %ju instead of %ju.\n", r, u);
+ printf ("Expected: %ju,", u);
+ flags_out (ex_flags);
+ printf ("Got: %ju,", r);
+ flags_out (flags);
exit (1);
}
}