complex_test.cpp revision b2ca03140da5d7d4e3897287d8e8b05355a837f9
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18
19// This file is compiled against both glibc and bionic, and our complex.h
20// depends on bionic-specific macros, so hack around that.
21#include <sys/cdefs.h>
22#if !defined(__INTRODUCED_IN)
23#define __INTRODUCED_IN(x)
24#define __INTRODUCED_IN_32(x)
25#define __INTRODUCED_IN_64(x)
26#define __INTRODUCED_IN_FUTURE
27#endif
28
29// libc++ actively gets in the way of including <complex.h> from C++, so we
30// have to be naughty.
31#include "../libc/include/complex.h"
32
33// (libc++ also seems to have really bad implementations of its own that ignore
34// the intricacies of floating point math.)
35// http://llvm.org/bugs/show_bug.cgi?id=21504
36
37#include <math.h> // For M_PI_2/M_PI_2l.
38
39// Note that gtest doesn't support complex numbers, so the output from
40// assertion failures is misleading/useless (at best you'll only see the real
41// part).
42// TODO: find out why gtest doesn't use these; until then they're only useful
43// for manual printf^Woperator<< debugging.
44#include <iostream>
45std::ostream& operator<<(std::ostream& os, const double _Complex c) {
46  os << "(" << creal(c) << "," << cimag(c) << "i)";
47 return os;
48}
49std::ostream& operator<<(std::ostream& os, const float _Complex c) {
50  os << "(" << crealf(c) << "," << cimagf(c) << "i)";
51  return os;
52}
53std::ostream& operator<<(std::ostream& os, const long double _Complex c) {
54  os << "(" << creall(c) << "," << cimagl(c) << "i)";
55  return os;
56}
57
58TEST(complex, cabs) {
59  ASSERT_EQ(0.0, cabs(0));
60}
61
62TEST(complex, cabsf) {
63  ASSERT_EQ(0.0, cabsf(0));
64}
65
66TEST(complex, cabsl) {
67  ASSERT_EQ(0.0, cabsl(0));
68}
69
70TEST(complex, cacos) {
71  ASSERT_EQ(M_PI_2, cacos(0.0));
72}
73
74TEST(complex, cacosf) {
75  ASSERT_EQ(static_cast<float>(M_PI_2), cacosf(0.0));
76}
77
78TEST(complex, cacosl) {
79  ASSERT_EQ(M_PI_2l, cacosl(0.0));
80}
81
82TEST(complex, cacosh) {
83  ASSERT_EQ(0.0, cacosh(1.0));
84}
85
86TEST(complex, cacoshl) {
87  ASSERT_EQ(0.0, cacoshl(1.0));
88}
89
90TEST(complex, cacoshf) {
91  ASSERT_EQ(0.0, cacoshf(1.0));
92}
93
94TEST(complex, carg) {
95  ASSERT_EQ(0.0, carg(0));
96}
97
98TEST(complex, cargf) {
99  ASSERT_EQ(0.0, cargf(0));
100}
101
102TEST(complex, cargl) {
103  ASSERT_EQ(0.0, cargl(0));
104}
105
106TEST(complex, casin) {
107  ASSERT_EQ(0.0, casin(0));
108}
109
110TEST(complex, casinf) {
111  ASSERT_EQ(0.0, casinf(0));
112}
113
114TEST(complex, casinl) {
115  ASSERT_EQ(0.0, casinl(0));
116}
117
118TEST(complex, casinh) {
119  ASSERT_EQ(0.0, casinh(0));
120}
121
122TEST(complex, casinhf) {
123  ASSERT_EQ(0.0, casinhf(0));
124}
125
126TEST(complex, casinhl) {
127  ASSERT_EQ(0.0, casinhl(0));
128}
129
130TEST(complex, catan) {
131  ASSERT_EQ(0.0, catan(0));
132}
133
134TEST(complex, catanf) {
135  ASSERT_EQ(0.0, catanf(0));
136}
137
138TEST(complex, catanl) {
139  ASSERT_EQ(0.0, catanl(0));
140}
141
142TEST(complex, catanh) {
143  ASSERT_EQ(0.0, catanh(0));
144}
145
146TEST(complex, catanhf) {
147  ASSERT_EQ(0.0, catanhf(0));
148}
149
150TEST(complex, catanhl) {
151  ASSERT_EQ(0.0, catanhl(0));
152}
153
154TEST(complex, ccos) {
155  ASSERT_EQ(1.0, ccos(0));
156}
157
158TEST(complex, ccosf) {
159  ASSERT_EQ(1.0, ccosf(0));
160}
161
162TEST(complex, ccosl) {
163  ASSERT_EQ(1.0, ccosl(0));
164}
165
166TEST(complex, ccosh) {
167  ASSERT_EQ(1.0, ccosh(0));
168}
169
170TEST(complex, ccoshf) {
171  ASSERT_EQ(1.0, ccoshf(0));
172}
173
174TEST(complex, ccoshl) {
175  ASSERT_EQ(1.0, ccoshl(0));
176}
177
178TEST(complex, cexp) {
179  ASSERT_EQ(1.0, cexp(0));
180}
181
182TEST(complex, cexpf) {
183  ASSERT_EQ(1.0, cexpf(0));
184}
185
186TEST(complex, cexpl) {
187  ASSERT_EQ(1.0, cexpl(0));
188}
189
190TEST(complex, cimag) {
191  ASSERT_EQ(0.0, cimag(0));
192}
193
194TEST(complex, cimagf) {
195  ASSERT_EQ(0.0f, cimagf(0));
196}
197
198TEST(complex, cimagl) {
199  ASSERT_EQ(0.0, cimagl(0));
200}
201
202TEST(complex, clog) {
203  ASSERT_EQ(0.0, clog(1.0));
204}
205
206TEST(complex, clogf) {
207  ASSERT_EQ(0.0f, clogf(1.0f));
208}
209
210TEST(complex, clogl) {
211  ASSERT_EQ(0.0L, clogl(1.0L));
212}
213
214TEST(complex, conj) {
215  ASSERT_EQ(0.0, conj(0));
216}
217
218TEST(complex, conjf) {
219  ASSERT_EQ(0.0f, conjf(0));
220}
221
222TEST(complex, conjl) {
223  ASSERT_EQ(0.0, conjl(0));
224}
225
226TEST(complex, cpow) {
227  ASSERT_EQ(8.0, cpow(2.0, 3.0));
228}
229
230TEST(complex, cpowf) {
231  ASSERT_EQ(8.0f, cpowf(2.0f, 3.0f));
232}
233
234TEST(complex, cpowl) {
235  ASSERT_EQ(8.0L, cpowl(2.0L, 3.0L));
236}
237
238TEST(complex, cproj) {
239  ASSERT_EQ(0.0, cproj(0));
240}
241
242TEST(complex, cprojf) {
243  ASSERT_EQ(0.0f, cprojf(0));
244}
245
246TEST(complex, cprojl) {
247  ASSERT_EQ(0.0, cprojl(0));
248}
249
250TEST(complex, creal) {
251  ASSERT_EQ(2.0, creal(2.0 + 3.0I));
252}
253
254TEST(complex, crealf) {
255  ASSERT_EQ(2.0f, crealf(2.0f + 3.0fI));
256}
257
258TEST(complex, creall) {
259  ASSERT_EQ(2.0, creall(2.0L + 3.0LI));
260}
261
262TEST(complex, csin) {
263  ASSERT_EQ(0.0, csin(0));
264}
265
266TEST(complex, csinf) {
267  ASSERT_EQ(0.0, csinf(0));
268}
269
270TEST(complex, csinl) {
271  ASSERT_EQ(0.0, csinl(0));
272}
273
274TEST(complex, csinh) {
275  ASSERT_EQ(0.0, csinh(0));
276}
277
278TEST(complex, csinhf) {
279  ASSERT_EQ(0.0, csinhf(0));
280}
281
282TEST(complex, csinhl) {
283  ASSERT_EQ(0.0, csinhl(0));
284}
285
286TEST(complex, csqrt) {
287  ASSERT_EQ(0.0, csqrt(0));
288}
289
290TEST(complex, csqrtf) {
291  ASSERT_EQ(0.0f, csqrtf(0));
292}
293
294TEST(complex, csqrtl) {
295  ASSERT_EQ(0.0, csqrtl(0));
296}
297
298TEST(complex, ctan) {
299  ASSERT_EQ(0.0, ctan(0));
300}
301
302TEST(complex, ctanf) {
303  ASSERT_EQ(0.0, ctanf(0));
304}
305
306TEST(complex, ctanl) {
307  ASSERT_EQ(0.0, ctanl(0));
308}
309
310TEST(complex, ctanh) {
311  ASSERT_EQ(0.0, ctanh(0));
312}
313
314TEST(complex, ctanhf) {
315  ASSERT_EQ(0.0, ctanhf(0));
316}
317
318TEST(complex, ctanhl) {
319  ASSERT_EQ(0.0, ctanhl(0));
320}
321