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