• 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 // This file is compiled against both glibc and bionic, and our complex.h
18 // depends on bionic-specific macros, so hack around that.
19 #include <sys/cdefs.h>
20 #if !defined(__INTRODUCED_IN)
21 #define __INTRODUCED_IN(x)
22 #endif
23 #if !defined(__BIONIC_AVAILABILITY_GUARD)
24 #define __BIONIC_AVAILABILITY_GUARD(x) 1
25 #endif
26 
27 // libc++ actively gets in the way of including <complex.h> from C++, so we
28 // have to be naughty.
29 #include "../libc/include/complex.h"
30 
31 // Ensure that libc++'s complex.h and __fwd/complex.h headers are no-ops.
32 #define _LIBCPP_COMPLEX_H
33 #define _LIBCPP___FWD_COMPLEX_H
34 
35 // (libc++ also seems to have really bad implementations of its own that ignore
36 // the intricacies of floating point math.)
37 // http://llvm.org/bugs/show_bug.cgi?id=21504
38 
39 #include <math.h> // For M_PI_2/M_PI_2l.
40 
41 // Prettify gtest Complex printing.
42 // Macro 'complex' defined in complex.h conflicts with iostream.
43 #pragma push_macro("complex")
44 #undef complex
45 #include <iostream>
46 #pragma pop_macro("complex")
47 namespace testing {
48 namespace internal {
PrintTo(const double _Complex & c,std::ostream * os)49 inline void PrintTo(const double _Complex& c, std::ostream* os) {
50   *os << "(" << creal(c) << "," << cimag(c) << "i)";
51 }
PrintTo(const float _Complex & c,std::ostream * os)52 inline void PrintTo(const float _Complex& c, std::ostream* os) {
53   *os << "(" << crealf(c) << "," << cimagf(c) << "i)";
54 }
PrintTo(const long double _Complex & c,std::ostream * os)55 inline void PrintTo(const long double _Complex& c, std::ostream* os) {
56   *os << "(" << creall(c) << "," << cimagl(c) << "i)";
57 }
58 }
59 }
60 
61 // Macro 'I' defined in complex.h conflicts with gtest.h.
62 #pragma push_macro("I")
63 #undef I
64 #include <gtest/gtest.h>
65 #pragma pop_macro("I")
66 
TEST(complex_h,cabs)67 TEST(complex_h, cabs) {
68   ASSERT_EQ(0.0, cabs(0));
69 }
70 
TEST(complex_h,cabsf)71 TEST(complex_h, cabsf) {
72   ASSERT_EQ(0.0, cabsf(0));
73 }
74 
TEST(complex_h,cabsl)75 TEST(complex_h, cabsl) {
76   ASSERT_EQ(0.0, cabsl(0));
77 }
78 
TEST(complex_h,cacos)79 TEST(complex_h, cacos) {
80   ASSERT_EQ(M_PI_2, cacos(0.0));
81 }
82 
TEST(complex_h,cacosf)83 TEST(complex_h, cacosf) {
84   ASSERT_EQ(static_cast<float>(M_PI_2), cacosf(0.0));
85 }
86 
TEST(complex_h,cacosl)87 TEST(complex_h, cacosl) {
88   ASSERT_EQ(M_PI_2l, cacosl(0.0));
89 }
90 
TEST(complex_h,cacosh)91 TEST(complex_h, cacosh) {
92   ASSERT_EQ(0.0, cacosh(1.0));
93 }
94 
TEST(complex_h,cacoshl)95 TEST(complex_h, cacoshl) {
96   ASSERT_EQ(0.0, cacoshl(1.0));
97 }
98 
TEST(complex_h,cacoshf)99 TEST(complex_h, cacoshf) {
100   ASSERT_EQ(0.0, cacoshf(1.0));
101 }
102 
TEST(complex_h,carg)103 TEST(complex_h, carg) {
104   ASSERT_EQ(0.0, carg(0));
105 }
106 
TEST(complex_h,cargf)107 TEST(complex_h, cargf) {
108   ASSERT_EQ(0.0, cargf(0));
109 }
110 
TEST(complex_h,cargl)111 TEST(complex_h, cargl) {
112   ASSERT_EQ(0.0, cargl(0));
113 }
114 
TEST(complex_h,casin)115 TEST(complex_h, casin) {
116   ASSERT_EQ(0.0, casin(0));
117 }
118 
TEST(complex_h,casinf)119 TEST(complex_h, casinf) {
120   ASSERT_EQ(0.0, casinf(0));
121 }
122 
TEST(complex_h,casinl)123 TEST(complex_h, casinl) {
124   ASSERT_EQ(0.0, casinl(0));
125 }
126 
TEST(complex_h,casinh)127 TEST(complex_h, casinh) {
128   ASSERT_EQ(0.0, casinh(0));
129 }
130 
TEST(complex_h,casinhf)131 TEST(complex_h, casinhf) {
132   ASSERT_EQ(0.0, casinhf(0));
133 }
134 
TEST(complex_h,casinhl)135 TEST(complex_h, casinhl) {
136   ASSERT_EQ(0.0, casinhl(0));
137 }
138 
TEST(complex_h,catan)139 TEST(complex_h, catan) {
140   ASSERT_EQ(0.0, catan(0));
141 }
142 
TEST(complex_h,catanf)143 TEST(complex_h, catanf) {
144   ASSERT_EQ(0.0, catanf(0));
145 }
146 
TEST(complex_h,catanl)147 TEST(complex_h, catanl) {
148   ASSERT_EQ(0.0, catanl(0));
149 }
150 
TEST(complex_h,catanh)151 TEST(complex_h, catanh) {
152   ASSERT_EQ(0.0, catanh(0));
153 }
154 
TEST(complex_h,catanhf)155 TEST(complex_h, catanhf) {
156   ASSERT_EQ(0.0, catanhf(0));
157 }
158 
TEST(complex_h,catanhl)159 TEST(complex_h, catanhl) {
160   ASSERT_EQ(0.0, catanhl(0));
161 }
162 
TEST(complex_h,ccos)163 TEST(complex_h, ccos) {
164   ASSERT_EQ(1.0, ccos(0));
165 }
166 
TEST(complex_h,ccosf)167 TEST(complex_h, ccosf) {
168   ASSERT_EQ(1.0, ccosf(0));
169 }
170 
TEST(complex_h,ccosl)171 TEST(complex_h, ccosl) {
172   ASSERT_EQ(1.0, ccosl(0));
173 }
174 
TEST(complex_h,ccosh)175 TEST(complex_h, ccosh) {
176   ASSERT_EQ(1.0, ccosh(0));
177 }
178 
TEST(complex_h,ccoshf)179 TEST(complex_h, ccoshf) {
180   ASSERT_EQ(1.0, ccoshf(0));
181 }
182 
TEST(complex_h,ccoshl)183 TEST(complex_h, ccoshl) {
184   ASSERT_EQ(1.0, ccoshl(0));
185 }
186 
TEST(complex_h,cexp)187 TEST(complex_h, cexp) {
188   ASSERT_EQ(1.0, cexp(0));
189 }
190 
TEST(complex_h,cexpf)191 TEST(complex_h, cexpf) {
192   ASSERT_EQ(1.0, cexpf(0));
193 }
194 
TEST(complex_h,cexpl)195 TEST(complex_h, cexpl) {
196   ASSERT_EQ(1.0, cexpl(0));
197 }
198 
TEST(complex_h,cimag)199 TEST(complex_h, cimag) {
200   ASSERT_EQ(0.0, cimag(0));
201 }
202 
TEST(complex_h,cimagf)203 TEST(complex_h, cimagf) {
204   ASSERT_EQ(0.0f, cimagf(0));
205 }
206 
TEST(complex_h,cimagl)207 TEST(complex_h, cimagl) {
208   ASSERT_EQ(0.0, cimagl(0));
209 }
210 
TEST(complex_h,clog)211 TEST(complex_h, clog) {
212   ASSERT_EQ(0.0, clog(1.0));
213 }
214 
TEST(complex_h,clogf)215 TEST(complex_h, clogf) {
216   ASSERT_EQ(0.0f, clogf(1.0f));
217 }
218 
TEST(complex_h,clogl)219 TEST(complex_h, clogl) {
220   ASSERT_EQ(0.0L, clogl(1.0L));
221 }
222 
TEST(complex_h,conj)223 TEST(complex_h, conj) {
224   ASSERT_EQ(0.0, conj(0));
225 }
226 
TEST(complex_h,conjf)227 TEST(complex_h, conjf) {
228   ASSERT_EQ(0.0f, conjf(0));
229 }
230 
TEST(complex_h,conjl)231 TEST(complex_h, conjl) {
232   ASSERT_EQ(0.0, conjl(0));
233 }
234 
TEST(complex_h,cpow)235 TEST(complex_h, cpow) {
236   ASSERT_EQ(8.0, cpow(2.0, 3.0));
237 }
238 
TEST(complex_h,cpowf)239 TEST(complex_h, cpowf) {
240   ASSERT_EQ(8.0f, cpowf(2.0f, 3.0f));
241 }
242 
TEST(complex_h,cpowl)243 TEST(complex_h, cpowl) {
244   ASSERT_EQ(8.0L, cpowl(2.0L, 3.0L));
245 }
246 
TEST(complex_h,cproj)247 TEST(complex_h, cproj) {
248   ASSERT_EQ(0.0, cproj(0));
249 }
250 
TEST(complex_h,cprojf)251 TEST(complex_h, cprojf) {
252   ASSERT_EQ(0.0f, cprojf(0));
253 }
254 
TEST(complex_h,cprojl)255 TEST(complex_h, cprojl) {
256   ASSERT_EQ(0.0, cprojl(0));
257 }
258 
TEST(complex_h,creal)259 TEST(complex_h, creal) {
260   ASSERT_EQ(2.0, creal(2.0 + 3.0I));
261 }
262 
TEST(complex_h,crealf)263 TEST(complex_h, crealf) {
264   ASSERT_EQ(2.0f, crealf(2.0f + 3.0fI));
265 }
266 
TEST(complex_h,creall)267 TEST(complex_h, creall) {
268   ASSERT_EQ(2.0, creall(2.0L + 3.0LI));
269 }
270 
TEST(complex_h,csin)271 TEST(complex_h, csin) {
272   ASSERT_EQ(0.0, csin(0));
273 }
274 
TEST(complex_h,csinf)275 TEST(complex_h, csinf) {
276   ASSERT_EQ(0.0, csinf(0));
277 }
278 
TEST(complex_h,csinl)279 TEST(complex_h, csinl) {
280   ASSERT_EQ(0.0, csinl(0));
281 }
282 
TEST(complex_h,csinh)283 TEST(complex_h, csinh) {
284   ASSERT_EQ(0.0, csinh(0));
285 }
286 
TEST(complex_h,csinhf)287 TEST(complex_h, csinhf) {
288   ASSERT_EQ(0.0, csinhf(0));
289 }
290 
TEST(complex_h,csinhl)291 TEST(complex_h, csinhl) {
292   ASSERT_EQ(0.0, csinhl(0));
293 }
294 
TEST(complex_h,csqrt)295 TEST(complex_h, csqrt) {
296   ASSERT_EQ(0.0, csqrt(0));
297 }
298 
TEST(complex_h,csqrtf)299 TEST(complex_h, csqrtf) {
300   ASSERT_EQ(0.0f, csqrtf(0));
301 }
302 
TEST(complex_h,csqrtl)303 TEST(complex_h, csqrtl) {
304   ASSERT_EQ(0.0, csqrtl(0));
305 }
306 
TEST(complex_h,ctan)307 TEST(complex_h, ctan) {
308   ASSERT_EQ(0.0, ctan(0));
309 }
310 
TEST(complex_h,ctanf)311 TEST(complex_h, ctanf) {
312   ASSERT_EQ(0.0, ctanf(0));
313 }
314 
TEST(complex_h,ctanl)315 TEST(complex_h, ctanl) {
316   ASSERT_EQ(0.0, ctanl(0));
317 }
318 
TEST(complex_h,ctanh)319 TEST(complex_h, ctanh) {
320   ASSERT_EQ(0.0, ctanh(0));
321 
322   double complex z;
323 
324   // If z is NaN+0i, the result is NaN+0i.
325   z = ctanh(nan("") + 0i);
326   ASSERT_TRUE(isnan(creal(z)));
327   ASSERT_EQ(0.0, cimag(z));
328 
329   // If z is NaN+yi, the result is NaN+NaNi.
330   z = ctanh(nan("") + 2.0i);
331   ASSERT_TRUE(isnan(creal(z)));
332   ASSERT_TRUE(isnan(cimag(z)));
333 
334   // If z is NaN+NaNi, the result is NaN+NaNi.
335   z = ctanh(nan("") + nan("") * I);
336   ASSERT_TRUE(isnan(creal(z)));
337   ASSERT_TRUE(isnan(cimag(z)));
338 }
339 
TEST(complex_h,ctanhf)340 TEST(complex_h, ctanhf) {
341   ASSERT_EQ(0.0f, ctanhf(0.0f));
342 
343   float complex z;
344 
345   // If z is NaN+0i, the result is NaN+0i.
346   z = ctanhf(nanf("") + 0.0fi);
347   ASSERT_TRUE(isnan(crealf(z)));
348   ASSERT_EQ(0.0f, cimagf(z));
349 
350   // If z is NaN+yi, the result is NaN+NaNi.
351   z = ctanhf(nanf("") + 2.0fi);
352   ASSERT_TRUE(isnan(crealf(z)));
353   ASSERT_TRUE(isnan(cimagf(z)));
354 
355   // If z is NaN+NaNi, the result is NaN+NaNi.
356   z = ctanhf(nanf("") + nanf("") * I);
357   ASSERT_TRUE(isnan(crealf(z)));
358   ASSERT_TRUE(isnan(cimagf(z)));
359 }
360 
TEST(complex_h,ctanhl)361 TEST(complex_h, ctanhl) {
362   ASSERT_EQ(0.0L, ctanhl(0.0L));
363 
364   long double complex z;
365 
366   // If z is NaN+0i, the result is NaN+0i.
367   z = ctanhl(nanl("") + 0.0Li);
368   ASSERT_TRUE(isnan(creall(z)));
369   // TODO: this case is currently broken in the netbsd ctanhl.
370   // ASSERT_EQ(0.0L, cimagl(z));
371 
372   // If z is NaN+yi, the result is NaN+NaNi.
373   z = ctanhl(nanl("") + 2.0Li);
374   ASSERT_TRUE(isnan(creall(z)));
375   ASSERT_TRUE(isnan(cimagl(z)));
376 
377   // If z is NaN+NaNi, the result is NaN+NaNi.
378   z = ctanhl(nanl("") + nanl("") * I);
379   ASSERT_TRUE(isnan(creall(z)));
380   ASSERT_TRUE(isnan(cimagl(z)));
381 }
382