diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2021-02-03 08:18:59 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2021-02-03 08:18:59 +0000 |
commit | 6422bd39816ee2ae6317a27874f83fc6421beae0 (patch) | |
tree | 99c153cbc1717ddcbc6438bbf19316cd36387cca /tests/tcompound.c | |
parent | 53177c638129e9cc6fbf5ae507f5da81198a5eed (diff) | |
download | mpfr-6422bd39816ee2ae6317a27874f83fc6421beae0.tar.gz |
added log2p1 and compound (mpfr_compound is not finished yet)
git-svn-id: https://scm.gforge.inria.fr/anonscm/svn/mpfr/trunk@14331 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tcompound.c')
-rw-r--r-- | tests/tcompound.c | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/tests/tcompound.c b/tests/tcompound.c new file mode 100644 index 000000000..4e661d519 --- /dev/null +++ b/tests/tcompound.c @@ -0,0 +1,173 @@ +/* Test file for mpfr_compound. + +Copyright 2021 Free Software Foundation, Inc. +Contributed by the AriC and Caramba projects, INRIA. + +This file is part of the GNU MPFR Library. + +The GNU 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 3 of the License, or (at your +option) any later version. + +The GNU 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 GNU MPFR Library; see the file COPYING.LESSER. If not, see +https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include "mpfr-test.h" + +#define TEST_FUNCTION mpfr_compound +#define INTEGER_TYPE long +#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 1, RANDS) +#define test_generic_ui test_generic_si +#include "tgeneric_ui.c" + +/* Special cases from IEEE 754-2019 */ +static void +check_ieee754 (void) +{ + mpfr_t x, y; + long i; + mpfr_prec_t prec = 2; /* we need at least 2 so that 3/4 is exact */ + + mpfr_init2 (x, prec); + mpfr_init2 (y, prec); + + /* compound(x,n) = NaN for x < -1, and set invalid exception */ + mpfr_clear_nanflag (); + mpfr_set_si (x, -2, MPFR_RNDN); + mpfr_compound (y, x, 17, MPFR_RNDN); + if (!mpfr_nan_p (y)) + { + printf ("Error, compound(-2,17) should give NaN\n"); + printf ("got "); mpfr_dump (y); + exit (1); + } + if (!mpfr_nanflag_p ()) + { + printf ("Error, compound(-2,17) should raise invalid flag\n"); + exit (1); + } + + /* compound(x,0) = 1 for x >= -1 (or NaN), we choose 1 */ + for (i = -1; i <= 2; i++) + { + if (i != 2) + mpfr_set_si (x, i, MPFR_RNDN); + else + mpfr_set_inf (x, 1); + mpfr_compound (y, x, 0, MPFR_RNDN); + if (mpfr_cmp_ui (y, 1) != 0) + { + mpfr_printf ("Error, compound(%Re,0) should give 1\n", x); + printf ("got "); mpfr_dump (y); + exit (1); + } + } + + /* compound(-1,n) = +Inf for n < 0, and raise divide-by-zero flag */ + mpfr_clear_divby0 (); + mpfr_set_si (x, -1, MPFR_RNDN); + mpfr_compound (y, x, -1, MPFR_RNDN); + if (!mpfr_inf_p (y) || MPFR_SIGN(y) < 0) + { + printf ("Error, compound(-1,-1) should give +Inf\n"); + printf ("got "); mpfr_dump (y); + exit (1); + } + if (!mpfr_divby0_p ()) + { + printf ("Error, compound(-1,-1) should raise divide-by-zero flag\n"); + exit (1); + } + + /* compound(-1,n) = +0 for n > 0 */ + mpfr_set_si (x, -1, MPFR_RNDN); + mpfr_compound (y, x, 1, MPFR_RNDN); + if (!mpfr_zero_p (y) || MPFR_SIGN(y) < 0) + { + printf ("Error, compound(-1,1) should give +0\n"); + printf ("got "); mpfr_dump (y); + exit (1); + } + + /* compound(+/-0,n) = 1 */ + for (i = -1; i <= 1; i++) + { + mpfr_set_zero (x, -1); + mpfr_compound (y, x, i, MPFR_RNDN); + if (mpfr_cmp_ui (y, 1) != 0) + { + mpfr_printf ("Error1, compound(%Re,%ld) should give 1\n", x, i); + printf ("got "); mpfr_dump (y); + exit (1); + } + mpfr_set_zero (x, +1); + mpfr_compound (y, x, i, MPFR_RNDN); + if (mpfr_cmp_ui (y, 1) != 0) + { + mpfr_printf ("Error, compound(%Re,%ld) should give 1\n", x, i); + printf ("got "); mpfr_dump (y); + exit (1); + } + } + + /* compound(+Inf,n) = +Inf for n > 0 */ + mpfr_set_inf (x, 1); + mpfr_compound (y, x, 1, MPFR_RNDN); + if (!mpfr_inf_p (y) || MPFR_SIGN(y) < 0) + { + printf ("Error, compound(+Inf,1) should give +Inf\n"); + printf ("got "); mpfr_dump (y); + exit (1); + } + + /* compound(+Inf,n) = +0 for n < 0 */ + mpfr_set_inf (x, 1); + mpfr_compound (y, x, -1, MPFR_RNDN); + if (!mpfr_zero_p (y) || MPFR_SIGN(y) < 0) + { + printf ("Error, compound(+Inf,-1) should give +0\n"); + printf ("got "); mpfr_dump (y); + exit (1); + } + + /* compound(NaN,n) = NaN for n <> 0 */ + mpfr_set_nan (x); + mpfr_compound (y, x, -1, MPFR_RNDN); + if (!mpfr_nan_p (y)) + { + printf ("Error, compound(NaN,-1) should give NaN\n"); + printf ("got "); mpfr_dump (y); + exit (1); + } + mpfr_compound (y, x, +1, MPFR_RNDN); + if (!mpfr_nan_p (y)) + { + printf ("Error, compound(NaN,+1) should give NaN\n"); + printf ("got "); mpfr_dump (y); + exit (1); + } + + mpfr_clear (x); + mpfr_clear (y); +} + +int +main (void) +{ + tests_start_mpfr (); + + check_ieee754 (); + + test_generic_si (MPFR_PREC_MIN, 100, 100); + + tests_end_mpfr (); + return 0; +} |