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// <complex>
10
11// template<class T>
12// complex<T>
13// pow(const complex<T>& x, const complex<T>& y);
14
15#include <complex>
16#include <cassert>
17
18#include "test_macros.h"
19#include "../cases.h"
20
21template <class T>
22void
23test(const std::complex<T>& a, const std::complex<T>& b, std::complex<T> x)
24{
25 std::complex<T> c = pow(a, b);
26 is_about(real(c), real(x));
27 is_about(imag(c), imag(x));
28}
29
30template <class T>
31void
32test()
33{
34 test(std::complex<T>(2, 3), std::complex<T>(2, 0), std::complex<T>(-5, 12));
35}
36
37void test_edges()
38{
39 const unsigned N = sizeof(testcases) / sizeof(testcases[0]);
40 for (unsigned i = 0; i < N; ++i)
41 {
42 for (unsigned j = 0; j < N; ++j)
43 {
44 std::complex<double> r = pow(testcases[i], testcases[j]);
45 std::complex<double> z = exp(testcases[j] * log(testcases[i]));
46 if (std::isnan(x: real(z: r)))
47 assert(std::isnan(real(z)));
48 else
49 {
50 assert(real(r) == real(z));
51 assert(std::signbit(real(r)) == std::signbit(real(z)));
52 }
53 if (std::isnan(x: imag(z: r)))
54 assert(std::isnan(imag(z)));
55 else
56 {
57 assert(imag(r) == imag(z));
58 assert(std::signbit(imag(r)) == std::signbit(imag(z)));
59 }
60 }
61 }
62}
63
64int main(int, char**)
65{
66 test<float>();
67 test<double>();
68 test<long double>();
69 test_edges();
70
71 return 0;
72}
73

source code of libcxx/test/std/numerics/complex.number/complex.transcendentals/pow_complex_complex.pass.cpp