blob: 710912a972216aebc4cb837f21f4a98fcf6218ff [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
19// libc++ actively gets in the way of including <complex.h> from C++, so we
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080020// have to be naughty.
21#include <../libm/include/complex.h>
22
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080023// (libc++ also seems to have really bad implementations of its own that ignore
24// the intricacies of floating point math.)
25// http://llvm.org/bugs/show_bug.cgi?id=21504
26
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080027#include <math.h> // For M_PI_2/M_PI_2l.
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080028
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080029// Note that gtest doesn't support complex numbers, so the output from
30// assertion failures is misleading/useless (at best you'll only see the real
31// part).
32// TODO: find out why gtest doesn't use these; until then they're only useful
33// for manual printf^Woperator<< debugging.
34#include <iostream>
35std::ostream& operator<<(std::ostream& os, const double _Complex c) {
36 os << "(" << creal(c) << "," << cimag(c) << "i)";
37 return os;
38}
39std::ostream& operator<<(std::ostream& os, const float _Complex c) {
40 os << "(" << crealf(c) << "," << cimagf(c) << "i)";
41 return os;
42}
43std::ostream& operator<<(std::ostream& os, const long double _Complex c) {
44 os << "(" << creall(c) << "," << cimagl(c) << "i)";
45 return os;
46}
47
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080048TEST(complex, cabs) {
49 ASSERT_EQ(0.0, cabs(0));
50}
51
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080052TEST(complex, cabsf) {
53 ASSERT_EQ(0.0, cabsf(0));
54}
55
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080056TEST(complex, cabsl) {
57 ASSERT_EQ(0.0, cabsl(0));
58}
59
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080060TEST(complex, cacos) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080061 ASSERT_EQ(M_PI_2, cacos(0.0));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080062}
63
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080064TEST(complex, cacosf) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080065 ASSERT_EQ(static_cast<float>(M_PI_2), cacosf(0.0));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080066}
67
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080068TEST(complex, cacosl) {
69 ASSERT_EQ(M_PI_2l, cacosl(0.0));
70}
71
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080072TEST(complex, cacosh) {
73 ASSERT_EQ(0.0, cacosh(1.0));
74}
75
Elliott Hughes9ee6adb2016-03-11 14:49:13 -080076TEST(complex, cacoshl) {
77 ASSERT_EQ(0.0, cacoshl(1.0));
78}
79
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080080TEST(complex, cacoshf) {
81 ASSERT_EQ(0.0, cacoshf(1.0));
82}
83
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080084TEST(complex, carg) {
85 ASSERT_EQ(0.0, carg(0));
86}
87
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080088TEST(complex, cargf) {
89 ASSERT_EQ(0.0, cargf(0));
90}
91
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080092TEST(complex, cargl) {
93 ASSERT_EQ(0.0, cargl(0));
94}
95
Elliott Hughesb8ee16f2014-11-06 11:16:55 -080096TEST(complex, casin) {
97 ASSERT_EQ(0.0, casin(0));
98}
99
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800100TEST(complex, casinf) {
101 ASSERT_EQ(0.0, casinf(0));
102}
103
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800104TEST(complex, casinl) {
105 ASSERT_EQ(0.0, casinl(0));
106}
107
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800108TEST(complex, casinh) {
109 ASSERT_EQ(0.0, casinh(0));
110}
111
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800112TEST(complex, casinhf) {
113 ASSERT_EQ(0.0, casinhf(0));
114}
115
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800116TEST(complex, casinhl) {
117 ASSERT_EQ(0.0, casinhl(0));
118}
119
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800120TEST(complex, catan) {
121 ASSERT_EQ(0.0, catan(0));
122}
123
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800124TEST(complex, catanf) {
125 ASSERT_EQ(0.0, catanf(0));
126}
127
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800128TEST(complex, catanl) {
129 ASSERT_EQ(0.0, catanl(0));
130}
131
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800132TEST(complex, catanh) {
133 ASSERT_EQ(0.0, catanh(0));
134}
135
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800136TEST(complex, catanhf) {
137 ASSERT_EQ(0.0, catanhf(0));
138}
139
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800140TEST(complex, catanhl) {
141 ASSERT_EQ(0.0, catanhl(0));
142}
143
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800144TEST(complex, ccos) {
145 ASSERT_EQ(1.0, ccos(0));
146}
147
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800148TEST(complex, ccosf) {
149 ASSERT_EQ(1.0, ccosf(0));
150}
151
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800152TEST(complex, ccosl) {
153 ASSERT_EQ(1.0, ccosl(0));
154}
155
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800156TEST(complex, ccosh) {
157 ASSERT_EQ(1.0, ccosh(0));
158}
159
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800160TEST(complex, ccoshf) {
161 ASSERT_EQ(1.0, ccoshf(0));
162}
163
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800164TEST(complex, ccoshl) {
165 ASSERT_EQ(1.0, ccoshl(0));
166}
167
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800168TEST(complex, cexp) {
169 ASSERT_EQ(1.0, cexp(0));
170}
171
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800172TEST(complex, cexpf) {
173 ASSERT_EQ(1.0, cexpf(0));
174}
175
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800176TEST(complex, cexpl) {
177 ASSERT_EQ(1.0, cexpl(0));
178}
179
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800180TEST(complex, cimag) {
181 ASSERT_EQ(0.0, cimag(0));
182}
183
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800184TEST(complex, cimagf) {
185 ASSERT_EQ(0.0f, cimagf(0));
186}
187
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800188TEST(complex, cimagl) {
189 ASSERT_EQ(0.0, cimagl(0));
190}
191
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800192TEST(complex, clog) {
193 ASSERT_EQ(0.0, clog(1.0));
194}
195
196TEST(complex, clogf) {
197 ASSERT_EQ(0.0f, clogf(1.0f));
198}
199
200TEST(complex, clogl) {
201 ASSERT_EQ(0.0L, clogl(1.0L));
202}
203
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800204TEST(complex, conj) {
205 ASSERT_EQ(0.0, conj(0));
206}
207
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800208TEST(complex, conjf) {
209 ASSERT_EQ(0.0f, conjf(0));
210}
211
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800212TEST(complex, conjl) {
213 ASSERT_EQ(0.0, conjl(0));
214}
215
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800216TEST(complex, cpow) {
217 ASSERT_EQ(8.0, cpow(2.0, 3.0));
218}
219
220TEST(complex, cpowf) {
221 ASSERT_EQ(8.0f, cpowf(2.0f, 3.0f));
222}
223
224TEST(complex, cpowl) {
225 ASSERT_EQ(8.0L, cpowl(2.0L, 3.0L));
226}
227
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800228TEST(complex, cproj) {
229 ASSERT_EQ(0.0, cproj(0));
230}
231
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800232TEST(complex, cprojf) {
233 ASSERT_EQ(0.0f, cprojf(0));
234}
235
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800236TEST(complex, cprojl) {
237 ASSERT_EQ(0.0, cprojl(0));
238}
239
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800240TEST(complex, creal) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800241 ASSERT_EQ(2.0, creal(2.0 + 3.0I));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800242}
243
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800244TEST(complex, crealf) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800245 ASSERT_EQ(2.0f, crealf(2.0f + 3.0fI));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800246}
247
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800248TEST(complex, creall) {
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800249 ASSERT_EQ(2.0, creall(2.0L + 3.0LI));
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800250}
251
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800252TEST(complex, csin) {
253 ASSERT_EQ(0.0, csin(0));
254}
255
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800256TEST(complex, csinf) {
257 ASSERT_EQ(0.0, csinf(0));
258}
259
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800260TEST(complex, csinl) {
261 ASSERT_EQ(0.0, csinl(0));
262}
263
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800264TEST(complex, csinh) {
265 ASSERT_EQ(0.0, csinh(0));
266}
267
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800268TEST(complex, csinhf) {
269 ASSERT_EQ(0.0, csinhf(0));
270}
271
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800272TEST(complex, csinhl) {
273 ASSERT_EQ(0.0, csinhl(0));
274}
275
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800276TEST(complex, csqrt) {
277 ASSERT_EQ(0.0, csqrt(0));
278}
279
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800280TEST(complex, csqrtf) {
281 ASSERT_EQ(0.0f, csqrt(0));
282}
283
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800284TEST(complex, csqrtl) {
285 ASSERT_EQ(0.0, csqrtl(0));
286}
287
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800288TEST(complex, ctan) {
289 ASSERT_EQ(0.0, ctan(0));
290}
291
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800292TEST(complex, ctanf) {
293 ASSERT_EQ(0.0, ctanf(0));
294}
295
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800296TEST(complex, ctanl) {
297 ASSERT_EQ(0.0, ctanl(0));
298}
299
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800300TEST(complex, ctanh) {
301 ASSERT_EQ(0.0, ctanh(0));
302}
303
Elliott Hughesb8ee16f2014-11-06 11:16:55 -0800304TEST(complex, ctanhf) {
305 ASSERT_EQ(0.0, ctanhf(0));
306}
Elliott Hughes9ee6adb2016-03-11 14:49:13 -0800307
308TEST(complex, ctanhl) {
309 ASSERT_EQ(0.0, ctanhl(0));
310}