diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2009-09-18 10:23:07 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2009-09-18 10:23:07 +0000 |
commit | 60302d4f8f0330f94310e898f62f78cf114da1b6 (patch) | |
tree | 358150a42da04c8a758ba5827efa16d79bcedf02 /tests/tmodf.c | |
parent | 148c024ee94f05e5099e11afb147bfab17ae796e (diff) | |
download | mpfr-60302d4f8f0330f94310e898f62f78cf114da1b6.tar.gz |
tests/tmodf.c: added overflow tests.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@6449 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tmodf.c')
-rw-r--r-- | tests/tmodf.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/tmodf.c b/tests/tmodf.c index 1311aeea3..21ca26604 100644 --- a/tests/tmodf.c +++ b/tests/tmodf.c @@ -102,6 +102,94 @@ check_nans (void) mpfr_clear (xf); } +static void +check_special_exprange (void) +{ + int inexact, ov; + unsigned int eflags, gflags; + mpfr_t xi, xf, x; + mp_exp_t emax; + + emax = mpfr_get_emax (); + mpfr_init2 (xi, 7); + mpfr_init2 (xf, 7); + mpfr_init2 (x, 8); + + mpfr_set_str (x, "0.11111111", 2, MPFR_RNDN); + for (ov = 0; ov <= 1; ov++) + { + char *s = ov ? "@Inf@" : "1"; + + if (ov) + set_emax (0); + mpfr_clear_flags (); + inexact = mpfr_modf (xi, xf, x, MPFR_RNDN); + gflags = __gmpfr_flags; + set_emax (emax); + if (MPFR_NOTZERO (xi) || MPFR_IS_NEG (xi) || + mpfr_cmp_str1 (xf, s) != 0) + { + printf ("Error in check_special_exprange (ov = %d):" + " expected 0 and %s, got\n", ov, s); + mpfr_out_str (stdout, 2, 0, xi, MPFR_RNDN); + printf (" and "); + mpfr_out_str (stdout, 2, 0, xf, MPFR_RNDN); + printf ("\n"); + exit (1); + } + if (inexact != 4) + { + printf ("Bad inexact value in check_special_exprange (ov = %d):" + " expected 4, got %d\n", ov, inexact); + exit (1); + } + eflags = MPFR_FLAGS_INEXACT | (ov ? MPFR_FLAGS_OVERFLOW : 0); + if (gflags != eflags) + { + printf ("Bad flags in check_special_exprange (ov = %d):" + " expected %u, got %u\n", ov, eflags, gflags); + exit (1); + } + } + + /* Test if an overflow occurs in mpfr_set for ope >= opq. */ + mpfr_set_emax (MPFR_EMAX_MAX); + mpfr_set_inf (x, 1); + mpfr_nextbelow (x); + mpfr_clear_flags (); + inexact = mpfr_modf (xi, xf, x, MPFR_RNDN); + gflags = __gmpfr_flags; + if (mpfr_cmp_str1 (xi, "@Inf@") != 0 || + MPFR_NOTZERO (xf) || MPFR_IS_NEG (xf)) + { + printf ("Error in check_special_exprange:" + " expected 0 and @Inf@, got\n"); + mpfr_out_str (stdout, 2, 0, xi, MPFR_RNDN); + printf (" and "); + mpfr_out_str (stdout, 2, 0, xf, MPFR_RNDN); + printf ("\n"); + exit (1); + } + if (inexact != 1) + { + printf ("Bad inexact value in check_special_exprange:" + " expected 1, got %d\n", inexact); + exit (1); + } + eflags = MPFR_FLAGS_INEXACT | MPFR_FLAGS_OVERFLOW; + if (gflags != eflags) + { + printf ("Bad flags in check_special_exprange:" + " expected %u, got %u\n", eflags, gflags); + exit (1); + } + set_emax (emax); + + /* Test if an underflow occurs in the general case. TODO */ + + mpfr_clears (xi, xf, x, (mpfr_ptr) 0); +} + int main (int argc, char *argv[]) { @@ -130,6 +218,8 @@ main (int argc, char *argv[]) /* integer part is rounded down, fractional part is exact: 2 */ check ("61632", "0", "61648", 10, 10, 53, 2, MPFR_RNDZ); + check_special_exprange (); + tests_end_mpfr (); return 0; } |