diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/reuse.c | 6 | ||||
-rw-r--r-- | tests/trint.c | 94 |
3 files changed, 98 insertions, 4 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 8593f107d..e3e65583b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,4 @@ -check_PROGRAMS= reuse tabs tadd tagm tcan_round tcmp tcmp2 tcmp_ui tdiv tdiv_ui tdump teq texp tget_str tlog tconst_log2 tmul tmul_2exp tmul_ui tout_str tconst_pi tpow trandom tround_prec tset_d tset_f tset_q tset_si tset_str tset_z tsqrt tsqrt_ui tui_div tui_sub tswap ttrunc tisnan tget_d tatan tcosh tsinh ttanh tacosh tasinh tatanh thyperbolic texp2 tfactorial tsub tasin tconst_euler tcos tsin ttan tsub_ui tset tlog1p texpm1 tlog2 tlog10 tui_pow tpow3 tadd_ui texceptions tfma thypot tacos +check_PROGRAMS= reuse tabs tadd tagm tcan_round tcmp tcmp2 tcmp_ui tdiv tdiv_ui tdump teq texp tget_str tlog tconst_log2 tmul tmul_2exp tmul_ui tout_str tconst_pi tpow trandom tround_prec tset_d tset_f tset_q tset_si tset_str tset_z tsqrt tsqrt_ui tui_div tui_sub tswap ttrunc trint tisnan tget_d tatan tcosh tsinh ttanh tacosh tasinh tatanh thyperbolic texp2 tfactorial tsub tasin tconst_euler tcos tsin ttan tsub_ui tset tlog1p texpm1 tlog2 tlog10 tui_pow tpow3 tadd_ui texceptions tfma thypot tacos EXTRA_DIST= tgeneric.c LDADD= $(top_builddir)/libmpfr.a @LDADD@ diff --git a/tests/reuse.c b/tests/reuse.c index d005eb485..3626b6e49 100644 --- a/tests/reuse.c +++ b/tests/reuse.c @@ -608,12 +608,12 @@ main (void) testfunc = (void*) mpfr_add; test3 ("mpfr_add", 53, GMP_RNDN); testfunc = (void*) mpfr_add_ui; test2ui ("mpfr_add_ui", 53, GMP_RNDN); testfunc = mpfr_agm; test3 ("mpfr_agm", 53, GMP_RNDN); - testfunc = mpfr_ceil; test2 ("mpfr_ceil", 53, GMP_RNDN); + testfunc = (void*) mpfr_ceil; test2 ("mpfr_ceil", 53, GMP_RNDN); testfunc = (void*) mpfr_div; test3 ("mpfr_div", 53, GMP_RNDN); testfunc = (void*) mpfr_div_2exp; test2ui ("mpfr_div_2exp", 53, GMP_RNDN); testfunc = (void*) mpfr_div_ui; test2ui ("mpfr_div_ui", 53, GMP_RNDN); testfunc = (void*) mpfr_exp; test2 ("mpfr_exp", 53, GMP_RNDN); - testfunc = mpfr_floor; test2 ("mpfr_floor", 53, GMP_RNDN); + testfunc = (void*) mpfr_floor; test2 ("mpfr_floor", 53, GMP_RNDN); testfunc = (void*) mpfr_log; test2 ("mpfr_log", 53, GMP_RNDN); testfunc = (void*) mpfr_mul; test3 ("mpfr_mul", 53, GMP_RNDN); testfunc = (void*) mpfr_mul_2exp; test2ui ("mpfr_mul_2exp", 53, GMP_RNDN); @@ -626,7 +626,7 @@ main (void) testfunc = (void*) mpfr_sqrt; test2 ("mpfr_sqrt", 53, GMP_RNDN); testfunc = (void*) mpfr_ui_div; testui2 ("mpfr_ui_div", 53, GMP_RNDN); testfunc = (void*) mpfr_ui_sub; testui2 ("mpfr_ui_sub", 53, GMP_RNDN); - testfunc = mpfr_trunc; test2 ("mpfr_trunc", 53, GMP_RNDN); + testfunc = (void*) mpfr_trunc; test2 ("mpfr_trunc", 53, GMP_RNDN); testfunc = (void*) mpfr_asin; test2 ("mpfr_asin", 53, GMP_RNDN); testfunc = (void*) mpfr_acos; test2 ("mpfr_acos", 53, GMP_RNDN); testfunc = (void*) mpfr_atan; test2 ("mpfr_atan", 53, GMP_RNDN); diff --git a/tests/trint.c b/tests/trint.c new file mode 100644 index 000000000..28be5b78c --- /dev/null +++ b/tests/trint.c @@ -0,0 +1,94 @@ +/* Test file for mpfr_trunc, mpfr_floor, mpfr_ceil, mpfr_round. + +Copyright (C) 2002 Free Software Foundation. + +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 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 Lesser General Public +License for more details. + +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. */ + +#include <stdio.h> +#include <stdlib.h> +#include "gmp.h" +#include "mpfr.h" + +int +main (void) +{ + mp_size_t s; + mpz_t z; + mp_prec_t p; + mpfr_t x, y, t; + mp_rnd_t r; + int inexact, sign_t; + + mpfr_init (x); + mpfr_init (y); + mpz_init (z); + mpfr_init (t); + mpz_set_ui (z, 1); + for (s=1; s<100; s++) + { + /* z has exactly s bits */ + + mpz_mul_2exp (z, z, 1); + if (rand () % 2) + mpz_add_ui (z, z, 1); + if (s == 1) + continue; + mpfr_set_prec (x, s); + mpfr_set_prec (t, s); + if (mpfr_set_z (x, z, GMP_RNDN)) + { + fprintf (stderr, "Error: mpfr_set_z should be exact (s = %u)\n", + (unsigned int) s); + exit (1); + } + for (p=2; p<100; p++) + { + mpfr_set_prec (y, p); + for (r=0; r<4; r++) + { + if (r == GMP_RNDN) + inexact = mpfr_round (y, x); + else if (r == GMP_RNDZ) + inexact = mpfr_trunc (y, x); + else if (r == GMP_RNDU) + inexact = mpfr_ceil (y, x); + else /* r = GMP_RNDD */ + inexact = mpfr_floor (y, x); + if (mpfr_sub (t, y, x, GMP_RNDN)) + { + fprintf (stderr, "Error: subtraction should be exact\n"); + exit (1); + } + sign_t = mpfr_cmp_ui (t, 0); + if (((inexact == 0) && (sign_t != 0)) || + ((inexact < 0) && (sign_t >= 0)) || + ((inexact > 0) && (sign_t <= 0))) + { + fprintf (stderr, "Wrong inexact flag\n"); + exit (1); + } + } + } + } + mpfr_clear (x); + mpfr_clear (y); + mpz_clear (z); + mpfr_clear (t); + + return 0; +} |