1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // XFAIL: LIBCXX-AIX-FIXME
10 
11 // <complex>
12 
13 // template<class T>
14 //   complex<T>
15 //   pow(const complex<T>& x, const T& y);
16 
17 #include <complex>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 #include "../cases.h"
22 
23 template <class T>
24 void
25 test(const std::complex<T>& a, const T& b, std::complex<T> x)
26 {
27     std::complex<T> c = pow(a, b);
28     is_about(real(c), real(x));
29     is_about(imag(c), imag(x));
30 }
31 
32 template <class T>
33 void
34 test()
35 {
36     test(std::complex<T>(2, 3), T(2), std::complex<T>(-5, 12));
37 }
38 
39 void test_edges()
40 {
41     const unsigned N = sizeof(testcases) / sizeof(testcases[0]);
42     for (unsigned i = 0; i < N; ++i)
43     {
44         for (unsigned j = 0; j < N; ++j)
45         {
46             std::complex<double> r = pow(testcases[i], real(testcases[j]));
47             std::complex<double> z = exp(std::complex<double>(real(testcases[j])) * log(testcases[i]));
48             if (std::isnan(real(r)))
49                 assert(std::isnan(real(z)));
50             else
51             {
52                 assert(real(r) == real(z));
53             }
54             if (std::isnan(imag(r)))
55                 assert(std::isnan(imag(z)));
56             else
57             {
58                 assert(imag(r) == imag(z));
59             }
60         }
61     }
62 }
63 
64 int main(int, char**)
65 {
66     test<float>();
67     test<double>();
68     test<long double>();
69     test_edges();
70 
71   return 0;
72 }
73