2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <gtest/gtest.h>
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
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>
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
37 #include <math.h> // For M_PI_2/M_PI_2l.
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
42 // TODO: find out why gtest doesn't use these; until then they're only useful
43 // for manual printf^Woperator<< debugging.
45 std::ostream& operator<<(std::ostream& os, const double _Complex c) {
46 os << "(" << creal(c) << "," << cimag(c) << "i)";
49 std::ostream& operator<<(std::ostream& os, const float _Complex c) {
50 os << "(" << crealf(c) << "," << cimagf(c) << "i)";
53 std::ostream& operator<<(std::ostream& os, const long double _Complex c) {
54 os << "(" << creall(c) << "," << cimagl(c) << "i)";
59 ASSERT_EQ(0.0, cabs(0));
62 TEST(complex, cabsf) {
63 ASSERT_EQ(0.0, cabsf(0));
66 TEST(complex, cabsl) {
67 ASSERT_EQ(0.0, cabsl(0));
70 TEST(complex, cacos) {
71 ASSERT_EQ(M_PI_2, cacos(0.0));
74 TEST(complex, cacosf) {
75 ASSERT_EQ(static_cast<float>(M_PI_2), cacosf(0.0));
78 TEST(complex, cacosl) {
79 ASSERT_EQ(M_PI_2l, cacosl(0.0));
82 TEST(complex, cacosh) {
83 ASSERT_EQ(0.0, cacosh(1.0));
86 TEST(complex, cacoshl) {
87 ASSERT_EQ(0.0, cacoshl(1.0));
90 TEST(complex, cacoshf) {
91 ASSERT_EQ(0.0, cacoshf(1.0));
95 ASSERT_EQ(0.0, carg(0));
98 TEST(complex, cargf) {
99 ASSERT_EQ(0.0, cargf(0));
102 TEST(complex, cargl) {
103 ASSERT_EQ(0.0, cargl(0));
106 TEST(complex, casin) {
107 ASSERT_EQ(0.0, casin(0));
110 TEST(complex, casinf) {
111 ASSERT_EQ(0.0, casinf(0));
114 TEST(complex, casinl) {
115 ASSERT_EQ(0.0, casinl(0));
118 TEST(complex, casinh) {
119 ASSERT_EQ(0.0, casinh(0));
122 TEST(complex, casinhf) {
123 ASSERT_EQ(0.0, casinhf(0));
126 TEST(complex, casinhl) {
127 ASSERT_EQ(0.0, casinhl(0));
130 TEST(complex, catan) {
131 ASSERT_EQ(0.0, catan(0));
134 TEST(complex, catanf) {
135 ASSERT_EQ(0.0, catanf(0));
138 TEST(complex, catanl) {
139 ASSERT_EQ(0.0, catanl(0));
142 TEST(complex, catanh) {
143 ASSERT_EQ(0.0, catanh(0));
146 TEST(complex, catanhf) {
147 ASSERT_EQ(0.0, catanhf(0));
150 TEST(complex, catanhl) {
151 ASSERT_EQ(0.0, catanhl(0));
154 TEST(complex, ccos) {
155 ASSERT_EQ(1.0, ccos(0));
158 TEST(complex, ccosf) {
159 ASSERT_EQ(1.0, ccosf(0));
162 TEST(complex, ccosl) {
163 ASSERT_EQ(1.0, ccosl(0));
166 TEST(complex, ccosh) {
167 ASSERT_EQ(1.0, ccosh(0));
170 TEST(complex, ccoshf) {
171 ASSERT_EQ(1.0, ccoshf(0));
174 TEST(complex, ccoshl) {
175 ASSERT_EQ(1.0, ccoshl(0));
178 TEST(complex, cexp) {
179 ASSERT_EQ(1.0, cexp(0));
182 TEST(complex, cexpf) {
183 ASSERT_EQ(1.0, cexpf(0));
186 TEST(complex, cexpl) {
187 ASSERT_EQ(1.0, cexpl(0));
190 TEST(complex, cimag) {
191 ASSERT_EQ(0.0, cimag(0));
194 TEST(complex, cimagf) {
195 ASSERT_EQ(0.0f, cimagf(0));
198 TEST(complex, cimagl) {
199 ASSERT_EQ(0.0, cimagl(0));
202 TEST(complex, clog) {
203 ASSERT_EQ(0.0, clog(1.0));
206 TEST(complex, clogf) {
207 ASSERT_EQ(0.0f, clogf(1.0f));
210 TEST(complex, clogl) {
211 ASSERT_EQ(0.0L, clogl(1.0L));
214 TEST(complex, conj) {
215 ASSERT_EQ(0.0, conj(0));
218 TEST(complex, conjf) {
219 ASSERT_EQ(0.0f, conjf(0));
222 TEST(complex, conjl) {
223 ASSERT_EQ(0.0, conjl(0));
226 TEST(complex, cpow) {
227 ASSERT_EQ(8.0, cpow(2.0, 3.0));
230 TEST(complex, cpowf) {
231 ASSERT_EQ(8.0f, cpowf(2.0f, 3.0f));
234 TEST(complex, cpowl) {
235 ASSERT_EQ(8.0L, cpowl(2.0L, 3.0L));
238 TEST(complex, cproj) {
239 ASSERT_EQ(0.0, cproj(0));
242 TEST(complex, cprojf) {
243 ASSERT_EQ(0.0f, cprojf(0));
246 TEST(complex, cprojl) {
247 ASSERT_EQ(0.0, cprojl(0));
250 TEST(complex, creal) {
251 ASSERT_EQ(2.0, creal(2.0 + 3.0I));
254 TEST(complex, crealf) {
255 ASSERT_EQ(2.0f, crealf(2.0f + 3.0fI));
258 TEST(complex, creall) {
259 ASSERT_EQ(2.0, creall(2.0L + 3.0LI));
262 TEST(complex, csin) {
263 ASSERT_EQ(0.0, csin(0));
266 TEST(complex, csinf) {
267 ASSERT_EQ(0.0, csinf(0));
270 TEST(complex, csinl) {
271 ASSERT_EQ(0.0, csinl(0));
274 TEST(complex, csinh) {
275 ASSERT_EQ(0.0, csinh(0));
278 TEST(complex, csinhf) {
279 ASSERT_EQ(0.0, csinhf(0));
282 TEST(complex, csinhl) {
283 ASSERT_EQ(0.0, csinhl(0));
286 TEST(complex, csqrt) {
287 ASSERT_EQ(0.0, csqrt(0));
290 TEST(complex, csqrtf) {
291 ASSERT_EQ(0.0f, csqrtf(0));
294 TEST(complex, csqrtl) {
295 ASSERT_EQ(0.0, csqrtl(0));
298 TEST(complex, ctan) {
299 ASSERT_EQ(0.0, ctan(0));
302 TEST(complex, ctanf) {
303 ASSERT_EQ(0.0, ctanf(0));
306 TEST(complex, ctanl) {
307 ASSERT_EQ(0.0, ctanl(0));
310 TEST(complex, ctanh) {
311 ASSERT_EQ(0.0, ctanh(0));
314 TEST(complex, ctanhf) {
315 ASSERT_EQ(0.0, ctanhf(0));
318 TEST(complex, ctanhl) {
319 ASSERT_EQ(0.0, ctanhl(0));