diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2017-08-22 08:00:54 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2017-08-22 08:00:54 +0000 |
commit | b65bf12a5896c1c96318cf65ed9456beb6a1c1ee (patch) | |
tree | 7fa6d933b1eb80e8500b84878c06d73861fade0f /tests/turandom.c | |
parent | 96c040f0188b116cd7d1057d0aa60d6d44ea3189 (diff) | |
download | mpfr-b65bf12a5896c1c96318cf65ed9456beb6a1c1ee.tar.gz |
[tests/turandom.c] Added overflow tests.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@11645 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/turandom.c')
-rw-r--r-- | tests/turandom.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/turandom.c b/tests/turandom.c index a9478ca61..5dc98708f 100644 --- a/tests/turandom.c +++ b/tests/turandom.c @@ -293,6 +293,62 @@ underflow_tests (void) mpfr_set_emin (emin); } +static void +overflow_tests (void) +{ + mpfr_t x; + mpfr_exp_t emax; + int i, k; + int rnd; + mpfr_flags_t ex_flags, flags; + + emax = mpfr_get_emax (); + mpfr_init2 (x, 4); + ex_flags = MPFR_FLAGS_OVERFLOW | MPFR_FLAGS_INEXACT; /* if overflow */ + for (i = -4; i <= 0; i++) + { + mpfr_set_emax (i); + RND_LOOP (rnd) + for (k = 0; k < 100; k++) + { + mpfr_clear_flags (); + mpfr_urandom (x, mpfr_rands, (mpfr_rnd_t) rnd); + flags = __gmpfr_flags; + MPFR_ASSERTN (mpfr_inexflag_p ()); + if (MPFR_IS_NEG (x)) + { + printf ("Error in overflow_tests: got a negative sign" + " for i=%d rnd=%s k=%d.\n", + i, mpfr_print_rnd_mode ((mpfr_rnd_t) rnd), k); + exit (1); + } + if (MPFR_IS_INF (x)) + { + if (rnd == MPFR_RNDD || rnd == MPFR_RNDZ) + { + printf ("Error in overflow_tests: the value cannot" + " be +inf for i=%d rnd=%s k=%d.\n", + i, mpfr_print_rnd_mode ((mpfr_rnd_t) rnd), k); + exit (1); + } + if (flags != ex_flags) + { + printf ("Error in overflow_tests: incorrect flags" + " for i=%d rnd=%s k=%d.\n", + i, mpfr_print_rnd_mode ((mpfr_rnd_t) rnd), k); + printf ("Expected "); + flags_out (ex_flags); + printf ("Got "); + flags_out (flags); + exit (1); + } + } + } + } + mpfr_clear (x); + mpfr_set_emax (emax); +} + int main (int argc, char *argv[]) { @@ -345,6 +401,7 @@ main (int argc, char *argv[]) } underflow_tests (); + overflow_tests (); #ifndef MPFR_USE_MINI_GMP /* Since these tests assume a deterministic random generator, and |