diff options
author | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2005-08-01 15:23:51 +0000 |
---|---|---|
committer | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2005-08-01 15:23:51 +0000 |
commit | 8a7788b83bfa6938141c625f5a5f820743066e04 (patch) | |
tree | f88a2a2deb410d9dd71103a45fbf5b64f36ed7ed /tests/tsubnormal.c | |
parent | ce85911b84c2bf0b1f2b1d1561803734542346b3 (diff) | |
download | mpfr-8a7788b83bfa6938141c625f5a5f820743066e04.tar.gz |
Add test file for mpfr_subnormalize
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@3692 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tsubnormal.c')
-rw-r--r-- | tests/tsubnormal.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/tsubnormal.c b/tests/tsubnormal.c new file mode 100644 index 000000000..8edf60c31 --- /dev/null +++ b/tests/tsubnormal.c @@ -0,0 +1,85 @@ +/* Test file for mpfr_subnormalize. + +Copyright 2005 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 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., 51 Franklin Place, Fifth Floor, Boston, +MA 02110-1301, USA. */ + +#include <stdio.h> +#include <stdlib.h> + +#include "mpfr-test.h" + +static const struct { + const char *in; + int i; + mp_rnd_t rnd; + const char *out; +} tab[] ={ + {"1E1", 0, GMP_RNDN, "1E1"}, + {"1E1", -1, GMP_RNDZ, "1E1"}, + {"1E1", -1, GMP_RNDD, "1E1"}, + {"1E1", 1, GMP_RNDU, "1E1"}, + {"0.10000E-10", 0, GMP_RNDN, "0.1E-10"}, + {"0.10001E-10", 0, GMP_RNDN, "0.1E-10"}, + {"0.11001E-10", 0, GMP_RNDN, "0.1E-9"}, + {"0.11001E-10", 0, GMP_RNDZ, "0.1E-10"}, + {"0.11001E-10", 0, GMP_RNDU, "0.1E-9"}, + {"0.11000E-10", 0, GMP_RNDN, "0.1E-9"}, + {"0.11111E-8", 0, GMP_RNDN, "0.10E-7"}, + {"0.10111E-8", 0, GMP_RNDN, "0.11E-8"}, + {"0.11110E-8", -1, GMP_RNDN, "0.10E-7"}, + {"0.10110E-8", 1, GMP_RNDN, "0.101E-8"} +}; + +static void +check1 (void) +{ + mpfr_t x; + int i, j; + + mpfr_set_default_prec (9); + mpfr_set_emin (-10); + mpfr_set_emax (10); + + mpfr_init (x); + for (i = 0; i < (sizeof (tab) / sizeof (tab[0])); i++) + { + mpfr_set_str (x, tab[i].in, 2, GMP_RNDN); + j = mpfr_subnormalize (x, tab[i].i, tab[i].rnd); + if (mpfr_cmp_str (x, tab[i].out, 2, GMP_RNDN) != 0) + { + printf ("Error for i=%d\nFor:%s\nExpected:%s\nGot:", + i, tab[i].in, tab[i].out); + mpfr_dump (x); + exit (1); + } + } + mpfr_clear (x); +} + + +int +main (int argc, char *argv[]) +{ + tests_start_mpfr (); + + check1 (); + + tests_end_mpfr (); + return 0; +} |