blob: 3a5ef7430db5a5ae85402a340af86deadbeec109 [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)
Josh Gao5a3d5ca2016-04-29 12:15:18 -070024#define __INTRODUCED_IN_32(x)
25#define __INTRODUCED_IN_64(x)
Josh Gao34c599a2016-04-29 13:45:25 -070026#define __INTRODUCED_IN_FUTURE
Josh Gaoff504e62016-04-29 11:52:39 -070027#endif
28
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080029// libc++ actively gets in the way of including <complex.h> from C++, so we
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080030// have to be naughty.
Dan Albertb2ca0312017-08-04 15:37:39 -070031#include "../libc/include/complex.h"
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080032
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080033// (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
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080037#include <math.h> // For M_PI_2/M_PI_2l.
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080038
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080039// 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
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080058TEST(complex, cabs) {
59 ASSERT_EQ(0.0, cabs(0));
60}
61
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080062TEST(complex, cabsf) {
63 ASSERT_EQ(0.0, cabsf(0));
64}
65
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080066TEST(complex, cabsl) {
67 ASSERT_EQ(0.0, cabsl(0));
68}
69
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080070TEST(complex, cacos) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080071 ASSERT_EQ(M_PI_2, cacos(0.0));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080072}
73
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080074TEST(complex, cacosf) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080075 ASSERT_EQ(static_cast<float>(M_PI_2), cacosf(0.0));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080076}
77
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080078TEST(complex, cacosl) {
79 ASSERT_EQ(M_PI_2l, cacosl(0.0));
80}
81
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080082TEST(complex, cacosh) {
83 ASSERT_EQ(0.0, cacosh(1.0));
84}
85
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080086TEST(complex, cacoshl) {
87 ASSERT_EQ(0.0, cacoshl(1.0));
88}
89
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080090TEST(complex, cacoshf) {
91 ASSERT_EQ(0.0, cacoshf(1.0));
92}
93
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080094TEST(complex, carg) {
95 ASSERT_EQ(0.0, carg(0));
96}
97
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080098TEST(complex, cargf) {
99 ASSERT_EQ(0.0, cargf(0));
100}
101
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800102TEST(complex, cargl) {
103 ASSERT_EQ(0.0, cargl(0));
104}
105
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800106TEST(complex, casin) {
107 ASSERT_EQ(0.0, casin(0));
108}
109
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800110TEST(complex, casinf) {
111 ASSERT_EQ(0.0, casinf(0));
112}
113
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800114TEST(complex, casinl) {
115 ASSERT_EQ(0.0, casinl(0));
116}
117
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800118TEST(complex, casinh) {
119 ASSERT_EQ(0.0, casinh(0));
120}
121
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800122TEST(complex, casinhf) {
123 ASSERT_EQ(0.0, casinhf(0));
124}
125
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800126TEST(complex, casinhl) {
127 ASSERT_EQ(0.0, casinhl(0));
128}
129
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800130TEST(complex, catan) {
131 ASSERT_EQ(0.0, catan(0));
132}
133
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800134TEST(complex, catanf) {
135 ASSERT_EQ(0.0, catanf(0));
136}
137
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800138TEST(complex, catanl) {
139 ASSERT_EQ(0.0, catanl(0));
140}
141
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800142TEST(complex, catanh) {
143 ASSERT_EQ(0.0, catanh(0));
144}
145
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800146TEST(complex, catanhf) {
147 ASSERT_EQ(0.0, catanhf(0));
148}
149
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800150TEST(complex, catanhl) {
151 ASSERT_EQ(0.0, catanhl(0));
152}
153
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800154TEST(complex, ccos) {
155 ASSERT_EQ(1.0, ccos(0));
156}
157
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800158TEST(complex, ccosf) {
159 ASSERT_EQ(1.0, ccosf(0));
160}
161
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800162TEST(complex, ccosl) {
163 ASSERT_EQ(1.0, ccosl(0));
164}
165
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800166TEST(complex, ccosh) {
167 ASSERT_EQ(1.0, ccosh(0));
168}
169
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800170TEST(complex, ccoshf) {
171 ASSERT_EQ(1.0, ccoshf(0));
172}
173
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800174TEST(complex, ccoshl) {
175 ASSERT_EQ(1.0, ccoshl(0));
176}
177
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800178TEST(complex, cexp) {
179 ASSERT_EQ(1.0, cexp(0));
180}
181
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800182TEST(complex, cexpf) {
183 ASSERT_EQ(1.0, cexpf(0));
184}
185
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800186TEST(complex, cexpl) {
187 ASSERT_EQ(1.0, cexpl(0));
188}
189
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800190TEST(complex, cimag) {
191 ASSERT_EQ(0.0, cimag(0));
192}
193
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800194TEST(complex, cimagf) {
195 ASSERT_EQ(0.0f, cimagf(0));
196}
197
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800198TEST(complex, cimagl) {
199 ASSERT_EQ(0.0, cimagl(0));
200}
201
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800202TEST(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
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800214TEST(complex, conj) {
215 ASSERT_EQ(0.0, conj(0));
216}
217
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800218TEST(complex, conjf) {
219 ASSERT_EQ(0.0f, conjf(0));
220}
221
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800222TEST(complex, conjl) {
223 ASSERT_EQ(0.0, conjl(0));
224}
225
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800226TEST(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
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800238TEST(complex, cproj) {
239 ASSERT_EQ(0.0, cproj(0));
240}
241
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800242TEST(complex, cprojf) {
243 ASSERT_EQ(0.0f, cprojf(0));
244}
245
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800246TEST(complex, cprojl) {
247 ASSERT_EQ(0.0, cprojl(0));
248}
249
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800250TEST(complex, creal) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800251 ASSERT_EQ(2.0, creal(2.0 + 3.0I));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800252}
253
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800254TEST(complex, crealf) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800255 ASSERT_EQ(2.0f, crealf(2.0f + 3.0fI));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800256}
257
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800258TEST(complex, creall) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800259 ASSERT_EQ(2.0, creall(2.0L + 3.0LI));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800260}
261
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800262TEST(complex, csin) {
263 ASSERT_EQ(0.0, csin(0));
264}
265
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800266TEST(complex, csinf) {
267 ASSERT_EQ(0.0, csinf(0));
268}
269
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800270TEST(complex, csinl) {
271 ASSERT_EQ(0.0, csinl(0));
272}
273
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800274TEST(complex, csinh) {
275 ASSERT_EQ(0.0, csinh(0));
276}
277
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800278TEST(complex, csinhf) {
279 ASSERT_EQ(0.0, csinhf(0));
280}
281
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800282TEST(complex, csinhl) {
283 ASSERT_EQ(0.0, csinhl(0));
284}
285
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800286TEST(complex, csqrt) {
287 ASSERT_EQ(0.0, csqrt(0));
288}
289
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800290TEST(complex, csqrtf) {
Elliott Hughese9719f32016-09-26 09:35:04 -0700291 ASSERT_EQ(0.0f, csqrtf(0));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800292}
293
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800294TEST(complex, csqrtl) {
295 ASSERT_EQ(0.0, csqrtl(0));
296}
297
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800298TEST(complex, ctan) {
299 ASSERT_EQ(0.0, ctan(0));
300}
301
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800302TEST(complex, ctanf) {
303 ASSERT_EQ(0.0, ctanf(0));
304}
305
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800306TEST(complex, ctanl) {
307 ASSERT_EQ(0.0, ctanl(0));
308}
309
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800310TEST(complex, ctanh) {
311 ASSERT_EQ(0.0, ctanh(0));
312}
313
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800314TEST(complex, ctanhf) {
315 ASSERT_EQ(0.0, ctanhf(0));
316}
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800317
318TEST(complex, ctanhl) {
319 ASSERT_EQ(0.0, ctanhl(0));
320}