1/* Test file for mpfr_zeta_ui.
2
3Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4Contributed by the Arenaire and Cacao projects, INRIA.
5
6This file is part of the GNU MPFR Library.
7
8The GNU MPFR Library is free software; you can redistribute it and/or modify
9it under the terms of the GNU Lesser General Public License as published by
10the Free Software Foundation; either version 3 of the License, or (at your
11option) any later version.
12
13The GNU MPFR Library is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16License for more details.
17
18You should have received a copy of the GNU Lesser General Public License
19along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
20http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
2151 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
22
23#include <stdio.h>
24#include <stdlib.h>
25
26#include "mpfr-test.h"
27
28#define TEST_FUNCTION mpfr_zeta_ui
29
30int
31main (int argc, char *argv[])
32{
33#if MPFR_VERSION >= MPFR_VERSION_NUM(2,3,0)
34  unsigned int prec, yprec;
35  int rnd;
36  mpfr_t x, y, z, t;
37  int inexact;
38  unsigned long n;
39
40  tests_start_mpfr ();
41
42  mpfr_init (x);
43  mpfr_init (y);
44  mpfr_init (z);
45  mpfr_init (t);
46
47  if (argc >= 3) /* tzeta_ui n prec [rnd] */
48    {
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);
53      printf ("\n");
54      goto clear_and_exit;
55    }
56
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");
61  if (mpfr_cmp (x, y))
62    {
63      printf ("Error for zeta(3), prec=33, MPFR_RNDZ\n");
64      printf ("expected "); mpfr_dump (y);
65      printf ("got      "); mpfr_dump (x);
66      exit (1);
67    }
68
69  for (prec = MPFR_PREC_MIN; prec <= 100; prec++)
70    {
71      mpfr_set_prec (x, prec);
72      mpfr_set_prec (z, prec);
73      mpfr_set_prec (t, prec);
74      yprec = prec + 10;
75      mpfr_set_prec (y, yprec);
76
77      for (n = 0; n < 50; n++)
78        for (rnd = 0; rnd < MPFR_RND_MAX; rnd++)
79          {
80            inexact = mpfr_zeta_ui (y, n, MPFR_RNDN);
81            if (mpfr_can_round (y, yprec, MPFR_RNDN, MPFR_RNDZ, prec
82                                + (rnd == MPFR_RNDN)))
83              {
84                mpfr_set (t, y, (mpfr_rnd_t) rnd);
85                inexact = mpfr_zeta_ui (z, n, (mpfr_rnd_t) rnd);
86                if (mpfr_cmp (t, z))
87                  {
88                    printf ("results differ for n=%lu", n);
89                    printf (" prec=%u rnd_mode=%s\n", prec,
90                            mpfr_print_rnd_mode ((mpfr_rnd_t) rnd));
91                    printf ("   got      ");
92                    mpfr_dump (z);
93                    printf ("   expected ");
94                    mpfr_dump (t);
95                    printf ("   approx   ");
96                    mpfr_dump (y);
97                    exit (1);
98                  }
99              }
100          }
101    }
102
103 clear_and_exit:
104  mpfr_clear (x);
105  mpfr_clear (y);
106  mpfr_clear (z);
107  mpfr_clear (t);
108
109  tests_end_mpfr ();
110#endif
111  return 0;
112}
113