• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
operator <<(std::ostream & os,const double _Complex c)45 std::ostream& operator<<(std::ostream& os, const double _Complex c) {
46   os << "(" << creal(c) << "," << cimag(c) << "i)";
47  return os;
48 }
operator <<(std::ostream & os,const float _Complex c)49 std::ostream& operator<<(std::ostream& os, const float _Complex c) {
50   os << "(" << crealf(c) << "," << cimagf(c) << "i)";
51   return os;
52 }
operator <<(std::ostream & os,const long double _Complex c)53 std::ostream& operator<<(std::ostream& os, const long double _Complex c) {
54   os << "(" << creall(c) << "," << cimagl(c) << "i)";
55   return os;
56 }
57 
TEST(complex,cabs)58 TEST(complex, cabs) {
59   ASSERT_EQ(0.0, cabs(0));
60 }
61 
TEST(complex,cabsf)62 TEST(complex, cabsf) {
63   ASSERT_EQ(0.0, cabsf(0));
64 }
65 
TEST(complex,cabsl)66 TEST(complex, cabsl) {
67   ASSERT_EQ(0.0, cabsl(0));
68 }
69 
TEST(complex,cacos)70 TEST(complex, cacos) {
71   ASSERT_EQ(M_PI_2, cacos(0.0));
72 }
73 
TEST(complex,cacosf)74 TEST(complex, cacosf) {
75   ASSERT_EQ(static_cast<float>(M_PI_2), cacosf(0.0));
76 }
77 
TEST(complex,cacosl)78 TEST(complex, cacosl) {
79   ASSERT_EQ(M_PI_2l, cacosl(0.0));
80 }
81 
TEST(complex,cacosh)82 TEST(complex, cacosh) {
83   ASSERT_EQ(0.0, cacosh(1.0));
84 }
85 
TEST(complex,cacoshl)86 TEST(complex, cacoshl) {
87   ASSERT_EQ(0.0, cacoshl(1.0));
88 }
89 
TEST(complex,cacoshf)90 TEST(complex, cacoshf) {
91   ASSERT_EQ(0.0, cacoshf(1.0));
92 }
93 
TEST(complex,carg)94 TEST(complex, carg) {
95   ASSERT_EQ(0.0, carg(0));
96 }
97 
TEST(complex,cargf)98 TEST(complex, cargf) {
99   ASSERT_EQ(0.0, cargf(0));
100 }
101 
TEST(complex,cargl)102 TEST(complex, cargl) {
103   ASSERT_EQ(0.0, cargl(0));
104 }
105 
TEST(complex,casin)106 TEST(complex, casin) {
107   ASSERT_EQ(0.0, casin(0));
108 }
109 
TEST(complex,casinf)110 TEST(complex, casinf) {
111   ASSERT_EQ(0.0, casinf(0));
112 }
113 
TEST(complex,casinl)114 TEST(complex, casinl) {
115   ASSERT_EQ(0.0, casinl(0));
116 }
117 
TEST(complex,casinh)118 TEST(complex, casinh) {
119   ASSERT_EQ(0.0, casinh(0));
120 }
121 
TEST(complex,casinhf)122 TEST(complex, casinhf) {
123   ASSERT_EQ(0.0, casinhf(0));
124 }
125 
TEST(complex,casinhl)126 TEST(complex, casinhl) {
127   ASSERT_EQ(0.0, casinhl(0));
128 }
129 
TEST(complex,catan)130 TEST(complex, catan) {
131   ASSERT_EQ(0.0, catan(0));
132 }
133 
TEST(complex,catanf)134 TEST(complex, catanf) {
135   ASSERT_EQ(0.0, catanf(0));
136 }
137 
TEST(complex,catanl)138 TEST(complex, catanl) {
139   ASSERT_EQ(0.0, catanl(0));
140 }
141 
TEST(complex,catanh)142 TEST(complex, catanh) {
143   ASSERT_EQ(0.0, catanh(0));
144 }
145 
TEST(complex,catanhf)146 TEST(complex, catanhf) {
147   ASSERT_EQ(0.0, catanhf(0));
148 }
149 
TEST(complex,catanhl)150 TEST(complex, catanhl) {
151   ASSERT_EQ(0.0, catanhl(0));
152 }
153 
TEST(complex,ccos)154 TEST(complex, ccos) {
155   ASSERT_EQ(1.0, ccos(0));
156 }
157 
TEST(complex,ccosf)158 TEST(complex, ccosf) {
159   ASSERT_EQ(1.0, ccosf(0));
160 }
161 
TEST(complex,ccosl)162 TEST(complex, ccosl) {
163   ASSERT_EQ(1.0, ccosl(0));
164 }
165 
TEST(complex,ccosh)166 TEST(complex, ccosh) {
167   ASSERT_EQ(1.0, ccosh(0));
168 }
169 
TEST(complex,ccoshf)170 TEST(complex, ccoshf) {
171   ASSERT_EQ(1.0, ccoshf(0));
172 }
173 
TEST(complex,ccoshl)174 TEST(complex, ccoshl) {
175   ASSERT_EQ(1.0, ccoshl(0));
176 }
177 
TEST(complex,cexp)178 TEST(complex, cexp) {
179   ASSERT_EQ(1.0, cexp(0));
180 }
181 
TEST(complex,cexpf)182 TEST(complex, cexpf) {
183   ASSERT_EQ(1.0, cexpf(0));
184 }
185 
TEST(complex,cexpl)186 TEST(complex, cexpl) {
187   ASSERT_EQ(1.0, cexpl(0));
188 }
189 
TEST(complex,cimag)190 TEST(complex, cimag) {
191   ASSERT_EQ(0.0, cimag(0));
192 }
193 
TEST(complex,cimagf)194 TEST(complex, cimagf) {
195   ASSERT_EQ(0.0f, cimagf(0));
196 }
197 
TEST(complex,cimagl)198 TEST(complex, cimagl) {
199   ASSERT_EQ(0.0, cimagl(0));
200 }
201 
TEST(complex,clog)202 TEST(complex, clog) {
203   ASSERT_EQ(0.0, clog(1.0));
204 }
205 
TEST(complex,clogf)206 TEST(complex, clogf) {
207   ASSERT_EQ(0.0f, clogf(1.0f));
208 }
209 
TEST(complex,clogl)210 TEST(complex, clogl) {
211   ASSERT_EQ(0.0L, clogl(1.0L));
212 }
213 
TEST(complex,conj)214 TEST(complex, conj) {
215   ASSERT_EQ(0.0, conj(0));
216 }
217 
TEST(complex,conjf)218 TEST(complex, conjf) {
219   ASSERT_EQ(0.0f, conjf(0));
220 }
221 
TEST(complex,conjl)222 TEST(complex, conjl) {
223   ASSERT_EQ(0.0, conjl(0));
224 }
225 
TEST(complex,cpow)226 TEST(complex, cpow) {
227   ASSERT_EQ(8.0, cpow(2.0, 3.0));
228 }
229 
TEST(complex,cpowf)230 TEST(complex, cpowf) {
231   ASSERT_EQ(8.0f, cpowf(2.0f, 3.0f));
232 }
233 
TEST(complex,cpowl)234 TEST(complex, cpowl) {
235   ASSERT_EQ(8.0L, cpowl(2.0L, 3.0L));
236 }
237 
TEST(complex,cproj)238 TEST(complex, cproj) {
239   ASSERT_EQ(0.0, cproj(0));
240 }
241 
TEST(complex,cprojf)242 TEST(complex, cprojf) {
243   ASSERT_EQ(0.0f, cprojf(0));
244 }
245 
TEST(complex,cprojl)246 TEST(complex, cprojl) {
247   ASSERT_EQ(0.0, cprojl(0));
248 }
249 
TEST(complex,creal)250 TEST(complex, creal) {
251   ASSERT_EQ(2.0, creal(2.0 + 3.0I));
252 }
253 
TEST(complex,crealf)254 TEST(complex, crealf) {
255   ASSERT_EQ(2.0f, crealf(2.0f + 3.0fI));
256 }
257 
TEST(complex,creall)258 TEST(complex, creall) {
259   ASSERT_EQ(2.0, creall(2.0L + 3.0LI));
260 }
261 
TEST(complex,csin)262 TEST(complex, csin) {
263   ASSERT_EQ(0.0, csin(0));
264 }
265 
TEST(complex,csinf)266 TEST(complex, csinf) {
267   ASSERT_EQ(0.0, csinf(0));
268 }
269 
TEST(complex,csinl)270 TEST(complex, csinl) {
271   ASSERT_EQ(0.0, csinl(0));
272 }
273 
TEST(complex,csinh)274 TEST(complex, csinh) {
275   ASSERT_EQ(0.0, csinh(0));
276 }
277 
TEST(complex,csinhf)278 TEST(complex, csinhf) {
279   ASSERT_EQ(0.0, csinhf(0));
280 }
281 
TEST(complex,csinhl)282 TEST(complex, csinhl) {
283   ASSERT_EQ(0.0, csinhl(0));
284 }
285 
TEST(complex,csqrt)286 TEST(complex, csqrt) {
287   ASSERT_EQ(0.0, csqrt(0));
288 }
289 
TEST(complex,csqrtf)290 TEST(complex, csqrtf) {
291   ASSERT_EQ(0.0f, csqrtf(0));
292 }
293 
TEST(complex,csqrtl)294 TEST(complex, csqrtl) {
295   ASSERT_EQ(0.0, csqrtl(0));
296 }
297 
TEST(complex,ctan)298 TEST(complex, ctan) {
299   ASSERT_EQ(0.0, ctan(0));
300 }
301 
TEST(complex,ctanf)302 TEST(complex, ctanf) {
303   ASSERT_EQ(0.0, ctanf(0));
304 }
305 
TEST(complex,ctanl)306 TEST(complex, ctanl) {
307   ASSERT_EQ(0.0, ctanl(0));
308 }
309 
TEST(complex,ctanh)310 TEST(complex, ctanh) {
311   ASSERT_EQ(0.0, ctanh(0));
312 }
313 
TEST(complex,ctanhf)314 TEST(complex, ctanhf) {
315   ASSERT_EQ(0.0, ctanhf(0));
316 }
317 
TEST(complex,ctanhl)318 TEST(complex, ctanhl) {
319   ASSERT_EQ(0.0, ctanhl(0));
320 }
321