diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2021-01-29 14:21:04 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2021-01-29 14:21:04 +0000 |
commit | 1863c7e873e16f8d72f155eb6dfbf139c621f546 (patch) | |
tree | 059f86ff5cb80c22b8d865abbfa51066dc9c8f18 /tests | |
parent | febe9e5d1c92d95ccef8fc8ecb7bf1fc361a1ec9 (diff) | |
download | mpfr-1863c7e873e16f8d72f155eb6dfbf139c621f546.tar.gz |
new function mpfr_acosu (still to be added in NEWS and mpfr.texi)
git-svn-id: https://scm.gforge.inria.fr/anonscm/svn/mpfr/trunk@14267 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/tacosu.c | 108 | ||||
-rw-r--r-- | tests/tgeneric.c | 17 |
3 files changed, 121 insertions, 6 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 814942b46..9aa5c4b23 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -30,7 +30,7 @@ output_info = { \ TESTS_NO_TVERSION = tabort_prec_max tassert tabort_defalloc1 \ tabort_defalloc2 talloc tinternals tinits tisqrt tsgn tcheck \ tisnan texceptions tset_exp tset mpf_compat mpfr_compat reuse \ - tabs tacos tacosh tadd tadd1sp tadd_d tadd_ui tagm tai \ + tabs tacos tacosh tacosu tadd tadd1sp tadd_d tadd_ui tagm tai \ talloc-cache tasin tasinh tatan tatanh taway tbeta tbuildopt \ tcan_round tcbrt tcmp tcmp2 tcmp_d tcmp_ld tcmp_ui tcmpabs \ tcomparisons tconst_catalan tconst_euler tconst_log2 tconst_pi \ diff --git a/tests/tacosu.c b/tests/tacosu.c new file mode 100644 index 000000000..49c0ec1d6 --- /dev/null +++ b/tests/tacosu.c @@ -0,0 +1,108 @@ +/* Test file for mpfr_acosu. + +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_acosu +#define ULONG_ARG2 +#include "tgeneric.c" + +int +main (void) +{ + mpfr_t x, y; + int r; + + tests_start_mpfr (); + + mpfr_init (x); + mpfr_init (y); + + MPFR_SET_NAN(x); + mpfr_acosu (y, x, 1, MPFR_RNDN); + if (mpfr_nan_p (y) == 0) + { + printf ("Error: acosu (NaN, 1) != NaN\n"); + exit (1); + } + + mpfr_set_ui (x, 2, MPFR_RNDN); + mpfr_acosu (y, x, 1, MPFR_RNDN); + if (mpfr_nan_p (y) == 0) + { + printf ("Error: acosu (2, 1) != NaN\n"); + exit (1); + } + + mpfr_set_si (x, -2, MPFR_RNDN); + mpfr_acosu (y, x, 1, MPFR_RNDN); + if (mpfr_nan_p (y) == 0) + { + printf ("Error: acosu (-2, 1) != NaN\n"); + exit (1); + } + + /* acosu (1,u) = 0, acosu(-1,u) = u/2 */ + mpfr_set_ui (x, 1, MPFR_RNDN); + mpfr_acosu (y, x, 1, MPFR_RNDN); + if (MPFR_NOTZERO (y) || MPFR_IS_NEG (y)) + { + printf ("Error: acosu(1,1) != +0.0\n"); + exit (1); + } + + /* acosu (0,u) = u/4 */ + for (r = 0; r < MPFR_RND_MAX; r++) + { + mpfr_set_ui (x, 0, MPFR_RNDN); /* exact */ + mpfr_acosu (y, x, 17, (mpfr_rnd_t) r); + mpfr_set_ui_2exp (x, 17, -2, MPFR_RNDN); + if (mpfr_cmp (x, y)) + { + printf ("Error: acosu(0,17) != 17/4 for rnd=%s\n", + mpfr_print_rnd_mode ((mpfr_rnd_t) r)); + exit (1); + } + } + + /* acos (-1,u) = u/2 */ + for (r = 0; r < MPFR_RND_MAX; r++) + { + mpfr_set_si (x, -1, MPFR_RNDN); /* exact */ + mpfr_acosu (y, x, 17, (mpfr_rnd_t) r); + mpfr_set_ui_2exp (x, 17, -1, MPFR_RNDN); + if (mpfr_cmp (x, y)) + { + printf ("Error: acosu(1,17) != 17/2 for rnd=%s\n", + mpfr_print_rnd_mode ((mpfr_rnd_t) r)); + exit (1); + } + } + + test_generic (MPFR_PREC_MIN, 100, 1000); + + mpfr_clear (x); + mpfr_clear (y); + + tests_end_mpfr (); + return 0; +} diff --git a/tests/tgeneric.c b/tests/tgeneric.c index 602b97eff..f2ad34fbd 100644 --- a/tests/tgeneric.c +++ b/tests/tgeneric.c @@ -178,7 +178,7 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) mpfr_set_prec (z, prec); mpfr_set_prec (t, prec); - yprec = prec + 10; + yprec = prec + 20; mpfr_set_prec (y, yprec); mpfr_set_prec (yd, yprec); mpfr_set_prec (yu, yprec); @@ -386,10 +386,12 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) printf ("For RNDF, result does not match RNDD nor RNDU\n"); printf ("x = "); mpfr_dump (x); #ifdef NEED_U - printf ("u = "); mpfr_dump (u); -#endif + printf ("u = "); #if defined(ULONG_ARG1) || defined(ULONG_ARG2) - printf ("i = %lu\n", i); + printf ("%lu\n", i); +#else + mpfr_dump (u); +#endif #endif printf ("yd (RNDD) = "); mpfr_dump (yd); printf ("yu (RNDU) = "); mpfr_dump (yu); @@ -713,12 +715,17 @@ test_generic (mpfr_prec_t p0, mpfr_prec_t p1, unsigned int nmax) if (! mpfr_equal_p (t, z) && rnd != MPFR_RNDF) { printf ("tgeneric: results differ for " - MAKE_STR(TEST_FUNCTION) " on\n x = "); + MAKE_STR(TEST_FUNCTION) " on\n x[%lu] = ", + mpfr_get_prec (x)); mpfr_dump (x); #ifdef NEED_U printf (" u = "); +#if defined(ULONG_ARG1) || defined(ULONG_ARG2) + printf ("%lu\n", i); +#else mpfr_dump (u); #endif +#endif printf (" prec = %u, rnd_mode = %s\n", (unsigned int) prec, mpfr_print_rnd_mode (rnd)); printf ("Got "); |