diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2015-08-24 15:38:14 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2015-08-24 15:38:14 +0000 |
commit | b2a1295a9271c13aedc945a1dcd37192fbbf1d50 (patch) | |
tree | 55e1d56ccd2d7ac275335640ca7baabcd475d021 /tests | |
parent | 53c5c3f927121188cf8d9a0ef2a40e8cefc5ee62 (diff) | |
download | mpfr-b2a1295a9271c13aedc945a1dcd37192fbbf1d50.tar.gz |
[tests/tfits.c] For the mpfr_fits_{uintmax,intmax}_p functions, check
that the flags are not modified and added tests of -Inf and -0.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@9654 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tfits.c | 119 |
1 files changed, 42 insertions, 77 deletions
diff --git a/tests/tfits.c b/tests/tfits.c index 53d6deafb..191b3a492 100644 --- a/tests/tfits.c +++ b/tests/tfits.c @@ -29,16 +29,6 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #include "mpfr-intmax.h" #include "mpfr-test.h" -#define ERROR1(N) \ - do \ - { \ - printf("Error %d for rnd = %s and x = ", N, \ - mpfr_print_rnd_mode ((mpfr_rnd_t) r)); \ - mpfr_dump(x); \ - exit(1); \ - } \ - while (0) - #define FTEST(N,NOT,FCT) \ do \ { \ @@ -79,7 +69,13 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., } \ while (0) -static void check_intmax (void); +#define CHECK_MAX(N,NOT) \ + do \ + { \ + FTEST (N, NOT, mpfr_fits_uintmax_p); \ + FTEST (N, NOT, mpfr_fits_intmax_p); \ + } \ + while (0) int main (void) @@ -170,90 +166,57 @@ main (void) } } - mpfr_clear (x); - mpfr_clear (y); - - check_intmax (); - - tests_end_mpfr (); - return 0; -} - -static void -check_intmax (void) -{ #ifdef _MPFR_H_HAVE_INTMAX_T - mpfr_t x, y; - int i, r; - mpfr_init2 (x, sizeof (uintmax_t) * CHAR_BIT); - mpfr_init2 (y, 8); + mpfr_set_prec (x, sizeof (uintmax_t) * CHAR_BIT); RND_LOOP (r) { - /* Check NAN */ + /* Check NaN */ mpfr_set_nan (x); - if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (52); - if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (53); + CHECK_MAX (1, !!); - /* Check INF */ + /* Check +Inf */ mpfr_set_inf (x, 1); - if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (54); - if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (55); - - /* Check Zero */ - MPFR_SET_ZERO (x); - if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (56); - if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (57); - - /* Check positive small op */ + CHECK_MAX (2, !!); + + /* Check -Inf */ + mpfr_set_inf (x, -1); + CHECK_MAX (3, !!); + + /* Check +0 */ + mpfr_set_zero (x, 1); + CHECK_MAX (4, !); + + /* Check -0 */ + mpfr_set_zero (x, -1); + CHECK_MAX (5, !); + + /* Check small positive op */ mpfr_set_str1 (x, "1@-1"); - if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (58); - if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (59); + CHECK_MAX (6, !); /* Check 17 */ mpfr_set_ui (x, 17, MPFR_RNDN); - if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (60); - if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (61); + CHECK_MAX (7, !); /* Check hugest */ mpfr_set_ui_2exp (x, 42, sizeof (uintmax_t) * 32, MPFR_RNDN); - if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (62); - if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (63); + CHECK_MAX (8, !!); /* Check all other values */ mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN); + FTEST (10, !, mpfr_fits_uintmax_p); mpfr_add_ui (x, x, 1, MPFR_RNDN); - if (mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (64); - mpfr_set_uj (x, MPFR_UINTMAX_MAX, MPFR_RNDN); - if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (65); + FTEST (11, !!, mpfr_fits_uintmax_p); mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN); + FTEST (12, !, mpfr_fits_intmax_p); mpfr_add_ui (x, x, 1, MPFR_RNDN); - if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (66); - mpfr_set_sj (x, MPFR_INTMAX_MAX, MPFR_RNDN); - if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (67); + FTEST (13, !!, mpfr_fits_intmax_p); mpfr_set_sj (x, MPFR_INTMAX_MIN, MPFR_RNDN); - if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (68); + FTEST (14, !, mpfr_fits_intmax_p); mpfr_sub_ui (x, x, 1, MPFR_RNDN); - if (mpfr_fits_intmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (69); + FTEST (15, !!, mpfr_fits_intmax_p); /* Check negative op */ for (i = 1; i <= 4; i++) @@ -263,14 +226,16 @@ check_intmax (void) mpfr_set_si_2exp (x, -i, -2, MPFR_RNDN); mpfr_rint (y, x, (mpfr_rnd_t) r); inv = MPFR_NOTZERO (y); - if (!mpfr_fits_uintmax_p (x, (mpfr_rnd_t) r) ^ inv) - ERROR1 (70); - if (!mpfr_fits_intmax_p (x, (mpfr_rnd_t) r)) - ERROR1 (71); + FTEST (19, inv ^ !, mpfr_fits_uintmax_p); + FTEST (19, !, mpfr_fits_intmax_p); } } +#endif /* _MPFR_H_HAVE_INTMAX_T */ + mpfr_clear (x); mpfr_clear (y); -#endif + + tests_end_mpfr (); + return 0; } |