Import Upstream version 0.8.2
[platform/upstream/mpc.git] / tests / tcosh.c
1 /* test file for mpc_cosh.
2
3 Copyright (C) 2008, 2009 Philippe Th\'eveny, Paul Zimmermann, Andreas Enge
4
5 This file is part of the MPC Library.
6
7 The MPC Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or (at your
10 option) any later version.
11
12 The MPC Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15 License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with the MPC Library; see the file COPYING.LIB.  If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 MA 02111-1307, USA. */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include "mpc-tests.h"
25
26 static void
27 test_failed (mpc_t op, mpc_t get, mpc_t expected)
28 {
29   printf ("mpc_cosh(op) failed\n with ");
30   OUT (op);
31   printf ("     ");
32   OUT (get);
33   OUT (expected);
34   exit (1);
35 }
36
37 static void
38 pure_real_argument (void)
39 {
40   /* cosh(x -i*0) = cosh(x) +i*0 if x<0 */
41   /* cosh(x -i*0) = cosh(x) -i*0 if x>0 */
42   /* cosh(x +i*0) = cosh(x) -i*0 if x<0 */
43   /* cosh(x -i*0) = cosh(x) +i*0 if x>0 */
44   mpc_t u;
45   mpc_t z;
46   mpc_t cosh_z;
47
48   mpc_init2 (z, 2);
49   mpc_init2 (u, 100);
50   mpc_init2 (cosh_z, 100);
51
52   /* cosh(1 +i*0) = cosh(1) +i*0 */
53   mpc_set_ui_ui (z, 1, 0, MPC_RNDNN);
54   mpfr_cosh (MPC_RE (u), MPC_RE (z), GMP_RNDN);
55   mpfr_set_ui (MPC_IM (u), 0, GMP_RNDN);
56   mpc_cosh (cosh_z, z, MPC_RNDNN);
57   if (mpc_cmp (cosh_z, u) != 0 || mpfr_signbit (MPC_IM (cosh_z)))
58     test_failed (z, cosh_z, u);
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_IM (cosh_z)))
65     test_failed (z, cosh_z, u);
66
67   /* cosh(-1 +i*0) = cosh(1) -i*0 */
68   mpc_neg (z, z, MPC_RNDNN);
69   mpc_cosh (cosh_z, z, MPC_RNDNN);
70   if (mpc_cmp (cosh_z, u) != 0 || !mpfr_signbit (MPC_IM (cosh_z)))
71     test_failed (z, cosh_z, u);
72
73   /* cosh(-1 -i*0) = cosh(1) +i*0 */
74   mpc_conj (z, z, MPC_RNDNN);
75   mpc_conj (u, u, MPC_RNDNN);
76   mpc_cosh (cosh_z, z, MPC_RNDNN);
77   if (mpc_cmp (cosh_z, u) != 0 || mpfr_signbit (MPC_IM (cosh_z)))
78     test_failed (z, cosh_z, u);
79
80   mpc_clear (cosh_z);
81   mpc_clear (z);
82   mpc_clear (u);
83 }
84
85 static void
86 pure_imaginary_argument (void)
87 {
88   /* cosh(+0 +i*y) = cos y +i*0*sin y */
89   /* cosh(-0 +i*y) = cos y -i*0*sin y */
90   mpc_t u;
91   mpc_t z;
92   mpc_t cosh_z;
93
94   mpc_init2 (z, 2);
95   mpc_init2 (u, 100);
96   mpc_init2 (cosh_z, 100);
97
98   /* cosh(+0 +i) = cos(1) +i*0 */
99   mpc_set_ui_ui (z, 0, 1, MPC_RNDNN);
100   mpfr_cos (MPC_RE (u), MPC_IM (z), GMP_RNDN);
101   mpfr_set_ui (MPC_IM (u), 0, GMP_RNDN);
102   mpc_cosh (cosh_z, z, MPC_RNDNN);
103   if (mpc_cmp (cosh_z, u) != 0 || mpfr_signbit (MPC_IM (cosh_z)))
104     test_failed (z, cosh_z, u);
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_IM (cosh_z)))
111     test_failed (z, cosh_z, u);
112
113   /* cosh(-0 +i) = cos(1) -i*0 */
114   mpc_neg (z, z, MPC_RNDNN);
115   mpc_cosh (cosh_z, z, MPC_RNDNN);
116   if (mpc_cmp (cosh_z, u) != 0 || !mpfr_signbit (MPC_IM (cosh_z)))
117     test_failed (z, cosh_z, u);
118
119   /* cosh(-0 -i) = cos(1) +i*0 */
120   mpc_conj (z, z, MPC_RNDNN);
121   mpc_conj (u, u, MPC_RNDNN);
122   mpc_cosh (cosh_z, z, MPC_RNDNN);
123   if (mpc_cmp (cosh_z, u) != 0 || mpfr_signbit (MPC_IM (cosh_z)))
124     test_failed (z, cosh_z, u);
125
126   mpc_clear (cosh_z);
127   mpc_clear (z);
128   mpc_clear (u);
129 }
130
131 int
132 main (void)
133 {
134   DECL_FUNC(CC, f,mpc_cosh);
135
136   test_start ();
137
138   data_check (f, "cosh.dat");
139   tgeneric (f, 2, 512, 7, 7);
140
141   pure_real_argument ();
142   pure_imaginary_argument ();
143
144   test_end ();
145
146   return 0;
147 }