diff options
Diffstat (limited to 'mpfr/tests/tui_div.c')
-rw-r--r-- | mpfr/tests/tui_div.c | 72 |
1 files changed, 64 insertions, 8 deletions
diff --git a/mpfr/tests/tui_div.c b/mpfr/tests/tui_div.c index b3e812378..42b0f45b8 100644 --- a/mpfr/tests/tui_div.c +++ b/mpfr/tests/tui_div.c @@ -1,20 +1,20 @@ /* Test file for mpfr_ui_div. -Copyright (C) 2000 Free Software Foundation. +Copyright (C) 2000, 2001 Free Software Foundation, Inc. This file is part of the MPFR Library. The MPFR Library is free software; you can redistribute it and/or modify -it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at your +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The MPFR Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. -You should have received a copy of the GNU Library General Public License +You should have received a copy of the GNU Lesser General Public License along with the MPFR Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -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,10 +52,64 @@ 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); } -int main(argc,argv) int argc; char *argv[]; +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 +main (int argc, char *argv[]) { #ifdef TEST double x; unsigned long y, N; int i,rnd_mode,rnd; @@ -79,6 +134,7 @@ int main(argc,argv) 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); @@ -93,6 +149,6 @@ int main(argc,argv) int argc; char *argv[]; 1.3178666932321966062e285); check(1476599377, -2.14191393656148625995e+305, GMP_RNDD, -6.8938315017943889615e-297); + return 0; } - |