diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2015-06-05 01:21:49 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2015-06-05 01:21:49 +0000 |
commit | 056d175cec64ca98d8765204b98be00b5000bebd (patch) | |
tree | a54764ada4f20e9ec0a03c7683009fb0a3149e8c /tests/tui_sub.c | |
parent | df15e49f51854708bce13a3db6ff8c643f72ba84 (diff) | |
download | mpfr-056d175cec64ca98d8765204b98be00b5000bebd.tar.gz |
[tests/tui_sub.c] Check overflow.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@9513 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tui_sub.c')
-rw-r--r-- | tests/tui_sub.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/tui_sub.c b/tests/tui_sub.c index 2fd53edec..0137f535f 100644 --- a/tests/tui_sub.c +++ b/tests/tui_sub.c @@ -259,6 +259,61 @@ static void check_neg (void) mpfr_clear (ysub); } +static void +check_overflow (void) +{ + mpfr_exp_t emin, emax; + mpfr_t x, y1, y2; + int inex1, inex2, rnd_mode; + mpfr_flags_t flags1, flags2; + + emin = mpfr_get_emin (); + emax = mpfr_get_emax (); + set_emin (MPFR_EMIN_MIN); + set_emax (MPFR_EMAX_MAX); + + mpfr_inits2 (32, x, y1, y2, (mpfr_ptr) 0); + mpfr_setmax (x, MPFR_EMAX_MAX); + mpfr_neg (x, x, MPFR_RNDN); + RND_LOOP (rnd_mode) + { + if (rnd_mode == MPFR_RNDU || rnd_mode == MPFR_RNDA) + { + inex1 = mpfr_overflow (y1, (mpfr_rnd_t) rnd_mode, 1); + flags1 = MPFR_FLAGS_OVERFLOW | MPFR_FLAGS_INEXACT; + } + else + { + mpfr_neg (y1, x, MPFR_RNDN); + inex1 = -1; + flags1 = MPFR_FLAGS_INEXACT; + } + mpfr_clear_flags (); + inex2 = mpfr_ui_sub (y2, 1, x, (mpfr_rnd_t) rnd_mode); + flags2 = __gmpfr_flags; + if (!(mpfr_equal_p (y1, y2) && + SAME_SIGN (inex1, inex2) && + flags1 == flags2)) + { + printf ("Error in check_overflow for %s\n", + mpfr_print_rnd_mode ((mpfr_rnd_t) rnd_mode)); + printf ("Expected "); + mpfr_dump (y1); + printf (" with inex = %d, flags =", inex1); + flags_out (flags1); + printf ("Got "); + mpfr_dump (y2); + printf (" with inex = %d, flags =", inex2); + flags_out (flags2); + exit (1); + } + } + mpfr_clears (x, y1, y2, (mpfr_ptr) 0); + + set_emin (emin); + set_emax (emax); +} + #define TEST_FUNCTION mpfr_ui_sub #define ULONG_ARG1 #include "tgeneric.c" @@ -294,6 +349,7 @@ main (int argc, char *argv[]) "2.9360773800002003e8"); check(354270183, "2.9469161763489528e3", MPFR_RNDN, "3.5426723608382362e8"); + check_overflow (); check_neg (); |