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