blob: 8ddd28bbf8744f4321e81bda9da1f095f8c79f40 [file] [log] [blame]
Elliott Hughesb8ee16f2014-11-06 11:16:55 -08001/*
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
Josh Gaoff504e62016-04-29 11:52:39 -070019// 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#endif
25
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080026// libc++ actively gets in the way of including <complex.h> from C++, so we
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080027// have to be naughty.
Elliott Hughesafe835d2016-04-02 08:36:33 -070028#include <../libc/include/complex.h>
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080029
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080030// (libc++ also seems to have really bad implementations of its own that ignore
31// the intricacies of floating point math.)
32// http://llvm.org/bugs/show_bug.cgi?id=21504
33
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080034#include <math.h> // For M_PI_2/M_PI_2l.
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080035
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080036// Note that gtest doesn't support complex numbers, so the output from
37// assertion failures is misleading/useless (at best you'll only see the real
38// part).
39// TODO: find out why gtest doesn't use these; until then they're only useful
40// for manual printf^Woperator<< debugging.
41#include <iostream>
42std::ostream& operator<<(std::ostream& os, const double _Complex c) {
43 os << "(" << creal(c) << "," << cimag(c) << "i)";
44 return os;
45}
46std::ostream& operator<<(std::ostream& os, const float _Complex c) {
47 os << "(" << crealf(c) << "," << cimagf(c) << "i)";
48 return os;
49}
50std::ostream& operator<<(std::ostream& os, const long double _Complex c) {
51 os << "(" << creall(c) << "," << cimagl(c) << "i)";
52 return os;
53}
54
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080055TEST(complex, cabs) {
56 ASSERT_EQ(0.0, cabs(0));
57}
58
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080059TEST(complex, cabsf) {
60 ASSERT_EQ(0.0, cabsf(0));
61}
62
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080063TEST(complex, cabsl) {
64 ASSERT_EQ(0.0, cabsl(0));
65}
66
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080067TEST(complex, cacos) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080068 ASSERT_EQ(M_PI_2, cacos(0.0));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080069}
70
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080071TEST(complex, cacosf) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080072 ASSERT_EQ(static_cast<float>(M_PI_2), cacosf(0.0));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080073}
74
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080075TEST(complex, cacosl) {
76 ASSERT_EQ(M_PI_2l, cacosl(0.0));
77}
78
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080079TEST(complex, cacosh) {
80 ASSERT_EQ(0.0, cacosh(1.0));
81}
82
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080083TEST(complex, cacoshl) {
84 ASSERT_EQ(0.0, cacoshl(1.0));
85}
86
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080087TEST(complex, cacoshf) {
88 ASSERT_EQ(0.0, cacoshf(1.0));
89}
90
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080091TEST(complex, carg) {
92 ASSERT_EQ(0.0, carg(0));
93}
94
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080095TEST(complex, cargf) {
96 ASSERT_EQ(0.0, cargf(0));
97}
98
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080099TEST(complex, cargl) {
100 ASSERT_EQ(0.0, cargl(0));
101}
102
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800103TEST(complex, casin) {
104 ASSERT_EQ(0.0, casin(0));
105}
106
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800107TEST(complex, casinf) {
108 ASSERT_EQ(0.0, casinf(0));
109}
110
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800111TEST(complex, casinl) {
112 ASSERT_EQ(0.0, casinl(0));
113}
114
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800115TEST(complex, casinh) {
116 ASSERT_EQ(0.0, casinh(0));
117}
118
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800119TEST(complex, casinhf) {
120 ASSERT_EQ(0.0, casinhf(0));
121}
122
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800123TEST(complex, casinhl) {
124 ASSERT_EQ(0.0, casinhl(0));
125}
126
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800127TEST(complex, catan) {
128 ASSERT_EQ(0.0, catan(0));
129}
130
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800131TEST(complex, catanf) {
132 ASSERT_EQ(0.0, catanf(0));
133}
134
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800135TEST(complex, catanl) {
136 ASSERT_EQ(0.0, catanl(0));
137}
138
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800139TEST(complex, catanh) {
140 ASSERT_EQ(0.0, catanh(0));
141}
142
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800143TEST(complex, catanhf) {
144 ASSERT_EQ(0.0, catanhf(0));
145}
146
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800147TEST(complex, catanhl) {
148 ASSERT_EQ(0.0, catanhl(0));
149}
150
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800151TEST(complex, ccos) {
152 ASSERT_EQ(1.0, ccos(0));
153}
154
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800155TEST(complex, ccosf) {
156 ASSERT_EQ(1.0, ccosf(0));
157}
158
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800159TEST(complex, ccosl) {
160 ASSERT_EQ(1.0, ccosl(0));
161}
162
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800163TEST(complex, ccosh) {
164 ASSERT_EQ(1.0, ccosh(0));
165}
166
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800167TEST(complex, ccoshf) {
168 ASSERT_EQ(1.0, ccoshf(0));
169}
170
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800171TEST(complex, ccoshl) {
172 ASSERT_EQ(1.0, ccoshl(0));
173}
174
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800175TEST(complex, cexp) {
176 ASSERT_EQ(1.0, cexp(0));
177}
178
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800179TEST(complex, cexpf) {
180 ASSERT_EQ(1.0, cexpf(0));
181}
182
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800183TEST(complex, cexpl) {
184 ASSERT_EQ(1.0, cexpl(0));
185}
186
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800187TEST(complex, cimag) {
188 ASSERT_EQ(0.0, cimag(0));
189}
190
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800191TEST(complex, cimagf) {
192 ASSERT_EQ(0.0f, cimagf(0));
193}
194
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800195TEST(complex, cimagl) {
196 ASSERT_EQ(0.0, cimagl(0));
197}
198
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800199TEST(complex, clog) {
200 ASSERT_EQ(0.0, clog(1.0));
201}
202
203TEST(complex, clogf) {
204 ASSERT_EQ(0.0f, clogf(1.0f));
205}
206
207TEST(complex, clogl) {
208 ASSERT_EQ(0.0L, clogl(1.0L));
209}
210
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800211TEST(complex, conj) {
212 ASSERT_EQ(0.0, conj(0));
213}
214
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800215TEST(complex, conjf) {
216 ASSERT_EQ(0.0f, conjf(0));
217}
218
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800219TEST(complex, conjl) {
220 ASSERT_EQ(0.0, conjl(0));
221}
222
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800223TEST(complex, cpow) {
224 ASSERT_EQ(8.0, cpow(2.0, 3.0));
225}
226
227TEST(complex, cpowf) {
228 ASSERT_EQ(8.0f, cpowf(2.0f, 3.0f));
229}
230
231TEST(complex, cpowl) {
232 ASSERT_EQ(8.0L, cpowl(2.0L, 3.0L));
233}
234
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800235TEST(complex, cproj) {
236 ASSERT_EQ(0.0, cproj(0));
237}
238
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800239TEST(complex, cprojf) {
240 ASSERT_EQ(0.0f, cprojf(0));
241}
242
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800243TEST(complex, cprojl) {
244 ASSERT_EQ(0.0, cprojl(0));
245}
246
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800247TEST(complex, creal) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800248 ASSERT_EQ(2.0, creal(2.0 + 3.0I));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800249}
250
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800251TEST(complex, crealf) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800252 ASSERT_EQ(2.0f, crealf(2.0f + 3.0fI));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800253}
254
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800255TEST(complex, creall) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800256 ASSERT_EQ(2.0, creall(2.0L + 3.0LI));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800257}
258
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800259TEST(complex, csin) {
260 ASSERT_EQ(0.0, csin(0));
261}
262
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800263TEST(complex, csinf) {
264 ASSERT_EQ(0.0, csinf(0));
265}
266
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800267TEST(complex, csinl) {
268 ASSERT_EQ(0.0, csinl(0));
269}
270
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800271TEST(complex, csinh) {
272 ASSERT_EQ(0.0, csinh(0));
273}
274
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800275TEST(complex, csinhf) {
276 ASSERT_EQ(0.0, csinhf(0));
277}
278
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800279TEST(complex, csinhl) {
280 ASSERT_EQ(0.0, csinhl(0));
281}
282
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800283TEST(complex, csqrt) {
284 ASSERT_EQ(0.0, csqrt(0));
285}
286
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800287TEST(complex, csqrtf) {
288 ASSERT_EQ(0.0f, csqrt(0));
289}
290
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800291TEST(complex, csqrtl) {
292 ASSERT_EQ(0.0, csqrtl(0));
293}
294
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800295TEST(complex, ctan) {
296 ASSERT_EQ(0.0, ctan(0));
297}
298
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800299TEST(complex, ctanf) {
300 ASSERT_EQ(0.0, ctanf(0));
301}
302
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800303TEST(complex, ctanl) {
304 ASSERT_EQ(0.0, ctanl(0));
305}
306
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800307TEST(complex, ctanh) {
308 ASSERT_EQ(0.0, ctanh(0));
309}
310
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800311TEST(complex, ctanhf) {
312 ASSERT_EQ(0.0, ctanhf(0));
313}
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800314
315TEST(complex, ctanhl) {
316 ASSERT_EQ(0.0, ctanhl(0));
317}