xref: /netbsd-src/external/lgpl3/mpc/dist/tests/tcosh.c (revision 39f28e1e142c5bfb6be935a49cb55e2287fec7ea)
1 /* tcosh -- test file for mpc_cosh.
2 
3 Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013 INRIA
4 
5 This file is part of GNU MPC.
6 
7 GNU MPC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15 more details.
16 
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program. If not, see http://www.gnu.org/licenses/ .
19 */
20 
21 #include <stdlib.h>
22 #include "mpc-tests.h"
23 
24 static void
pure_real_argument(void)25 pure_real_argument (void)
26 {
27   /* cosh(x -i*0) = cosh(x) +i*0 if x<0 */
28   /* cosh(x -i*0) = cosh(x) -i*0 if x>0 */
29   /* cosh(x +i*0) = cosh(x) -i*0 if x<0 */
30   /* cosh(x -i*0) = cosh(x) +i*0 if x>0 */
31   mpc_t u;
32   mpc_t z;
33   mpc_t cosh_z;
34 
35   mpc_init2 (z, 2);
36   mpc_init2 (u, 100);
37   mpc_init2 (cosh_z, 100);
38 
39   /* cosh(1 +i*0) = cosh(1) +i*0 */
40   mpc_set_ui_ui (z, 1, 0, MPC_RNDNN);
41   mpfr_cosh (mpc_realref (u), mpc_realref (z), MPFR_RNDN);
42   mpfr_set_ui (mpc_imagref (u), 0, MPFR_RNDN);
43   mpc_cosh (cosh_z, z, MPC_RNDNN);
44   if (mpc_cmp (cosh_z, u) != 0 || mpfr_signbit (mpc_imagref (cosh_z)))
45     TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN);
46 
47   /* cosh(1 -i*0) = cosh(1) -i*0 */
48   mpc_conj (z, z, MPC_RNDNN);
49   mpc_conj (u, u, MPC_RNDNN);
50   mpc_cosh (cosh_z, z, MPC_RNDNN);
51   if (mpc_cmp (cosh_z, u) != 0 || !mpfr_signbit (mpc_imagref (cosh_z)))
52     TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN);
53 
54   /* cosh(-1 +i*0) = cosh(1) -i*0 */
55   mpc_neg (z, z, MPC_RNDNN);
56   mpc_cosh (cosh_z, z, MPC_RNDNN);
57   if (mpc_cmp (cosh_z, u) != 0 || !mpfr_signbit (mpc_imagref (cosh_z)))
58     TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN);
59 
60   /* cosh(-1 -i*0) = cosh(1) +i*0 */
61   mpc_conj (z, z, MPC_RNDNN);
62   mpc_conj (u, u, MPC_RNDNN);
63   mpc_cosh (cosh_z, z, MPC_RNDNN);
64   if (mpc_cmp (cosh_z, u) != 0 || mpfr_signbit (mpc_imagref (cosh_z)))
65     TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN);
66 
67   mpc_clear (cosh_z);
68   mpc_clear (z);
69   mpc_clear (u);
70 }
71 
72 static void
pure_imaginary_argument(void)73 pure_imaginary_argument (void)
74 {
75   /* cosh(+0 +i*y) = cos y +i*0*sin y */
76   /* cosh(-0 +i*y) = cos y -i*0*sin y */
77   mpc_t u;
78   mpc_t z;
79   mpc_t cosh_z;
80 
81   mpc_init2 (z, 2);
82   mpc_init2 (u, 100);
83   mpc_init2 (cosh_z, 100);
84 
85   /* cosh(+0 +i) = cos(1) + i*0 */
86   mpc_set_ui_ui (z, 0, 1, MPC_RNDNN);
87   mpfr_cos (mpc_realref (u), mpc_imagref (z), MPFR_RNDN);
88   mpfr_set_ui (mpc_imagref (u), 0, MPFR_RNDN);
89   mpc_cosh (cosh_z, z, MPC_RNDNN);
90   if (mpc_cmp (cosh_z, u) != 0 || mpfr_signbit (mpc_imagref (cosh_z)))
91     TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN);
92 
93   /* cosh(+0 -i) = cos(1) - i*0 */
94   mpc_conj (z, z, MPC_RNDNN);
95   mpc_conj (u, u, MPC_RNDNN);
96   mpc_cosh (cosh_z, z, MPC_RNDNN);
97   if (mpc_cmp (cosh_z, u) != 0 || !mpfr_signbit (mpc_imagref (cosh_z)))
98     TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN);
99 
100   /* cosh(-0 +i) = cos(1) - i*0 */
101   mpc_neg (z, z, MPC_RNDNN);
102   mpc_cosh (cosh_z, z, MPC_RNDNN);
103   if (mpc_cmp (cosh_z, u) != 0 || !mpfr_signbit (mpc_imagref (cosh_z)))
104     TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN);
105 
106   /* cosh(-0 -i) = cos(1) + i*0 */
107   mpc_conj (z, z, MPC_RNDNN);
108   mpc_conj (u, u, MPC_RNDNN);
109   mpc_cosh (cosh_z, z, MPC_RNDNN);
110   if (mpc_cmp (cosh_z, u) != 0 || mpfr_signbit (mpc_imagref (cosh_z)))
111     TEST_FAILED ("mpc_cosh", z, cosh_z, u, MPC_RNDNN);
112 
113   mpc_clear (cosh_z);
114   mpc_clear (z);
115   mpc_clear (u);
116 }
117 
118 #define MPC_FUNCTION_CALL                                       \
119   P[0].mpc_inex = mpc_cosh (P[1].mpc, P[2].mpc, P[3].mpc_rnd)
120 #define MPC_FUNCTION_CALL_REUSE_OP1                             \
121   P[0].mpc_inex = mpc_cosh (P[1].mpc, P[1].mpc, P[3].mpc_rnd)
122 
123 #include "data_check.tpl"
124 #include "tgeneric.tpl"
125 int
main(void)126 main (void)
127 {
128   test_start ();
129 
130   data_check_template ("cosh.dsc", "cosh.dat");
131 
132   tgeneric_template ("cosh.dsc", 2, 512, 7, 7);
133 
134   /* FIXME: remove the following tests? (Now tested by tgeneric) */
135   pure_real_argument ();
136   pure_imaginary_argument ();
137 
138   test_end ();
139 
140   return 0;
141 }
142