1/* ty0 -- test file for the Bessel function of second kind (order 0)
2
3Copyright 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_y0
29#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 8, RANDS)
30#include "tgeneric.c"
31
32int
33main (int argc, char *argv[])
34{
35  mpfr_t x, y;
36
37  tests_start_mpfr ();
38
39  mpfr_init (x);
40  mpfr_init (y);
41
42  /* special values */
43  mpfr_set_nan (x);
44  mpfr_y0 (y, x, MPFR_RNDN);
45  MPFR_ASSERTN(mpfr_nan_p (y));
46
47  mpfr_set_inf (x, 1); /* +Inf */
48  mpfr_y0 (y, x, MPFR_RNDN);
49  MPFR_ASSERTN(mpfr_cmp_ui (y, 0) == 0 && MPFR_IS_POS (y));
50
51  mpfr_set_inf (x, -1); /* -Inf */
52  mpfr_y0 (y, x, MPFR_RNDN);
53  MPFR_ASSERTN(mpfr_nan_p (y));
54
55  mpfr_set_ui (x, 0, MPFR_RNDN); /* +0 */
56  mpfr_y0 (y, x, MPFR_RNDN);
57  MPFR_ASSERTN(mpfr_inf_p (y) && MPFR_IS_NEG (y)); /* y0(+0)=-Inf */
58
59  mpfr_set_ui (x, 0, MPFR_RNDN);
60  mpfr_neg (x, x, MPFR_RNDN); /* -0 */
61  mpfr_y0 (y, x, MPFR_RNDN);
62  MPFR_ASSERTN(mpfr_inf_p (y) && MPFR_IS_NEG (y)); /* y0(-0)=-Inf */
63
64  mpfr_set_prec (x, 53);
65  mpfr_set_prec (y, 53);
66
67  mpfr_set_ui (x, 1, MPFR_RNDN);
68  mpfr_y0 (y, x, MPFR_RNDN);
69  mpfr_set_str_binary (x, "0.00010110100110000000001000100110111100110101100011011111");
70  if (mpfr_cmp (x, y))
71    {
72      printf ("Error in mpfr_y0 for x=1, rnd=MPFR_RNDN\n");
73      printf ("Expected "); mpfr_dump (x);
74      printf ("Got      "); mpfr_dump (y);
75      exit (1);
76    }
77
78  mpfr_set_si (x, -1, MPFR_RNDN);
79  mpfr_y0 (y, x, MPFR_RNDN);
80  if (!mpfr_nan_p (y))
81    {
82      printf ("Error in mpfr_y0 for x=-1, rnd=MPFR_RNDN\n");
83      printf ("Expected NaN\n");
84      printf ("Got      "); mpfr_dump (y);
85      exit (1);
86    }
87
88  mpfr_clear (x);
89  mpfr_clear (y);
90
91  test_generic (2, 100, 1);
92
93  data_check ("data/y0", mpfr_y0, "mpfr_y0");
94
95  tests_end_mpfr ();
96
97  return 0;
98}
99