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