xref: /netbsd-src/external/lgpl3/mpfr/dist/tests/tasinh.c (revision 4391d5e9d4f291db41e3b3ba26a01b5e51364aae)
1 /* Test file for mpfr_asinh.
2 
3 Copyright 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4 Contributed by the Arenaire and Cacao 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 http://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 <stdio.h>
24 #include <stdlib.h>
25 
26 #include "mpfr-test.h"
27 
28 #define TEST_FUNCTION mpfr_asinh
29 #include "tgeneric.c"
30 
31 static void
32 special (void)
33 {
34   mpfr_t x, y, z;
35 
36   mpfr_init (x);
37   mpfr_init (y);
38 
39   MPFR_SET_INF(x);
40   mpfr_set_ui (y, 1, MPFR_RNDN);
41   mpfr_asinh (x, y, MPFR_RNDN);
42   if (MPFR_IS_INF(x) || MPFR_IS_NAN(x) )
43     {
44       printf ("Inf flag not clears in asinh!\n");
45       exit (1);
46     }
47 
48   MPFR_SET_NAN(x);
49   mpfr_asinh (x, y, MPFR_RNDN);
50   if (MPFR_IS_NAN(x) || MPFR_IS_INF(x))
51     {
52       printf ("NAN flag not clears in asinh!\n");
53       exit (1);
54     }
55 
56   /* asinh(+0) = +0, asinh(-0) = -0 */
57   mpfr_set_ui (x, 0, MPFR_RNDN);
58   mpfr_asinh (y, x, MPFR_RNDN);
59   if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) < 0)
60     {
61       printf ("Error: mpfr_asinh(+0) <> +0\n");
62       exit (1);
63     }
64   mpfr_neg (x, x, MPFR_RNDN);
65   mpfr_asinh (y, x, MPFR_RNDN);
66   if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) > 0)
67     {
68       printf ("Error: mpfr_asinh(-0) <> -0\n");
69       exit (1);
70     }
71 
72   MPFR_SET_NAN(x);
73   mpfr_asinh (y, x, MPFR_RNDN);
74   if (!mpfr_nan_p (y))
75     {
76       printf ("Error: mpfr_asinh(NaN) <> NaN\n");
77       exit (1);
78     }
79 
80   mpfr_set_inf (x, 1);
81   mpfr_asinh (y, x, MPFR_RNDN);
82   if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0)
83     {
84       printf ("Error: mpfr_asinh(+Inf) <> +Inf\n");
85       exit (1);
86     }
87 
88   mpfr_set_inf (x, -1);
89   mpfr_asinh (y, x, MPFR_RNDN);
90   if (!mpfr_inf_p (y) || mpfr_sgn (y) > 0)
91     {
92       printf ("Error: mpfr_asinh(-Inf) <> -Inf\n");
93       exit (1);
94     }
95 
96   mpfr_set_prec (x, 32);
97   mpfr_set_prec (y, 32);
98 
99   mpfr_set_str_binary (x, "0.1010100100111011001111100101E-1");
100   mpfr_asinh (x, x, MPFR_RNDN);
101   mpfr_set_str_binary (y, "0.10100110010010101101010011011101E-1");
102   if (!mpfr_equal_p (x, y))
103     {
104       printf ("Error: mpfr_asinh (1)\n");
105       exit (1);
106     }
107 
108   mpfr_set_str_binary (x, "-.10110011011010111110010001100001");
109   mpfr_asinh (x, x, MPFR_RNDN);
110   mpfr_set_str_binary (y, "-.10100111010000111001011100110011");
111   if (!mpfr_equal_p (x, y))
112     {
113       printf ("Error: mpfr_asinh (2)\n");
114       exit (1);
115     }
116 
117   mpfr_set_prec (x, 33);
118   mpfr_set_prec (y, 43);
119   mpfr_set_str_binary (x, "0.111001101100000110011001010000101");
120   mpfr_asinh (y, x, MPFR_RNDZ);
121   mpfr_init2 (z, 43);
122   mpfr_set_str_binary (z, "0.1100111101010101101010101110000001000111001");
123   if (!mpfr_equal_p (y, z))
124     {
125       printf ("Error: mpfr_asinh (3)\n");
126       exit (1);
127     }
128 
129   mpfr_set_prec (x, 53);
130   mpfr_set_prec (y, 2);
131   mpfr_set_str (x, "1.8000000000009@-6", 16, MPFR_RNDN);
132   mpfr_asinh (y, x, MPFR_RNDZ);
133   mpfr_set_prec (z, 2);
134   mpfr_set_str (z, "1.0@-6", 16, MPFR_RNDN);
135   if (!mpfr_equal_p (y, z))
136     {
137       printf ("Error: mpfr_asinh (4)\n");
138       exit (1);
139     }
140 
141   mpfr_clear (x);
142   mpfr_clear (y);
143   mpfr_clear (z);
144 }
145 
146 int
147 main (int argc, char *argv[])
148 {
149   tests_start_mpfr ();
150 
151   special ();
152 
153   test_generic (2, 100, 25);
154 
155   data_check ("data/asinh", mpfr_asinh, "mpfr_asinh");
156   bad_cases (mpfr_asinh, mpfr_sinh, "mpfr_asinh", 256, -128, 29,
157              4, 128, 800, 40);
158 
159   tests_end_mpfr ();
160   return 0;
161 }
162