diff options
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 |