blob: 746c0bed38b3d9ec5fe21a058d59dc0cf75c8244 [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 Gaoff504e62016-04-29 11:52:39 -070026#endif
27
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080028// libc++ actively gets in the way of including <complex.h> from C++, so we
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080029// have to be naughty.
Elliott Hughesafe835d2016-04-02 08:36:33 -070030#include <../libc/include/complex.h>
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080031
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080032// (libc++ also seems to have really bad implementations of its own that ignore
33// the intricacies of floating point math.)
34// http://llvm.org/bugs/show_bug.cgi?id=21504
35
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080036#include <math.h> // For M_PI_2/M_PI_2l.
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080037
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080038// Note that gtest doesn't support complex numbers, so the output from
39// assertion failures is misleading/useless (at best you'll only see the real
40// part).
41// TODO: find out why gtest doesn't use these; until then they're only useful
42// for manual printf^Woperator<< debugging.
43#include <iostream>
44std::ostream& operator<<(std::ostream& os, const double _Complex c) {
45 os << "(" << creal(c) << "," << cimag(c) << "i)";
46 return os;
47}
48std::ostream& operator<<(std::ostream& os, const float _Complex c) {
49 os << "(" << crealf(c) << "," << cimagf(c) << "i)";
50 return os;
51}
52std::ostream& operator<<(std::ostream& os, const long double _Complex c) {
53 os << "(" << creall(c) << "," << cimagl(c) << "i)";
54 return os;
55}
56
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080057TEST(complex, cabs) {
58 ASSERT_EQ(0.0, cabs(0));
59}
60
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080061TEST(complex, cabsf) {
62 ASSERT_EQ(0.0, cabsf(0));
63}
64
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080065TEST(complex, cabsl) {
66 ASSERT_EQ(0.0, cabsl(0));
67}
68
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080069TEST(complex, cacos) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080070 ASSERT_EQ(M_PI_2, cacos(0.0));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080071}
72
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080073TEST(complex, cacosf) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080074 ASSERT_EQ(static_cast<float>(M_PI_2), cacosf(0.0));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080075}
76
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080077TEST(complex, cacosl) {
78 ASSERT_EQ(M_PI_2l, cacosl(0.0));
79}
80
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080081TEST(complex, cacosh) {
82 ASSERT_EQ(0.0, cacosh(1.0));
83}
84
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080085TEST(complex, cacoshl) {
86 ASSERT_EQ(0.0, cacoshl(1.0));
87}
88
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080089TEST(complex, cacoshf) {
90 ASSERT_EQ(0.0, cacoshf(1.0));
91}
92
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080093TEST(complex, carg) {
94 ASSERT_EQ(0.0, carg(0));
95}
96
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080097TEST(complex, cargf) {
98 ASSERT_EQ(0.0, cargf(0));
99}
100
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800101TEST(complex, cargl) {
102 ASSERT_EQ(0.0, cargl(0));
103}
104
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800105TEST(complex, casin) {
106 ASSERT_EQ(0.0, casin(0));
107}
108
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800109TEST(complex, casinf) {
110 ASSERT_EQ(0.0, casinf(0));
111}
112
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800113TEST(complex, casinl) {
114 ASSERT_EQ(0.0, casinl(0));
115}
116
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800117TEST(complex, casinh) {
118 ASSERT_EQ(0.0, casinh(0));
119}
120
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800121TEST(complex, casinhf) {
122 ASSERT_EQ(0.0, casinhf(0));
123}
124
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800125TEST(complex, casinhl) {
126 ASSERT_EQ(0.0, casinhl(0));
127}
128
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800129TEST(complex, catan) {
130 ASSERT_EQ(0.0, catan(0));
131}
132
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800133TEST(complex, catanf) {
134 ASSERT_EQ(0.0, catanf(0));
135}
136
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800137TEST(complex, catanl) {
138 ASSERT_EQ(0.0, catanl(0));
139}
140
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800141TEST(complex, catanh) {
142 ASSERT_EQ(0.0, catanh(0));
143}
144
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800145TEST(complex, catanhf) {
146 ASSERT_EQ(0.0, catanhf(0));
147}
148
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800149TEST(complex, catanhl) {
150 ASSERT_EQ(0.0, catanhl(0));
151}
152
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800153TEST(complex, ccos) {
154 ASSERT_EQ(1.0, ccos(0));
155}
156
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800157TEST(complex, ccosf) {
158 ASSERT_EQ(1.0, ccosf(0));
159}
160
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800161TEST(complex, ccosl) {
162 ASSERT_EQ(1.0, ccosl(0));
163}
164
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800165TEST(complex, ccosh) {
166 ASSERT_EQ(1.0, ccosh(0));
167}
168
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800169TEST(complex, ccoshf) {
170 ASSERT_EQ(1.0, ccoshf(0));
171}
172
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800173TEST(complex, ccoshl) {
174 ASSERT_EQ(1.0, ccoshl(0));
175}
176
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800177TEST(complex, cexp) {
178 ASSERT_EQ(1.0, cexp(0));
179}
180
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800181TEST(complex, cexpf) {
182 ASSERT_EQ(1.0, cexpf(0));
183}
184
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800185TEST(complex, cexpl) {
186 ASSERT_EQ(1.0, cexpl(0));
187}
188
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800189TEST(complex, cimag) {
190 ASSERT_EQ(0.0, cimag(0));
191}
192
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800193TEST(complex, cimagf) {
194 ASSERT_EQ(0.0f, cimagf(0));
195}
196
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800197TEST(complex, cimagl) {
198 ASSERT_EQ(0.0, cimagl(0));
199}
200
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800201TEST(complex, clog) {
202 ASSERT_EQ(0.0, clog(1.0));
203}
204
205TEST(complex, clogf) {
206 ASSERT_EQ(0.0f, clogf(1.0f));
207}
208
209TEST(complex, clogl) {
210 ASSERT_EQ(0.0L, clogl(1.0L));
211}
212
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800213TEST(complex, conj) {
214 ASSERT_EQ(0.0, conj(0));
215}
216
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800217TEST(complex, conjf) {
218 ASSERT_EQ(0.0f, conjf(0));
219}
220
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800221TEST(complex, conjl) {
222 ASSERT_EQ(0.0, conjl(0));
223}
224
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800225TEST(complex, cpow) {
226 ASSERT_EQ(8.0, cpow(2.0, 3.0));
227}
228
229TEST(complex, cpowf) {
230 ASSERT_EQ(8.0f, cpowf(2.0f, 3.0f));
231}
232
233TEST(complex, cpowl) {
234 ASSERT_EQ(8.0L, cpowl(2.0L, 3.0L));
235}
236
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800237TEST(complex, cproj) {
238 ASSERT_EQ(0.0, cproj(0));
239}
240
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800241TEST(complex, cprojf) {
242 ASSERT_EQ(0.0f, cprojf(0));
243}
244
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800245TEST(complex, cprojl) {
246 ASSERT_EQ(0.0, cprojl(0));
247}
248
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800249TEST(complex, creal) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800250 ASSERT_EQ(2.0, creal(2.0 + 3.0I));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800251}
252
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800253TEST(complex, crealf) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800254 ASSERT_EQ(2.0f, crealf(2.0f + 3.0fI));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800255}
256
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800257TEST(complex, creall) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800258 ASSERT_EQ(2.0, creall(2.0L + 3.0LI));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800259}
260
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800261TEST(complex, csin) {
262 ASSERT_EQ(0.0, csin(0));
263}
264
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800265TEST(complex, csinf) {
266 ASSERT_EQ(0.0, csinf(0));
267}
268
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800269TEST(complex, csinl) {
270 ASSERT_EQ(0.0, csinl(0));
271}
272
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800273TEST(complex, csinh) {
274 ASSERT_EQ(0.0, csinh(0));
275}
276
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800277TEST(complex, csinhf) {
278 ASSERT_EQ(0.0, csinhf(0));
279}
280
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800281TEST(complex, csinhl) {
282 ASSERT_EQ(0.0, csinhl(0));
283}
284
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800285TEST(complex, csqrt) {
286 ASSERT_EQ(0.0, csqrt(0));
287}
288
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800289TEST(complex, csqrtf) {
290 ASSERT_EQ(0.0f, csqrt(0));
291}
292
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800293TEST(complex, csqrtl) {
294 ASSERT_EQ(0.0, csqrtl(0));
295}
296
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800297TEST(complex, ctan) {
298 ASSERT_EQ(0.0, ctan(0));
299}
300
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800301TEST(complex, ctanf) {
302 ASSERT_EQ(0.0, ctanf(0));
303}
304
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800305TEST(complex, ctanl) {
306 ASSERT_EQ(0.0, ctanl(0));
307}
308
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800309TEST(complex, ctanh) {
310 ASSERT_EQ(0.0, ctanh(0));
311}
312
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800313TEST(complex, ctanhf) {
314 ASSERT_EQ(0.0, ctanhf(0));
315}
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800316
317TEST(complex, ctanhl) {
318 ASSERT_EQ(0.0, ctanhl(0));
319}