1/* tyn -- test file for the Bessel function of second kind
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
28int
29main (int argc, char *argv[])
30{
31  mpfr_t x, y;
32  long n;
33  mpfr_prec_t prec = 53;
34
35  tests_start_mpfr ();
36
37  mpfr_init (x);
38  mpfr_init (y);
39
40  if (argc != 1)
41    {
42      if (argc != 4)
43        {
44          printf ("Usage: tyn n x prec\n");
45          exit (1);
46        }
47      n = atoi (argv[1]);
48      prec = atoi (argv[3]);
49      mpfr_set_prec (x, prec);
50      mpfr_set_prec (y, prec);
51      mpfr_set_str (x, argv[2], 10, MPFR_RNDN);
52      mpfr_yn (y, n, x, MPFR_RNDN);
53      printf ("Y(%ld,", n);
54      mpfr_out_str (stdout, 10, 0, x, MPFR_RNDN);
55      printf (")=");
56      mpfr_out_str (stdout, 10, 0, y, MPFR_RNDN);
57      printf ("\n");
58      goto end;
59    }
60
61  /* special values */
62  mpfr_set_nan (x);
63  mpfr_yn (y, 17, x, MPFR_RNDN);
64  MPFR_ASSERTN(mpfr_nan_p (y));
65
66  mpfr_set_inf (x, 1); /* +Inf */
67  mpfr_yn (y, 17, x, MPFR_RNDN);
68  MPFR_ASSERTN(mpfr_cmp_ui (y, 0) == 0 && MPFR_IS_POS (y));
69
70  mpfr_set_inf (x, -1); /* -Inf */
71  mpfr_yn (y, 17, x, MPFR_RNDN);
72  MPFR_ASSERTN(mpfr_nan_p (y));
73
74  mpfr_set_ui (x, 0, MPFR_RNDN); /* +0 */
75  mpfr_yn (y, 0, x, MPFR_RNDN);
76  MPFR_ASSERTN(mpfr_inf_p (y) && MPFR_IS_NEG (y)); /* y0(+0)=-Inf */
77  mpfr_yn (y, 17, x, MPFR_RNDN);
78  MPFR_ASSERTN(mpfr_inf_p (y) && MPFR_IS_NEG (y)); /* y17(+0)=-Inf */
79  mpfr_yn (y, -17, x, MPFR_RNDN);
80  MPFR_ASSERTN(mpfr_inf_p (y) && MPFR_IS_POS (y)); /* y(-17,+0)=+Inf */
81  mpfr_yn (y, -42, x, MPFR_RNDN);
82  MPFR_ASSERTN(mpfr_inf_p (y) && MPFR_IS_NEG (y)); /* y(-42,+0)=-Inf */
83
84  mpfr_set_ui (x, 0, MPFR_RNDN);
85  mpfr_neg (x, x, MPFR_RNDN); /* -0 */
86  mpfr_yn (y, 0, x, MPFR_RNDN);
87  MPFR_ASSERTN(mpfr_inf_p (y) && MPFR_IS_NEG (y)); /* y0(-0)=-Inf */
88  mpfr_yn (y, 17, x, MPFR_RNDN);
89  MPFR_ASSERTN(mpfr_inf_p (y) && MPFR_IS_NEG (y)); /* y17(-0)=-Inf */
90  mpfr_yn (y, -17, x, MPFR_RNDN);
91  MPFR_ASSERTN(mpfr_inf_p (y) && MPFR_IS_POS (y)); /* y(-17,-0)=+Inf */
92  mpfr_yn (y, -42, x, MPFR_RNDN);
93  MPFR_ASSERTN(mpfr_inf_p (y) && MPFR_IS_NEG (y)); /* y(-42,-0)=-Inf */
94
95  mpfr_set_prec (x, 53);
96  mpfr_set_prec (y, 53);
97
98  mpfr_set_ui (x, 1, MPFR_RNDN);
99  mpfr_yn (y, 0, x, MPFR_RNDN);
100  mpfr_set_str_binary (x, "0.00010110100110000000001000100110111100110101100011011111");
101  if (mpfr_cmp (x, y))
102    {
103      printf ("Error in mpfr_yn for n=0, x=1, rnd=MPFR_RNDN\n");
104      printf ("Expected "); mpfr_dump (x);
105      printf ("Got      "); mpfr_dump (y);
106      exit (1);
107    }
108
109  mpfr_set_ui (x, 1, MPFR_RNDN);
110  mpfr_yn (y, 1, x, MPFR_RNDN);
111  mpfr_set_str_binary (x, "-0.110001111111110110010000001111101011001101011100101");
112  if (mpfr_cmp (x, y))
113    {
114      printf ("Error in mpfr_yn for n=1, x=1, rnd=MPFR_RNDN\n");
115      printf ("Expected "); mpfr_dump (x);
116      printf ("Got      "); mpfr_dump (y);
117      exit (1);
118    }
119
120  mpfr_set_ui (x, 1, MPFR_RNDN);
121  mpfr_yn (y, -1, x, MPFR_RNDN);
122  mpfr_set_str_binary (x, "0.110001111111110110010000001111101011001101011100101");
123  if (mpfr_cmp (x, y))
124    {
125      printf ("Error in mpfr_yn for n=-1, x=1, rnd=MPFR_RNDN\n");
126      printf ("Expected "); mpfr_dump (x);
127      printf ("Got      "); mpfr_dump (y);
128      exit (1);
129    }
130
131  mpfr_set_ui (x, 1, MPFR_RNDN);
132  mpfr_yn (y, 2, x, MPFR_RNDN);
133  mpfr_set_str_binary (x, "-1.101001101001001100100010101001000101101000010010001");
134  if (mpfr_cmp (x, y))
135    {
136      printf ("Error in mpfr_yn for n=2, x=1, rnd=MPFR_RNDN\n");
137      printf ("Expected "); mpfr_dump (x);
138      printf ("Got      "); mpfr_dump (y);
139      exit (1);
140    }
141
142  mpfr_set_ui (x, 1, MPFR_RNDN);
143  mpfr_yn (y, -2, x, MPFR_RNDN);
144  mpfr_set_str_binary (x, "-1.101001101001001100100010101001000101101000010010001");
145  if (mpfr_cmp (x, y))
146    {
147      printf ("Error in mpfr_yn for n=-2, x=1, rnd=MPFR_RNDN\n");
148      printf ("Expected "); mpfr_dump (x);
149      printf ("Got      "); mpfr_dump (y);
150      exit (1);
151    }
152
153  mpfr_set_ui (x, 1, MPFR_RNDN);
154  mpfr_yn (y, 17, x, MPFR_RNDN);
155  mpfr_set_str_binary (x, "-0.11000100111000100010101101011000110011001101100001011E60");
156  if (mpfr_cmp (x, y))
157    {
158      printf ("Error in mpfr_yn for n=17, x=1, rnd=MPFR_RNDN\n");
159      printf ("Expected "); mpfr_dump (x);
160      printf ("Got      "); mpfr_dump (y);
161      exit (1);
162    }
163
164  mpfr_set_ui (x, 1, MPFR_RNDN);
165  mpfr_yn (y, -17, x, MPFR_RNDN);
166  mpfr_set_str_binary (x, "0.11000100111000100010101101011000110011001101100001011E60");
167  if (mpfr_cmp (x, y))
168    {
169      printf ("Error in mpfr_yn for n=-17, x=1, rnd=MPFR_RNDN\n");
170      printf ("Expected "); mpfr_dump (x);
171      printf ("Got      "); mpfr_dump (y);
172      exit (1);
173    }
174
175  mpfr_set_ui (x, 17, MPFR_RNDN);
176  mpfr_yn (y, 1, x, MPFR_RNDN);
177  mpfr_set_str_binary (x, "0.00101010110011011111001100000001101011011001111111");
178  if (mpfr_cmp (x, y))
179    {
180      printf ("Error in mpfr_yn for n=1, x=17, rnd=MPFR_RNDN\n");
181      printf ("Expected "); mpfr_dump (x);
182      printf ("Got      "); mpfr_dump (y);
183      exit (1);
184    }
185
186 end:
187  mpfr_clear (x);
188  mpfr_clear (y);
189
190  tests_end_mpfr ();
191  return 0;
192}
193