1/* tj0 -- test file for the Bessel function of first 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_j0
29#define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), 8, RANDS)
30#define REDUCE_EMAX 262143 /* otherwise arg. reduction is too expensive */
31#include "tgeneric.c"
32
33int
34main (int argc, char *argv[])
35{
36  mpfr_t x, y;
37
38  tests_start_mpfr ();
39
40  mpfr_init (x);
41  mpfr_init (y);
42
43  /* special values */
44  mpfr_set_nan (x);
45  mpfr_j0 (y, x, MPFR_RNDN);
46  MPFR_ASSERTN(mpfr_nan_p (y));
47
48  mpfr_set_inf (x, 1); /* +Inf */
49  mpfr_j0 (y, x, MPFR_RNDN);
50  MPFR_ASSERTN(mpfr_cmp_ui (y, 0) == 0 && MPFR_IS_POS (y));
51
52  mpfr_set_inf (x, -1); /* -Inf */
53  mpfr_j0 (y, x, MPFR_RNDN);
54  MPFR_ASSERTN(mpfr_cmp_ui (y, 0) == 0 && MPFR_IS_POS (y));
55
56  mpfr_set_ui (x, 0, MPFR_RNDN); /* +0 */
57  mpfr_j0 (y, x, MPFR_RNDN);
58  MPFR_ASSERTN(mpfr_cmp_ui (y, 1) == 0); /* j0(+0)=1 */
59
60  mpfr_set_ui (x, 0, MPFR_RNDN);
61  mpfr_neg (x, x, MPFR_RNDN); /* -0 */
62  mpfr_j0 (y, x, MPFR_RNDN);
63  MPFR_ASSERTN(mpfr_cmp_ui (y, 1) == 0); /* j0(-0)=1 */
64
65  mpfr_set_prec (x, 53);
66  mpfr_set_prec (y, 53);
67
68  mpfr_set_ui (x, 1, MPFR_RNDN);
69  mpfr_j0 (y, x, MPFR_RNDN);
70  mpfr_set_str_binary (x, "0.1100001111100011111111101101111010111101110001111");
71  if (mpfr_cmp (x, y))
72    {
73      printf ("Error in mpfr_j0 for x=1, rnd=MPFR_RNDN\n");
74      printf ("Expected "); mpfr_dump (x);
75      printf ("Got      "); mpfr_dump (y);
76      exit (1);
77    }
78
79  mpfr_set_si (x, -1, MPFR_RNDN);
80  mpfr_j0 (y, x, MPFR_RNDN);
81  mpfr_set_str_binary (x, "0.1100001111100011111111101101111010111101110001111");
82  if (mpfr_cmp (x, y))
83    {
84      printf ("Error in mpfr_j0 for x=-1, rnd=MPFR_RNDN\n");
85      printf ("Expected "); mpfr_dump (x);
86      printf ("Got      "); mpfr_dump (y);
87      exit (1);
88    }
89
90  /* Bug reported on 2007-07-03 by Sisyphus (assertion failed in r4619) */
91  mpfr_set_si (x, 70000, MPFR_RNDN);
92  mpfr_j0 (y, x, MPFR_RNDN);
93
94  /* Bug reported by Kevin Rauch on 27 Oct 2007 */
95  mpfr_set_prec (x, 7);
96  mpfr_set_prec (y, 7);
97  mpfr_set_si (x, -100, MPFR_RNDN);
98  mpfr_j0 (y, x, MPFR_RNDN);
99  MPFR_ASSERTN (! mpfr_nan_p (y) && mpfr_cmp_ui_2exp (y, 41, -11) == 0);
100
101  mpfr_clear (x);
102  mpfr_clear (y);
103
104  test_generic (2, 100, 10);
105
106  data_check ("data/j0", mpfr_j0, "mpfr_j0");
107
108  tests_end_mpfr ();
109
110  return 0;
111}
112