diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2001-10-26 08:43:09 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2001-10-26 08:43:09 +0000 |
commit | 7b25f866ff10829c1dd75ef95a34c9d24bb99425 (patch) | |
tree | 64d10f5e745548957e04452d62e433681953d080 /tests/tui_div.c | |
parent | a14d763666063440fe669c06c48e66cb403c9443 (diff) | |
download | mpfr-7b25f866ff10829c1dd75ef95a34c9d24bb99425.tar.gz |
added test for inexact flag
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1403 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tui_div.c')
-rw-r--r-- | tests/tui_div.c | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/tests/tui_div.c b/tests/tui_div.c index c40698960..ba364dc40 100644 --- a/tests/tui_div.c +++ b/tests/tui_div.c @@ -29,6 +29,7 @@ MA 02111-1307, USA. */ #endif void check _PROTO((unsigned long, double, mp_rnd_t, double)); +void check_inexact _PROTO((void)); /* checks that y/x gives the same results in double and with mpfr with 53 bits of precision */ @@ -51,7 +52,60 @@ void check (unsigned long y, double x, mp_rnd_t rnd_mode, double z1) y, x, mpfr_print_rnd_mode(rnd_mode)); exit(1); } - mpfr_clear(xx); mpfr_clear(zz); + mpfr_clear(xx); + mpfr_clear(zz); +} + +void +check_inexact () +{ + mpfr_t x, y, z; + mp_prec_t px, py; + int inexact, cmp; + unsigned long int u; + mp_rnd_t rnd; + + mpfr_init (x); + mpfr_init (y); + mpfr_init (z); + + for (px=1; px<300; px++) + { + mpfr_set_prec (x, px); + mpfr_random (x); + u = lrand48 (); + for (py=1; py<300; py++) + { + mpfr_set_prec (y, py); + mpfr_set_prec (z, py + px); + for (rnd=0; rnd<4; rnd++) + { + inexact = mpfr_ui_div (y, u, x, rnd); + if (mpfr_mul (z, y, x, rnd)) + { + fprintf (stderr, "z <- y * x should be exact\n"); + exit (1); + } + cmp = mpfr_cmp_ui (z, u); + if (((inexact == 0) && (cmp != 0)) || + ((inexact > 0) && (cmp <= 0)) || + ((inexact < 0) && (cmp >= 0))) + { + fprintf (stderr, "Wrong inexact flag for u=%lu, rnd=%s\n", u, + mpfr_print_rnd_mode(rnd)); + printf ("expected %d, got %d\n", cmp, inexact); + printf ("x="); mpfr_print_raw (x); putchar ('\n'); + printf ("y="); mpfr_print_raw (y); putchar ('\n'); + printf ("y*x="); mpfr_print_raw (z); putchar ('\n'); + exit (1); + } + } + } + } + + mpfr_clear (x); + mpfr_clear (y); + mpfr_clear (z); } int @@ -80,6 +134,7 @@ main (int argc, char *argv[]) } } #endif + check_inexact (); check(1, 1.0/0.0, GMP_RNDN, 0.0); check(1, -1.0/0.0, GMP_RNDN, -0.0); check(1, 0.0/0.0, GMP_RNDN, 0.0/0.0); |