1/* Test file for mpfr_ai.
2
3Copyright 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#include <limits.h>
26
27#include "mpfr-test.h"
28
29#define TEST_FUNCTION mpfr_ai
30#define TEST_RANDOM_EMIN -5
31#define TEST_RANDOM_EMAX 5
32#define REDUCE_EMAX 7 /* this is to avoid that test_generic() calls mpfr_ai
33                         with too large inputs. FIXME: remove this once
34                         mpfr_ai can handle large inputs */
35#include "tgeneric.c"
36
37static void
38check_large (void)
39{
40  mpfr_t x, y, z;
41
42  mpfr_init2 (x, 38);
43  mpfr_init2 (y, 110);
44  mpfr_init2 (z, 110);
45  mpfr_set_str_binary (x, "-1E8");
46  mpfr_ai (y, x, MPFR_RNDN);
47  mpfr_set_str_binary (z, "-10001110100001011111110001100011101100011100010000110100100101011111011100000101110101010010000000101110011111E-112");
48  if (mpfr_equal_p (y, z) == 0)
49    {
50      printf ("Error in mpfr_ai for x=-2^8\n");
51      exit (1);
52    }
53#if 0 /* disabled since mpfr_ai does not currently handle large arguments */
54  mpfr_set_str_binary (x, "-1E26");
55  mpfr_ai (y, x, MPFR_RNDN);
56  mpfr_set_str_binary (z, "-110001111100000011001010010101001101001011001011101011001010100100001110001101101101000010000011001000001011E-118");
57  if (mpfr_equal_p (y, z) == 0)
58    {
59      printf ("Error in mpfr_ai for x=-2^26\n");
60      exit (1);
61    }
62  mpfr_set_str_binary (x, "-0.11111111111111111111111111111111111111E1073741823");
63  mpfr_ai (y, x, MPFR_RNDN);
64  /* FIXME: compute the correctly rounded value we should get for Ai(x),
65     and check we get this value */
66#endif
67  mpfr_clear (x);
68  mpfr_clear (y);
69  mpfr_clear (z);
70}
71
72int
73main (int argc, char *argv[])
74{
75  tests_start_mpfr ();
76
77  check_large ();
78
79  test_generic (2, 100, 5);
80
81  tests_end_mpfr ();
82  return 0;
83}
84