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