1 /* Test file for mpfr_zeta_ui.
3 Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 Contributed by the AriC and Caramel projects, INRIA.
6 This file is part of the GNU MPFR Library.
8 The GNU MPFR Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
13 The GNU MPFR Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
20 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
21 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
26 #include "mpfr-test.h"
28 #define TEST_FUNCTION mpfr_zeta_ui
31 main (int argc, char *argv[])
33 #if MPFR_VERSION >= MPFR_VERSION_NUM(2,3,0)
34 unsigned int prec, yprec;
47 if (argc >= 3) /* tzeta_ui n prec [rnd] */
49 mpfr_set_prec (x, atoi (argv[2]));
50 mpfr_zeta_ui (x, atoi (argv[1]),
51 argc > 3 ? (mpfr_rnd_t) atoi (argv[3]) : MPFR_RNDN);
52 mpfr_out_str (stdout, 10, 0, x, MPFR_RNDN);
57 mpfr_set_prec (x, 33);
58 mpfr_set_prec (y, 33);
59 mpfr_zeta_ui (x, 3, MPFR_RNDZ);
60 mpfr_set_str_binary (y, "0.100110011101110100000000001001111E1");
63 printf ("Error for zeta(3), prec=33, MPFR_RNDZ\n");
64 printf ("expected "); mpfr_dump (y);
65 printf ("got "); mpfr_dump (x);
70 inex = mpfr_zeta_ui (x, 0, MPFR_RNDN);
71 MPFR_ASSERTN (inex == 0 && mpfr_cmp_si_2exp (x, -1, -1) == 0
72 && !mpfr_divby0_p ());
75 inex = mpfr_zeta_ui (x, 1, MPFR_RNDN);
76 MPFR_ASSERTN (inex == 0 && MPFR_IS_INF (x) && MPFR_IS_POS (x)
79 for (prec = MPFR_PREC_MIN; prec <= 100; prec++)
81 mpfr_set_prec (x, prec);
82 mpfr_set_prec (z, prec);
83 mpfr_set_prec (t, prec);
85 mpfr_set_prec (y, yprec);
87 for (n = 0; n < 50; n++)
88 for (rnd = 0; rnd < MPFR_RND_MAX; rnd++)
90 mpfr_zeta_ui (y, n, MPFR_RNDN);
91 if (mpfr_can_round (y, yprec, MPFR_RNDN, MPFR_RNDZ, prec
92 + (rnd == MPFR_RNDN)))
94 mpfr_set (t, y, (mpfr_rnd_t) rnd);
95 mpfr_zeta_ui (z, n, (mpfr_rnd_t) rnd);
98 printf ("results differ for n=%lu", n);
99 printf (" prec=%u rnd_mode=%s\n", prec,
100 mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
103 printf (" expected ");